public function testScan()
 {
     $filePatterns = ['php' => '/.*\\.php$/', 'etc' => '/\\/app\\/etc\\/.*\\.xml$/', 'config' => '/\\/etc\\/(config([a-z0-9\\.]*)?|adminhtml\\/system)\\.xml$/', 'view' => '/\\/view\\/[a-z0-9A-Z\\/\\.]*\\.xml$/', 'design' => '/\\/app\\/design\\/[a-z0-9A-Z\\/\\.]*\\.xml$/'];
     $actual = $this->_model->scan($this->_testDir, $filePatterns);
     $expected = ['php' => [$this->_testDir . '/additional.php', $this->_testDir . '/app/bootstrap.php', $this->_testDir . '/app/code/Magento/SomeModule/Helper/Test.php', $this->_testDir . '/app/code/Magento/SomeModule/Model/Test.php'], 'config' => [$this->_testDir . '/app/code/Magento/SomeModule/etc/adminhtml/system.xml', $this->_testDir . '/app/code/Magento/SomeModule/etc/config.xml'], 'view' => [$this->_testDir . '/app/code/Magento/SomeModule/view/frontend/default.xml'], 'design' => [$this->_testDir . '/app/design/adminhtml/Magento/backend/layout.xml'], 'etc' => [$this->_testDir . '/app/etc/additional.xml', $this->_testDir . '/app/etc/config.xml']];
     $this->assertEquals(sort($expected['php']), sort($actual['php']), 'Incorrect php files list');
     $this->assertEquals(sort($expected['config']), sort($actual['config']), 'Incorrect config files list');
     $this->assertEquals(sort($expected['view']), sort($actual['view']), 'Incorrect view files list');
     $this->assertEquals(sort($expected['design']), sort($actual['design']), 'Incorrect design files list');
     $this->assertEquals(sort($expected['etc']), sort($actual['etc']), 'Incorrect etc files list');
 }
    /**
     * Processes operation task
     *
     * @return void
     */
    public function doOperation()
    {
        if (array_diff(array_keys($this->data), ['filePatterns', 'path'])
            !== array_diff(['filePatterns', 'path'], array_keys($this->data))) {
            return;
        }

        $files = $this->directoryScanner->scan($this->data['path'], $this->data['filePatterns']);
        $repositories = $this->serviceDataAttributesScanner->collectEntities($files['extension_attributes']);
        foreach ($repositories as $entityName) {
            class_exists($entityName);
        }
    }
 /**
  * Processes operation task
  *
  * @return void
  */
 public function doOperation()
 {
     if (array_diff(array_keys($this->data), ['filePatterns', 'paths', 'excludePatterns']) !== array_diff(['filePatterns', 'paths', 'excludePatterns'], array_keys($this->data))) {
         return;
     }
     $files = [];
     foreach ($this->data['paths'] as $path) {
         $files = array_merge_recursive($files, $this->directoryScanner->scan($path, $this->data['filePatterns'], $this->data['excludePatterns']));
     }
     $proxies = $this->proxyScanner->collectEntities($files['di']);
     foreach ($proxies as $entityName) {
         class_exists($entityName);
     }
 }
Esempio n. 4
0
    /**
     * Processes operation task
     *
     * @return void
     */
    public function doOperation()
    {
        if (array_diff(array_keys($this->data), ['filePatterns', 'path'])
            !== array_diff(['filePatterns', 'path'], array_keys($this->data))) {
            return;
        }

        $this->classesScanner->getList($this->data['path']);
        $this->repositoryScanner->setUseAutoload(false);
        $files = $this->directoryScanner->scan($this->data['path'], $this->data['filePatterns']);
        $repositories = $this->repositoryScanner->collectEntities($files['di']);
        foreach ($repositories as $entityName) {
            class_exists($entityName);
        }
    }
 /**
  * {@inheritdoc}
  */
 public function doOperation()
 {
     if (array_diff(array_keys($this->data), ['filePatterns', 'paths', 'excludePatterns']) !== array_diff(['filePatterns', 'paths', 'excludePatterns'], array_keys($this->data))) {
         return;
     }
     foreach ($this->data['paths'] as $paths) {
         if (!is_array($paths)) {
             $paths = (array) $paths;
         }
         $files = [];
         foreach ($paths as $path) {
             $this->classesScanner->getList($path);
             $files = array_merge_recursive($files, $this->directoryScanner->scan($path, $this->data['filePatterns'], $this->data['excludePatterns']));
         }
         $entities = $this->phpScanner->collectEntities($files['php']);
         foreach ($entities as $entityName) {
             class_exists($entityName);
         }
     }
 }
 /**
  * Generate Code
  *
  * @param string $generationDir
  * @param array $fileExcludePatterns
  * @param InputInterface $input
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function generateCode($generationDir, $fileExcludePatterns, $input)
 {
     // 1.1 Code scan
     $filePatterns = ['php' => '/.*\\.php$/', 'di' => '/\\/etc\\/([a-zA-Z_]*\\/di|di)\\.xml$/'];
     $directoryScanner = new Scanner\DirectoryScanner();
     foreach ($this->componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $codeScanDir) {
         $this->files = array_merge_recursive($this->files, $directoryScanner->scan($codeScanDir, $filePatterns, $fileExcludePatterns));
     }
     $this->files['additional'] = [$input->getOption(self::INPUT_KEY_EXTRA_CLASSES_FILE)];
     $repositoryScanner = new Scanner\RepositoryScanner();
     $repositories = $repositoryScanner->collectEntities($this->files['di']);
     $scanner = new Scanner\CompositeScanner();
     $scanner->addChild(new Scanner\PhpScanner($this->log), 'php');
     $scanner->addChild(new Scanner\XmlScanner($this->log), 'di');
     $scanner->addChild(new Scanner\ArrayScanner(), 'additional');
     $this->entities = $scanner->collectEntities($this->files);
     $interceptorScanner = new Scanner\XmlInterceptorScanner();
     $this->entities['interceptors'] = $interceptorScanner->collectEntities($this->files['di']);
     // 1.2 Generation of Factory and Additional Classes
     $generatorIo = new \Magento\Framework\Code\Generator\Io(new \Magento\Framework\Filesystem\Driver\File(), $generationDir);
     $this->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 */
     $this->generator->setObjectManager($this->objectManager);
     $generatorAutoloader = new \Magento\Framework\Code\Generator\Autoloader($this->generator);
     spl_autoload_register([$generatorAutoloader, 'load']);
     foreach ($repositories 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;
         }
     }
     foreach (['php', 'additional'] as $type) {
         sort($this->entities[$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;
             }
         }
     }
 }
 /**
  * Generate Code
  *
  * @param string $generationDir
  * @param array $fileExcludePatterns
  * @param InputInterface $input
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function generateCode($generationDir, $fileExcludePatterns, $input)
 {
     // 1.1 Code scan
     $filePatterns = ['php' => '/.*\\.php$/', 'di' => '/\\/etc\\/([a-zA-Z_]*\\/di|di)\\.xml$/'];
     $directoryScanner = new Scanner\DirectoryScanner();
     foreach ($this->componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $codeScanDir) {
         $this->files = array_merge_recursive($this->files, $directoryScanner->scan($codeScanDir, $filePatterns, $fileExcludePatterns));
     }
     $this->files['di'][] = $this->directoryList->getPath(\Magento\Framework\App\Filesystem\DirectoryList::CONFIG) . '/di.xml';
     $this->files['additional'] = [$input->getOption(self::INPUT_KEY_EXTRA_CLASSES_FILE)];
     $repositoryScanner = new Scanner\RepositoryScanner();
     $repositories = $repositoryScanner->collectEntities($this->files['di']);
     $scanner = new Scanner\CompositeScanner();
     $scanner->addChild(new Scanner\PhpScanner($this->log), 'php');
     $scanner->addChild(new Scanner\XmlScanner($this->log), 'di');
     $scanner->addChild(new Scanner\ArrayScanner(), 'additional');
     $this->entities = $scanner->collectEntities($this->files);
     $interceptorScanner = new Scanner\XmlInterceptorScanner();
     $this->entities['interceptors'] = $interceptorScanner->collectEntities($this->files['di']);
     // 1.2 Generation of Factory and Additional Classes
     $generatorIo = $this->objectManager->create('Magento\\Framework\\Code\\Generator\\Io', ['generationDirectory' => $generationDir]);
     $this->generator = $this->objectManager->create('Magento\\Framework\\Code\\Generator', ['ioObject' => $generatorIo]);
     /** Initialize object manager for code generation based on configs */
     $this->generator->setObjectManager($this->objectManager);
     $generatorAutoloader = new \Magento\Framework\Code\Generator\Autoloader($this->generator);
     spl_autoload_register([$generatorAutoloader, 'load']);
     foreach ($repositories as $entityName) {
         switch ($this->generator->generateClass($entityName)) {
             case CodeGenerator::GENERATION_SUCCESS:
                 $this->log->add(Log::GENERATION_SUCCESS, $entityName);
                 break;
             case CodeGenerator::GENERATION_ERROR:
                 $this->log->add(Log::GENERATION_ERROR, $entityName);
                 break;
             case CodeGenerator::GENERATION_SKIP:
             default:
                 //no log
                 break;
         }
     }
     foreach (['php', 'additional'] as $type) {
         sort($this->entities[$type]);
         foreach ($this->entities[$type] as $entityName) {
             switch ($this->generator->generateClass($entityName)) {
                 case CodeGenerator::GENERATION_SUCCESS:
                     $this->log->add(Log::GENERATION_SUCCESS, $entityName);
                     break;
                 case CodeGenerator::GENERATION_ERROR:
                     $this->log->add(Log::GENERATION_ERROR, $entityName);
                     break;
                 case CodeGenerator::GENERATION_SKIP:
                 default:
                     //no log
                     break;
             }
         }
     }
 }