public function testGenerate() { $generator = new ClassGenerator('Abc\\Test'); $generator->setAbstract(true); $generator->addTrait('ATrait'); $generator->addUse('ATrait'); $generator->addTrait('BTrait'); $generator->setImplementedInterfaces(['ITestA', 'ITestB']); $generator->setExtendedClass('ParentClass'); $generator->addProperty('abc'); $generator->addMethod('bar'); $data = <<<EOF namespace Abc; use ATrait; abstract class Test extends ParentClass implements ITestA, ITestB { use ATrait, BTrait; public \$abc = null; public function bar() { } } EOF; $this->assertEquals($data, $generator->generate()); }
/** * @param State|\Scaffold\State $state * @return State|void */ public function build(State $state) { $model = $state->getModel('options-factory'); $generator = new ClassGenerator($model->getName()); $generator->setImplementedInterfaces(['FactoryInterface']); $model->setGenerator($generator); $generator->addUse('Zend\\ServiceManager\\FactoryInterface'); $generator->addUse('Zend\\ServiceManager\\ServiceLocatorInterface'); $options = $state->getModel('options'); $key = $options->getServiceName(); $key = substr($key, 0, -7); $body = <<<EOF \$config = \$serviceLocator->get('Config'); return new {$options->getClassName()}( isset(\$config['{$key}']) ? \$config['{$key}'] : [] ); EOF; $method = new MethodGenerator('createService'); $method->setParameter(new ParameterGenerator('serviceLocator', 'ServiceLocatorInterface')); $method->setBody($body); $doc = new DocBlockGenerator(''); $doc->setTag(new Tag(['name' => 'inhertidoc'])); $method->setDocBlock($doc); $generator->addMethodFromGenerator($method); }
/** * Build generators * * @param State|\Scaffold\State $state * @return \Scaffold\State|void */ public function build(State $state) { $model = $state->getServiceModel(); $generator = new ClassGenerator($model->getName()); $generator->setImplementedInterfaces(['ServiceLocatorAwareInterface']); $generator->addUse('Doctrine\\ORM\\EntityManager'); $generator->addUse($state->getEntityModel()->getName()); $generator->addUse($state->getModel('NotFoundException')->getName()); $generator->addUse($state->getModel('repository-trait')->getName()); $generator->addUse('Zend\\ServiceManager\\ServiceLocatorAwareInterface'); $generator->addUse('Zend\\ServiceManager\\ServiceLocatorAwareTrait'); $generator->addUse('Zend\\ServiceManager\\ServiceLocatorInterface'); $generator->addTrait('ServiceLocatorAwareTrait'); $generator->addTrait($state->getModel('repository-trait')->getClassName()); $this->addProperty($generator, 'entityManager', 'EntityManager'); $this->buildConstructor($generator); $this->buildLoadById($generator, $state); $this->buildSearch($generator, $state); $this->buildSave($generator, $state); $this->buildDelete($generator, $state); $this->buildEntityManager($generator); $this->buildFactory($generator, $state); $model->setGenerator($generator); }