Esempio n. 1
0
 // 1 Code generation
 // 1.1 Code scan
 $filePatterns = ['php' => '/.*\\.php$/', 'di' => '/\\/etc\\/([a-zA-Z_]*\\/di|di)\\.xml$/'];
 $codeScanDir = realpath($rootDir . '/app');
 $directoryScanner = new Scanner\DirectoryScanner();
 $files = $directoryScanner->scan($codeScanDir, $filePatterns, $fileExcludePatterns);
 $files['additional'] = [$opt->getOption('extra-classes-file')];
 $entities = [];
 $repositoryScanner = new Scanner\RepositoryScanner();
 $repositories = $repositoryScanner->collectEntities($files['di']);
 $scanner = new Scanner\CompositeScanner();
 $scanner->addChild(new Scanner\PhpScanner($log), 'php');
 $scanner->addChild(new Scanner\XmlScanner($log), 'di');
 $scanner->addChild(new Scanner\ArrayScanner(), 'additional');
 $entities = $scanner->collectEntities($files);
 $interceptorScanner = new Scanner\XmlInterceptorScanner();
 $entities['interceptors'] = $interceptorScanner->collectEntities($files['di']);
 // 1.2 Generation of Factory and Additional Classes
 $generatorIo = new \Magento\Framework\Code\Generator\Io(new \Magento\Framework\Filesystem\Driver\File(), $generationDir);
 $generator = new \Magento\Framework\Code\Generator($generatorIo, [Interceptor::ENTITY_TYPE => 'Magento\\Framework\\Interception\\Code\\Generator\\Interceptor', Proxy::ENTITY_TYPE => 'Magento\\Framework\\ObjectManager\\Code\\Generator\\Proxy', Factory::ENTITY_TYPE => 'Magento\\Framework\\ObjectManager\\Code\\Generator\\Factory', Mapper::ENTITY_TYPE => 'Magento\\Framework\\Api\\Code\\Generator\\Mapper', Persistor::ENTITY_TYPE => 'Magento\\Framework\\ObjectManager\\Code\\Generator\\Persistor', Repository::ENTITY_TYPE => 'Magento\\Framework\\ObjectManager\\Code\\Generator\\Repository', Converter::ENTITY_TYPE => 'Magento\\Framework\\ObjectManager\\Code\\Generator\\Converter', SearchResults::ENTITY_TYPE => 'Magento\\Framework\\Api\\Code\\Generator\\SearchResults', ExtensionAttributesInterfaceGenerator::ENTITY_TYPE => 'Magento\\Framework\\Api\\Code\\Generator\\ExtensionAttributesInterfaceGenerator', ExtensionAttributesGenerator::ENTITY_TYPE => 'Magento\\Framework\\Api\\Code\\Generator\\ExtensionAttributesGenerator']);
 /** Initialize object manager for code generation based on configs */
 $magentoObjectManagerFactory = \Magento\Framework\App\Bootstrap::createObjectManagerFactory(BP, $_SERVER);
 $objectManager = $magentoObjectManagerFactory->create($_SERVER);
 $generator->setObjectManager($objectManager);
 $generatorAutoloader = new \Magento\Framework\Code\Generator\Autoloader($generator);
 spl_autoload_register([$generatorAutoloader, 'load']);
 foreach ($repositories as $entityName) {
     switch ($generator->generateClass($entityName)) {
         case \Magento\Framework\Code\Generator::GENERATION_SUCCESS:
             $log->add(Log::GENERATION_SUCCESS, $entityName);
             break;
 public function testCollectEntities()
 {
     $actual = $this->_model->collectEntities($this->_testFiles);
     $expected = ['Magento\\Framework\\App\\Cache\\Interceptor', 'Magento\\Framework\\App\\Action\\Context\\Interceptor'];
     $this->assertEquals($expected, $actual);
 }