示例#1
0
 /**
  * Flushes interception cached configuration and generates a new one
  *
  * @return void
  */
 public function doOperation()
 {
     if (empty($this->data)) {
         return;
     }
     $logWriter = new \Magento\Tools\Di\Compiler\Log\Writer\Quiet();
     $errorWriter = new \Magento\Tools\Di\Compiler\Log\Writer\Console();
     $log = new \Magento\Tools\Di\Compiler\Log\Log($logWriter, $errorWriter);
     $validator = new \Magento\Framework\Code\Validator();
     $validator->add(new \Magento\Framework\Code\Validator\ConstructorIntegrity());
     $validator->add(new \Magento\Framework\Code\Validator\ContextAggregation());
     $directoryCompiler = new \Magento\Tools\Di\Compiler\Directory($log, $validator);
     foreach ($this->data as $path) {
         if (is_readable($path)) {
             $directoryCompiler->compile($path);
         }
     }
     list($definitions, ) = $directoryCompiler->getResult();
     $this->configInterface->initialize(array_keys($definitions));
 }
示例#2
0
             case \Magento\Framework\Code\Generator::GENERATION_SUCCESS:
                 $log->add(Log::GENERATION_SUCCESS, $entityName);
                 break;
             case \Magento\Framework\Code\Generator::GENERATION_ERROR:
                 $log->add(Log::GENERATION_ERROR, $entityName);
                 break;
             case \Magento\Framework\Code\Generator::GENERATION_SKIP:
             default:
                 //no log
                 break;
         }
     }
 }
 // 2. Compilation
 // 2.1 Code scan
 $validator = new \Magento\Framework\Code\Validator();
 $validator->add(new \Magento\Framework\Code\Validator\ConstructorIntegrity());
 $validator->add(new \Magento\Framework\Code\Validator\ContextAggregation());
 $classesScanner = new \Magento\Tools\Di\Code\Reader\ClassesScanner();
 $classesScanner->addExcludePatterns($fileExcludePatterns);
 $directoryInstancesNamesList = new \Magento\Tools\Di\Code\Reader\Decorator\Directory($log, new \Magento\Framework\Code\Reader\ClassReader(), $classesScanner, $validator, $generationDir);
 foreach ($compilationDirs as $path) {
     if (is_readable($path)) {
         $directoryInstancesNamesList->getList($path);
     }
 }
 $inheritanceScanner = new Scanner\InheritanceInterceptorScanner();
 $entities['interceptors'] = $inheritanceScanner->collectEntities(get_declared_classes(), $entities['interceptors']);
 // 2.1.1 Generation of Proxy and Interceptor Classes
 foreach (['interceptors', 'di'] as $type) {
     foreach ($entities[$type] as $entityName) {
 /**
  * Compile Code
  *
  * @param string $generationDir
  * @param array $fileExcludePatterns
  * @param InputInterface $input
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 private function compileCode($generationDir, $fileExcludePatterns, $input)
 {
     $diDir = $input->getOption(self::INPUT_KEY_DI) ? $input->getOption(self::INPUT_KEY_DI) : $this->directoryList->getPath(DirectoryList::DI);
     $relationsFile = $diDir . '/relations.ser';
     $pluginDefFile = $diDir . '/plugins.ser';
     $compilationDirs = [$this->directoryList->getPath(DirectoryList::SETUP) . '/Magento/Setup/Module', $this->directoryList->getRoot() . '/dev/tools/Magento/Tools'];
     $compilationDirs = array_merge($compilationDirs, $this->componentRegistrar->getPaths(ComponentRegistrar::MODULE), $this->componentRegistrar->getPaths(ComponentRegistrar::LIBRARY));
     $serializer = $input->getOption(self::INPUT_KEY_SERIALIZER) == Igbinary::NAME ? new Igbinary() : new Standard();
     // 2.1 Code scan
     $validator = new \Magento\Framework\Code\Validator();
     $validator->add(new \Magento\Framework\Code\Validator\ConstructorIntegrity());
     $validator->add(new \Magento\Framework\Code\Validator\ContextAggregation());
     $classesScanner = new \Magento\Setup\Module\Di\Code\Reader\ClassesScanner();
     $classesScanner->addExcludePatterns($fileExcludePatterns);
     $directoryInstancesNamesList = new \Magento\Setup\Module\Di\Code\Reader\Decorator\Directory($this->log, new \Magento\Framework\Code\Reader\ClassReader(), $classesScanner, $validator, $generationDir);
     foreach ($compilationDirs as $path) {
         if (is_readable($path)) {
             $directoryInstancesNamesList->getList($path);
         }
     }
     $inheritanceScanner = new Scanner\InheritanceInterceptorScanner();
     $this->entities['interceptors'] = $inheritanceScanner->collectEntities(get_declared_classes(), $this->entities['interceptors']);
     // 2.1.1 Generation of Proxy and Interceptor Classes
     foreach (['interceptors', 'di'] as $type) {
         foreach ($this->entities[$type] as $entityName) {
             switch ($this->generator->generateClass($entityName)) {
                 case \Magento\Framework\Code\Generator::GENERATION_SUCCESS:
                     $this->log->add(Log::GENERATION_SUCCESS, $entityName);
                     break;
                 case \Magento\Framework\Code\Generator::GENERATION_ERROR:
                     $this->log->add(Log::GENERATION_ERROR, $entityName);
                     break;
                 case \Magento\Framework\Code\Generator::GENERATION_SKIP:
                 default:
                     //no log
                     break;
             }
         }
     }
     //2.1.2 Compile relations for Proxy/Interceptor classes
     $directoryInstancesNamesList->getList($generationDir);
     $relations = $directoryInstancesNamesList->getRelations();
     // 2.2 Compression
     $relationsFileDir = dirname($relationsFile);
     if (!file_exists($relationsFileDir)) {
         mkdir($relationsFileDir, DriverInterface::WRITEABLE_DIRECTORY_MODE, true);
     }
     $relations = array_filter($relations);
     file_put_contents($relationsFile, $serializer->serialize($relations));
     // 3. Plugin Definition Compilation
     $pluginScanner = new Scanner\CompositeScanner();
     $pluginScanner->addChild(new Scanner\PluginScanner(), 'di');
     $pluginDefinitions = [];
     $pluginList = $pluginScanner->collectEntities($this->files);
     $pluginDefinitionList = new \Magento\Framework\Interception\Definition\Runtime();
     foreach ($pluginList as $type => $entityList) {
         foreach ($entityList as $entity) {
             $pluginDefinitions[ltrim($entity, '\\')] = $pluginDefinitionList->getMethodList($entity);
         }
     }
     $outputContent = $serializer->serialize($pluginDefinitions);
     $pluginDefFileDir = dirname($pluginDefFile);
     if (!file_exists($pluginDefFileDir)) {
         mkdir($pluginDefFileDir, DriverInterface::WRITEABLE_DIRECTORY_MODE, true);
     }
     file_put_contents($pluginDefFile, $outputContent);
 }