/** * Generates config per scope and returns it * * @param DefinitionsCollection $definitionsCollection * @param string $areaCode * * @return array */ public function generateCachePerScope(DefinitionsCollection $definitionsCollection, $areaCode) { $areaConfig = clone $this->diContainerConfig; if ($areaCode !== App\Area::AREA_GLOBAL) { $areaConfig->extend($this->configLoader->load($areaCode)); } $config = []; $this->fillThirdPartyInterfaces($areaConfig, $definitionsCollection); $config['arguments'] = $this->getConfigForScope($definitionsCollection, $areaConfig); foreach ($config['arguments'] as $key => $value) { if ($value !== null) { $config['arguments'][$key] = serialize($value); } } foreach ($definitionsCollection->getInstancesNamesList() as $instanceName) { if (!$areaConfig->isShared($instanceName)) { $config['nonShared'][$instanceName] = true; } $preference = $areaConfig->getPreference($instanceName); if ($instanceName !== $preference) { $config['preferences'][$instanceName] = $preference; } } foreach (array_keys($areaConfig->getVirtualTypes()) as $virtualType) { $config['instanceTypes'][$virtualType] = $areaConfig->getInstanceType($virtualType); } return $config; }
/** * @param $area * @dataProvider loadDataProvider */ public function testLoad($area) { $configData = ['some' => 'config', 'data' => 'value']; $this->_cacheMock->expects($this->once())->method('load')->with($area . '::DiConfig')->will($this->returnValue(false)); $this->_readerMock->expects($this->once())->method('read')->with($area)->will($this->returnValue($configData)); $this->assertEquals($configData, $this->_model->load($area)); }
/** * {@inheritdoc} **/ public function launch() { $areaCode = 'adminhtml'; $this->appState->setAreaCode($areaCode); $this->objectManager->configure($this->configLoader->load($areaCode)); /** @var \Magento\Tools\SampleData\Logger $sampleDataLogger */ $sampleDataLogger = $this->objectManager->get('Magento\\Tools\\SampleData\\Logger'); $sampleDataLogger->setSubject($this->objectManager->get('Magento\\Setup\\Model\\ConsoleLogger')); $this->installer->run($this->userFactory->create()->loadByUsername($this->adminUserName)); return $this->response; }
/** * Run application * * @return \Magento\Framework\App\ResponseInterface */ public function launch() { $areaCode = 'install'; $this->_state->setAreaCode($areaCode); $this->_objectManager->configure($this->_loader->load($areaCode)); if (isset($this->_arguments['uninstall'])) { $sessionConsole = $this->_objectManager->create('\\Magento\\Framework\\Session\\SessionConsole'); $installerModel = $this->_objectManager->create('Magento\\Install\\Model\\Installer', ['session' => $sessionConsole]); $installer = $this->_installerFactory->create(['installArgs' => $this->_arguments, 'installer' => $installerModel]); } else { $installer = $this->_installerFactory->create(array('installArgs' => $this->_arguments)); } if (isset($this->_arguments['show_locales'])) { $this->_output->readableOutput($this->_output->prepareArray($installer->getAvailableLocales())); } elseif (isset($this->_arguments['show_currencies'])) { $this->_output->readableOutput($this->_output->prepareArray($installer->getAvailableCurrencies())); } elseif (isset($this->_arguments['show_timezones'])) { $this->_output->readableOutput($this->_output->prepareArray($installer->getAvailableTimezones())); } elseif (isset($this->_arguments['show_install_options'])) { $this->_output->readableOutput(PHP_EOL . 'Required parameters:'); $this->_output->readableOutput($this->_output->alignArrayKeys($installer->getRequiredParams())); $this->_output->readableOutput(PHP_EOL . 'Optional parameters:'); $this->_output->readableOutput($this->_output->alignArrayKeys($installer->getOptionalParams())); $this->_output->readableOutput(PHP_EOL . 'Flag values are considered positive if set to 1, y, true or yes.' . 'Any other value is considered as negative.' . PHP_EOL); } else { $this->_handleInstall($installer); } $this->_response->setCode(0); return $this->_response; }
/** * {@inheritdoc} * @throws \InvalidArgumentException */ protected function execute(InputInterface $input, OutputInterface $output) { $locale = $input->getOption(self::LOCALE_OPTION); if (!$this->validator->isValid($locale)) { throw new \InvalidArgumentException($locale . ' argument has invalid value, please run info:language:list for list of available locales'); } $area = $input->getOption(self::AREA_OPTION); $theme = $input->getOption(self::THEME_OPTION); $type = $input->getArgument(self::TYPE_ARGUMENT); $this->state->setAreaCode($area); $this->objectManager->configure($this->configLoader->load($area)); $sourceFileGenerator = $this->sourceFileGeneratorPool->create($type); foreach ($input->getArgument(self::FILE_ARGUMENT) as $file) { $file .= '.' . $type; $output->writeln("<info>Gathering {$file} sources.</info>"); $asset = $this->assetRepo->createAsset($file, ['area' => $area, 'theme' => $theme, 'locale' => $locale]); $rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT); $sourceFile = $this->assetSource->findSource($asset); $relativePath = $rootDir->getRelativePath($sourceFile); $content = $rootDir->readFile($relativePath); $chain = $this->chainFactory->create(['asset' => $asset, 'origContent' => $content, 'origContentType' => $asset->getContentType(), 'origAssetPath' => $relativePath]); $processedCoreFile = $sourceFileGenerator->generateFileTree($chain); $targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW); $source = $rootDir->getRelativePath($processedCoreFile); $destination = $asset->getPath(); $rootDir->copyFile($source, $destination, $targetDir); $output->writeln("<info>Successfully processed dynamic stylesheet into CSS</info>"); } }
/** * Finds requested resource and provides it to the client * * @return \Magento\Framework\App\ResponseInterface * @throws \Exception */ public function launch() { $appMode = $this->state->getMode(); if ($appMode == \Magento\Framework\App\State::MODE_PRODUCTION) { $this->response->setHttpResponseCode(404); } else { try { $path = $this->request->get('resource'); $params = $this->parsePath($path); $this->state->setAreaCode($params['area']); $this->objectManager->configure($this->configLoader->load($params['area'])); $file = $params['file']; unset($params['file']); $asset = $this->assetRepo->createAsset($file, $params); $this->response->setFilePath($asset->getSourceFile()); $this->publisher->publish($asset); } catch (\Exception $e) { if ($appMode == \Magento\Framework\App\State::MODE_DEVELOPER) { throw $e; } $this->response->setHttpResponseCode(404); } } return $this->response; }
/** * Run application * * @return ResponseInterface */ public function launch() { $areaCode = $this->_areaList->getCodeByFrontName($this->_request->getFrontName()); $this->_state->setAreaCode($areaCode); $this->_objectManager->configure($this->_configLoader->load($areaCode)); $this->_response = $this->_objectManager->get('Magento\\Framework\\App\\FrontControllerInterface')->dispatch($this->_request); // This event gives possibility to launch something before sending output (allow cookie setting) $eventParams = array('request' => $this->_request, 'response' => $this->_response); $this->_eventManager->dispatch('controller_front_send_response_before', $eventParams); return $this->_response; }
/** * Run application * * @return ResponseInterface */ public function launch() { try { $areaCode = $this->_areaList->getCodeByFrontName($this->_request->getFrontName()); $this->_state->setAreaCode($areaCode); $this->_objectManager->configure($this->_configLoader->load($areaCode)); $this->_response = $this->_objectManager->get('Magento\\Framework\\App\\FrontControllerInterface')->dispatch($this->_request); // This event gives possibility to launch something before sending output (allow cookie setting) $eventParams = array('request' => $this->_request, 'response' => $this->_response); $this->_eventManager->dispatch('controller_front_send_response_before', $eventParams); } catch (\Exception $exception) { $message = $exception->getMessage() . "\n"; try { if ($this->_state->getMode() == State::MODE_DEVELOPER) { $message .= '<pre>'; $message .= $exception->getMessage() . "\n\n"; $message .= $exception->getTraceAsString(); $message .= '</pre>'; } else { $reportData = array($exception->getMessage(), $exception->getTraceAsString()); // retrieve server data if (isset($_SERVER)) { if (isset($_SERVER['REQUEST_URI'])) { $reportData['url'] = $_SERVER['REQUEST_URI']; } if (isset($_SERVER['SCRIPT_NAME'])) { $reportData['script_name'] = $_SERVER['SCRIPT_NAME']; } } require_once $this->_filesystem->getPath(Filesystem::PUB_DIR) . '/errors/report.php'; $processor = new \Magento\Framework\Error\Processor($this->_response); $processor->saveReport($reportData); $this->_response = $processor->processReport(); } } catch (\Exception $exception) { $message .= "Unknown error happened."; } $this->_response->setHttpResponseCode(500); $this->_response->setBody($message); } return $this->_response; }
/** * Launch application * * @return \Magento\Framework\App\ResponseInterface */ public function launch() { $this->state->setAreaCode($this->params->getArea()); $this->objectManager->configure($this->configLoader->load($this->params->getArea())); $sourceFileGenerator = $this->sourceFileGeneratorPool->create($this->params->getExt()); foreach ($this->params->getFiles() as $file) { $file .= '.' . $this->params->getExt(); $this->logger->logMessage("Gathering {$file} sources."); $asset = $this->assetRepo->createAsset($file, ['area' => $this->params->getArea(), 'theme' => $this->params->getTheme(), 'locale' => $this->params->getLocale()]); $sourceFile = $this->assetSource->findSource($asset); $content = \file_get_contents($sourceFile); $chain = $this->chainFactory->create(['asset' => $asset, 'origContent' => $content, 'origContentType' => $asset->getContentType()]); $processedCoreFile = $sourceFileGenerator->generateFileTree($chain); $targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW); $rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT); $source = $rootDir->getRelativePath($processedCoreFile); $destination = $asset->getPath(); $rootDir->copyFile($source, $destination, $targetDir); $this->logger->logMessage("Done"); } $this->response->setCode(Response::SUCCESS); return $this->response; }
/** * Load area configuration * * @return $this */ protected function _initConfig() { $this->_objectManager->configure($this->_diConfigLoader->load($this->_code)); return $this; }