Example #1
0
 /**
  * Loads the configuration file
  *
  * @param string $fileKey
  * @return array
  * @throws \Exception
  */
 public function load($fileKey = null)
 {
     $path = $this->dirList->getPath(DirectoryList::CONFIG);
     $fileDriver = $this->driverPool->getDriver(DriverPool::FILE);
     $result = [];
     if ($fileKey) {
         $filePath = $path . '/' . $this->configFilePool->getPath($fileKey);
         if ($fileDriver->isExists($filePath)) {
             $result = (include $filePath);
         }
     } else {
         $configFiles = $this->configFilePool->getPaths();
         $allFilesData = [];
         $result = [];
         foreach (array_keys($configFiles) as $fileKey) {
             $configFile = $path . '/' . $this->configFilePool->getPath($fileKey);
             if ($fileDriver->isExists($configFile)) {
                 $fileData = (include $configFile);
             } else {
                 continue;
             }
             $allFilesData[$configFile] = $fileData;
             if (!empty($fileData)) {
                 $intersection = array_intersect_key($result, $fileData);
                 if (!empty($intersection)) {
                     $displayMessage = $this->findFilesWithKeys(array_keys($intersection), $allFilesData);
                     throw new \Exception("Key collision! The following keys occur in multiple config files:" . PHP_EOL . $displayMessage);
                 }
                 $result = array_merge($result, $fileData);
             }
         }
     }
     return $result ?: [];
 }
 /**
  * Create a readable file.
  *
  * @param string $path
  * @param DriverInterface|string $driver Driver or driver code
  * @param string $mode [optional]
  * @return Write
  */
 public function create($path, $driver, $mode = 'r')
 {
     if (is_string($driver)) {
         return new Write($path, $this->driverPool->getDriver($driver), $mode);
     }
     return new Write($path, $driver, $mode);
 }
 /**
  * Create a readable file
  *
  * @param string $path
  * @param DriverInterface|string $driver Driver or driver code
  * @return \Magento\Framework\Filesystem\File\ReadInterface
  */
 public function create($path, $driver)
 {
     if (is_string($driver)) {
         return new Read($path, $this->driverPool->getDriver($driver));
     }
     return new Read($path, $driver);
 }
 public function testCustomDriver()
 {
     $customOne = $this->getMockForAbstractClass('\\Magento\\Framework\\Filesystem\\DriverInterface');
     $customTwo = get_class($this->getMockForAbstractClass('\\Magento\\Framework\\Filesystem\\DriverInterface'));
     $object = new DriverPool(['customOne' => $customOne, 'customTwo' => $customTwo]);
     $this->assertSame($customOne, $object->getDriver('customOne'));
     $this->assertInstanceOf('\\Magento\\Framework\\Filesystem\\DriverInterface', $object->getDriver('customOne'));
     $this->assertEquals($customTwo, get_class($object->getDriver('customTwo')));
     $this->assertInstanceOf('\\Magento\\Framework\\Filesystem\\DriverInterface', $object->getDriver('customTwo'));
 }
 /**
  * Check var/generation read and write access
  *
  * @return bool
  */
 public function check()
 {
     $initParams = $this->serviceManager->get(InitParamListener::BOOTSTRAP_PARAM);
     $filesystemDirPaths = isset($initParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS]) ? $initParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] : [];
     $directoryList = new DirectoryList(BP, $filesystemDirPaths);
     $generationDirectoryPath = $directoryList->getPath(DirectoryList::GENERATION);
     $driverPool = new DriverPool();
     $fileWriteFactory = new WriteFactory($driverPool);
     /** @var \Magento\Framework\Filesystem\DriverInterface $driver */
     $driver = $driverPool->getDriver(DriverPool::FILE);
     $directoryWrite = new Write($fileWriteFactory, $driver, $generationDirectoryPath);
     if ($directoryWrite->isExist()) {
         if ($directoryWrite->isDirectory() || $directoryWrite->isReadable()) {
             try {
                 $probeFilePath = $generationDirectoryPath . DIRECTORY_SEPARATOR . uniqid(mt_rand()) . 'tmp';
                 $fileWriteFactory->create($probeFilePath, DriverPool::FILE, 'w');
                 $driver->deleteFile($probeFilePath);
             } catch (\Exception $e) {
                 return false;
             }
         } else {
             return false;
         }
     } else {
         try {
             $directoryWrite->create();
         } catch (\Exception $e) {
             return false;
         }
     }
     return true;
 }
 /**
  * Create ObjectManager
  *
  * @param array $arguments
  * @return \Magento\Framework\ObjectManagerInterface
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function create(array $arguments)
 {
     $writeFactory = new \Magento\Framework\Filesystem\Directory\WriteFactory($this->driverPool);
     $generatedFiles = new GeneratedFiles($this->directoryList, $writeFactory);
     $generatedFiles->cleanGeneratedFiles();
     $deploymentConfig = $this->createDeploymentConfig($this->directoryList, $this->configFilePool, $arguments);
     $arguments = array_merge($deploymentConfig->get(), $arguments);
     $definitionFactory = new \Magento\Framework\ObjectManager\DefinitionFactory($this->driverPool->getDriver(DriverPool::FILE), $this->directoryList->getPath(DirectoryList::DI), $this->directoryList->getPath(DirectoryList::GENERATION), $deploymentConfig->get(self::CONFIG_PATH_DEFINITION_FORMAT, Serialized::MODE_NAME));
     $definitions = $definitionFactory->createClassDefinition($deploymentConfig->get('definitions'));
     $relations = $definitionFactory->createRelations();
     /** @var EnvironmentFactory $envFactory */
     $envFactory = new $this->envFactoryClassName($relations, $definitions);
     /** @var EnvironmentInterface $env */
     $env = $envFactory->createEnvironment();
     /** @var ConfigInterface $diConfig */
     $diConfig = $env->getDiConfig();
     $appMode = isset($arguments[State::PARAM_MODE]) ? $arguments[State::PARAM_MODE] : State::MODE_DEFAULT;
     $booleanUtils = new \Magento\Framework\Stdlib\BooleanUtils();
     $argInterpreter = $this->createArgumentInterpreter($booleanUtils);
     $argumentMapper = new \Magento\Framework\ObjectManager\Config\Mapper\Dom($argInterpreter);
     if ($env->getMode() != Environment\Compiled::MODE) {
         $configData = $this->_loadPrimaryConfig($this->directoryList, $this->driverPool, $argumentMapper, $appMode);
         if ($configData) {
             $diConfig->extend($configData);
         }
     }
     // set cache profiler decorator if enabled
     if (\Magento\Framework\Profiler::isEnabled()) {
         $cacheFactoryArguments = $diConfig->getArguments('Magento\\Framework\\App\\Cache\\Frontend\\Factory');
         $cacheFactoryArguments['decorators'][] = ['class' => 'Magento\\Framework\\Cache\\Frontend\\Decorator\\Profiler', 'parameters' => ['backendPrefixes' => ['Zend_Cache_Backend_', 'Cm_Cache_Backend_']]];
         $cacheFactoryConfig = ['Magento\\Framework\\App\\Cache\\Frontend\\Factory' => ['arguments' => $cacheFactoryArguments]];
         $diConfig->extend($cacheFactoryConfig);
     }
     $sharedInstances = ['Magento\\Framework\\App\\DeploymentConfig' => $deploymentConfig, 'Magento\\Framework\\App\\Filesystem\\DirectoryList' => $this->directoryList, 'Magento\\Framework\\Filesystem\\DirectoryList' => $this->directoryList, 'Magento\\Framework\\Filesystem\\DriverPool' => $this->driverPool, 'Magento\\Framework\\ObjectManager\\RelationsInterface' => $relations, 'Magento\\Framework\\Interception\\DefinitionInterface' => $definitionFactory->createPluginDefinition(), 'Magento\\Framework\\ObjectManager\\ConfigInterface' => $diConfig, 'Magento\\Framework\\Interception\\ObjectManager\\ConfigInterface' => $diConfig, 'Magento\\Framework\\ObjectManager\\DefinitionInterface' => $definitions, 'Magento\\Framework\\Stdlib\\BooleanUtils' => $booleanUtils, 'Magento\\Framework\\ObjectManager\\Config\\Mapper\\Dom' => $argumentMapper, 'Magento\\Framework\\ObjectManager\\ConfigLoaderInterface' => $env->getObjectManagerConfigLoader(), $this->_configClassName => $diConfig];
     $arguments['shared_instances'] =& $sharedInstances;
     $this->factory = $env->getObjectManagerFactory($arguments);
     /** @var \Magento\Framework\ObjectManagerInterface $objectManager */
     $objectManager = new $this->_locatorClassName($this->factory, $diConfig, $sharedInstances);
     $this->factory->setObjectManager($objectManager);
     ObjectManager::setInstance($objectManager);
     $generatorParams = $diConfig->getArguments('Magento\\Framework\\Code\\Generator');
     /** Arguments are stored in different format when DI config is compiled, thus require custom processing */
     $generatedEntities = isset($generatorParams['generatedEntities']['_v_']) ? $generatorParams['generatedEntities']['_v_'] : (isset($generatorParams['generatedEntities']) ? $generatorParams['generatedEntities'] : []);
     $definitionFactory->getCodeGenerator()->setObjectManager($objectManager)->setGeneratedEntities($generatedEntities);
     $env->configureObjectManager($diConfig, $sharedInstances);
     return $objectManager;
 }
 /**
  * Create a writable directory
  *
  * @param string $path
  * @param string $driverCode
  * @param int $createPermissions
  * @return \Magento\Framework\Filesystem\Directory\Write
  */
 public function create($path, $driverCode = DriverPool::FILE, $createPermissions = null)
 {
     $driver = $this->driverPool->getDriver($driverCode);
     $factory = new \Magento\Framework\Filesystem\File\WriteFactory($this->driverPool);
     return new Write($factory, $driver, $path, $createPermissions);
 }
Example #8
0
 /**
  * Create a readable directory
  *
  * @param string $path
  * @param string $driverCode
  * @return ReadInterface
  */
 public function create($path, $driverCode = DriverPool::FILE)
 {
     $driver = $this->driverPool->getDriver($driverCode);
     $factory = new \Magento\Framework\Filesystem\File\ReadFactory($this->driverPool);
     return new Read($factory, $driver, $path);
 }