/** * Set parameters from configuration * * @param string $aliasOrClass * @param array $parameters */ public function setParameters($aliasOrClass, array $parameters) { foreach ($parameters as $parameter) { if (is_string($parameter)) { $this->_generator->generateClass($parameter); } } parent::setParameters($aliasOrClass, $parameters); }
/** * Generate all not existing entity classes in constructor * * @param string $className */ public function generateForConstructor($className) { $reflectionClass = new ReflectionClass($className); if ($reflectionClass->hasMethod('__construct')) { $constructor = $reflectionClass->getMethod('__construct'); $parameters = $constructor->getParameters(); /** @var $parameter ReflectionParameter */ foreach ($parameters as $parameter) { preg_match('/\\[\\s\\<\\w+?>\\s([\\w\\\\]+)/s', $parameter->__toString(), $matches); if (isset($matches[1])) { $this->_generator->generateClass($matches[1]); } } } }
public function testGenerateClassProxyWithNamespace() { $factoryClassName = self::CLASS_NAME_WITH_NAMESPACE . 'Proxy'; $this->assertTrue($this->_generator->generateClass($factoryClassName)); $proxy = Mage::getObjectManager()->create($factoryClassName); $this->assertInstanceOf(self::CLASS_NAME_WITH_NAMESPACE, $proxy); $this->_verifyProxyMethods(self::CLASS_NAME_WITH_NAMESPACE, $proxy); }
/** * @expectedException Magento_Exception */ public function testGenerateClassWithError() { $this->_autoloader->staticExpects($this->once())->method('getFile')->will($this->returnValue(false)); $this->_generator->expects($this->once())->method('generate')->will($this->returnValue(false)); $this->_model = new Magento_Di_Generator($this->_generator, $this->_autoloader); $expectedEntities = array_values($this->_expectedEntities); $resultClassName = self::SOURCE_CLASS . ucfirst(array_shift($expectedEntities)); $this->_model->generateClass($resultClassName); }
* obtain it through the world-wide-web, please send an email * to license@magentocommerce.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade Magento to newer * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * * @category Tools * @package DI * @copyright Copyright (c) 2013 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ require __DIR__ . '/../../../app/bootstrap.php'; $generator = new Magento_Di_Generator(); $generatedEntities = $generator->getGeneratedEntities(); if (!isset($argv[1]) || in_array($argv[1], array('-?', '/?', '-help', '--help'))) { $message = " * Usage: php entity_generator.php [" . implode('|', $generatedEntities) . "] <required_entity_class_name>\n" . " * Example: php entity_generator.php factory Mage_Tag_Model_Tag" . " - will generate file var/generation/Mage/Tag/Model/TagFactory.php\n"; print $message; exit; } $entityType = $argv[1]; if (!in_array($argv[1], $generatedEntities)) { print "Error! Unknown entity type.\n"; exit; } if (!isset($argv[2])) { print "Error! Please, specify class name.\n"; exit; }