15 use Psr\Log\LoggerInterface;
88 private $objectManager;
102 private $errorCode = 0;
122 if ($factory ===
null) {
125 return new self($factory, $rootDir, $initParams);
208 $this->rootDir = $rootDir;
209 $this->server = $initParams;
210 $this->objectManager = $this->factory->create($this->server);
220 return $this->server;
236 throw new \InvalidArgumentException(
"The provided class doesn't implement AppInterface: {$type}");
239 }
catch (\Exception $e) {
254 \Magento\Framework\Profiler::start(
'magento');
255 $this->initErrorHandler();
256 $this->assertMaintenance();
260 \Magento\Framework\Profiler::stop(
'magento');
261 }
catch (\Exception $e) {
262 \Magento\Framework\Profiler::stop(
'magento');
263 $this->objectManager->get(LoggerInterface::class)->error($e->getMessage());
268 }
catch (\Exception $e) {
279 protected function assertMaintenance()
281 $isExpected = $this->getIsExpected(self::PARAM_REQUIRE_MAINTENANCE, self::DEFAULT_REQUIRE_MAINTENANCE);
282 if (
null === $isExpected) {
286 $this->maintenance = $this->objectManager->get(\
Magento\Framework\
App\MaintenanceMode::class);
289 $phpRemoteAddressEnvironment = $this->objectManager->get(
290 \
Magento\Framework\HTTP\PhpEnvironment\RemoteAddress::class
292 $remoteAddress = $phpRemoteAddressEnvironment->getRemoteAddress();
293 $isOn = $this->maintenance->isOn($remoteAddress ? $remoteAddress :
'');
295 if ($isOn && !$isExpected) {
297 throw new \Exception(
'Unable to proceed: the maintenance mode is enabled. ');
299 if (!$isOn && $isExpected) {
301 throw new \Exception(
'Unable to proceed: the maintenance mode must be enabled first. ');
313 $isExpected = $this->getIsExpected(self::PARAM_REQUIRE_IS_INSTALLED, self::DEFAULT_REQUIRE_IS_INSTALLED);
314 if (
null === $isExpected) {
317 $isInstalled = $this->isInstalled();
318 if (!$isInstalled && $isExpected) {
320 throw new \Exception(
'Error: Application is not installed yet. ');
322 if ($isInstalled && !$isExpected) {
324 throw new \Exception(
'Error: Application is already installed. ');
337 private function getIsExpected($key, $default)
339 if (array_key_exists($key, $this->server)) {
340 if (isset($this->server[$key])) {
341 return (
bool) (int) $this->server[$key];
353 private function isInstalled()
367 return $this->objectManager;
375 private function initErrorHandler()
378 set_error_handler([
$handler,
'handler']);
388 return $this->errorCode;
424 $message =
"An error has happened during application run. See exception log for details.\n";
426 if (!$this->objectManager) {
427 throw new \DomainException();
429 $this->objectManager->get(LoggerInterface::class)->critical($e);
430 }
catch (\Exception $e) {
431 $message .=
"Could not write error message to log. Please use developer mode to see the message.\n";
static create($rootDir, array $initParams, ObjectManagerFactory $factory=null)
if(!file_exists($installConfigFile)) $dirList
const DEFAULT_REQUIRE_IS_INSTALLED
createApplication($type, $arguments=[])
const INIT_PARAM_FILESYSTEM_DRIVERS
static createConfigFilePool()
const INIT_PARAM_FILESYSTEM_DIR_PATHS
const DEFAULT_REQUIRE_MAINTENANCE
static populateMappings(AutoloaderInterface $autoloader, DirectoryList $dirList)
const PARAM_REQUIRE_MAINTENANCE
static createFilesystemDirectoryList($rootDir, array $initParams)
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
run(AppInterface $application)
static createFilesystemDriverPool(array $initParams)
__construct(ObjectManagerFactory $factory, $rootDir, array $initParams)
const PARAM_REQUIRE_IS_INSTALLED
static createObjectManagerFactory($rootDir, array $initParams)
static populateAutoloader($rootDir, $initParams)
catch(\Exception $e) $handler