/** * Build generators * * @param State|State $state * @return \Scaffold\State|void */ public function build(State $state) { $model = $state->getControllerModel(); $generator = new ClassGenerator($model->getName()); $generator->setExtendedClass('AbstractRestfulController'); $generator->addUse('Zend\\Mvc\\Controller\\AbstractRestfulController'); $generator->addUse('Doctrine\\ORM\\EntityManager'); $generator->addUse('Zend\\Form\\Form'); $generator->addUse($state->getServiceTraitModel()->getName()); $generator->addTrait($state->getServiceTraitModel()->getClassName()); $this->addProperty($generator, 'entityManager', 'EntityManager'); $this->buildGetEntityManager($generator, $state); $model->setGenerator($generator); }
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()); }
/** * 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); }