コード例 #1
0
 // 1 Code generation
 // 1.1 Code scan
 $directoryScanner = new Scanner\DirectoryScanner();
 $files = $directoryScanner->scan($codeScanDir, $filePatterns);
 $files['additional'] = array($opt->getOption('extra-classes-file'));
 $entities = array();
 $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(), null, $generationDir);
 $generator = new \Magento\Framework\Code\Generator(null, $generatorIo, array(\Magento\Framework\Interception\Code\Generator\Interceptor::ENTITY_TYPE => 'Magento\\Framework\\Interception\\Code\\Generator\\Interceptor', SearchResultsBuilder::ENTITY_TYPE => 'Magento\\Framework\\Service\\Code\\Generator\\SearchResultsBuilder', Proxy::ENTITY_TYPE => 'Magento\\Framework\\ObjectManager\\Code\\Generator\\Proxy', Factory::ENTITY_TYPE => 'Magento\\Framework\\ObjectManager\\Code\\Generator\\Factory', Builder::ENTITY_TYPE => 'Magento\\Framework\\Service\\Code\\Generator\\Builder', Mapper::ENTITY_TYPE => 'Magento\\Framework\\Service\\Code\\Generator\\Mapper', Repository::ENTITY_TYPE => 'Magento\\Framework\\ObjectManager\\Code\\Generator\\Repository', Converter::ENTITY_TYPE => 'Magento\\Framework\\ObjectManager\\Code\\Generator\\Converter', SearchResults::ENTITY_TYPE => 'Magento\\Framework\\Service\\Code\\Generator\\SearchResults'));
 $autoloader = new \Magento\Framework\Code\Generator\Autoloader($generator);
 spl_autoload_register(array($autoloader, 'load'));
 foreach (array('php', 'additional') as $type) {
     sort($entities[$type]);
     foreach ($entities[$type] as $entityName) {
         switch ($generator->generateClass($entityName)) {
             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
コード例 #2
0
ファイル: compiler.php プロジェクト: shabbirvividads/magento2
 $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;
         case \Magento\Framework\Code\Generator::GENERATION_ERROR:
             $log->add(Log::GENERATION_ERROR, $entityName);
             break;
         case \Magento\Framework\Code\Generator::GENERATION_SKIP:
コード例 #3
0
ファイル: autoload.php プロジェクト: shabbirvividads/magento2
 * See COPYING.txt for license details.
 */
use Magento\Framework\Api\Code\Generator\DataBuilder;
use Magento\Framework\Api\Code\Generator\Mapper;
use Magento\Framework\Api\Code\Generator\ExtensionAttributesGenerator;
use Magento\Framework\Api\Code\Generator\ExtensionAttributesInterfaceGenerator;
use Magento\Framework\Api\Code\Generator\SearchResults;
use Magento\Framework\Api\Code\Generator\SearchResultsBuilder;
use Magento\Framework\Interception\Code\Generator\Interceptor;
use Magento\Framework\ObjectManager\Code\Generator\Converter;
use Magento\Framework\ObjectManager\Code\Generator\Factory;
use Magento\Framework\ObjectManager\Code\Generator\Persistor;
use Magento\Framework\ObjectManager\Code\Generator\Proxy;
use Magento\Framework\ObjectManager\Code\Generator\Repository;
use Magento\Tools\Di\Code\Scanner;
use Magento\Tools\Di\Compiler\Log\Writer;
use Magento\Tools\Di\Definition\Compressor;
/**
 * Enable code generation for the undeclared classes.
 */
$generationDir = TESTS_TEMP_DIR . '/var/generation';
$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);
$autoloader = new \Magento\Framework\Code\Generator\Autoloader($generator);
spl_autoload_register([$autoloader, 'load']);
$autoloadWrapper = \Magento\Framework\Autoload\AutoloaderRegistry::getAutoloader();
$autoloadWrapper->addPsr4('Magento\\', $generationDir . '/Magento/');