/** * @param State $state * @param Model $model * @param OutputInterface $output */ public function mergeConfig(State $state, Model $model, OutputInterface $output) { $config = $model->getServiceConfig(); if (is_array($config)) { $state->getModuleConfig()->merge($config); } }
/** * Build generators * * @param State|State $state */ public function build(State $state) { $model = $state->getModel($this->name); $data = file_get_contents(SCAFFOLD_ROOT . "/data/template/" . $this->name); $data = str_replace('__NAMESPACE_PLACEHOLDER__', ucfirst($this->config->getModule()), $data); $model->setGenerator(new BinGenerator($data)); }
protected function write(State $state, InputInterface $input, OutputInterface $output) { $writeState = new State($this->configWriter); $writeState->addModel($state->getEntityModel()); $writeState->addModel($state->getModel('entity-test')); parent::write($writeState, $input, $output); }
public function buildCreateService(ClassGenerator $generator, State $state) { $method = new MethodGenerator('createService'); $method->setDocBlock(new DocBlockGenerator()); $method->getDocBlock()->setShortDescription('{@inheritdoc}'); $method->setParameter(new ParameterGenerator('serviceLocator', 'ServiceLocatorInterface')); $name = lcfirst($state->getEntityModel()->getClassName()); $entity = $state->getEntityModel()->getName(); $method->setBody(<<<EOF \$form = new Form('{$name}'); \$submit = new Element\\Submit('submit'); \$submit->setValue('Submit'); \$form->add(\$submit); \$form->setInputFilter(\$this->getInputFilter()); /** @var EntityManager \$entityManager */ \$entityManager = \$serviceLocator->get('entity_manager'); \$form->setHydrator(new DoctrineObject(\$entityManager, '{$entity}')); return \$form; EOF ); $generator->addMethodFromGenerator($method); }
/** * @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); }
protected function execute(InputInterface $input, OutputInterface $output) { $config = new Config(); $config->setBasePath(getcwd()); $config->setFromArray($input->getArguments()); $config->setFromArray(array('bare' => $input->getOption('bare'))); $moduleConfig = new ConfigWriter($config); $state = new State($moduleConfig); $builder = new FullContainer($config); $builder->prepare($state); $builder->build($state); $writeState = new State($moduleConfig); $models = array('service' => $state->getServiceModel(), 'factory' => $state->getModel('service-factory'), 'trait' => $state->getModel('service-trait'), 'test' => $state->getModel('service-test')); foreach (array_keys($models) as $key) { if ($input->getOption('no-' . $key)) { $models[$key] = false; } if ($input->getOption('only-' . $key)) { foreach (array_keys($models) as $index) { if ($key != $index) { $models[$index] = false; } } } } foreach ($models as $model) { if ($model) { $writeState->addModel($model); } } $writer = new ModelWriter($config); $writer->write($writeState, $output); $moduleConfig->save($output); }
/** * @param State|\Scaffold\State $state * @return State|void */ public function build(State $state) { $model = $state->getModel('options'); $generator = new ClassGenerator($model->getName()); $generator->setExtendedClass('AbstractOptions'); $model->setGenerator($generator); $generator->addUse('Zend\\Stdlib\\AbstractOptions'); }
protected function getClassDocBlock(State $state) { $repository = $state->getRepositoryModel()->getName(); $doc = new DocBlockGenerator(); $doc->setTag(new Tag\GenericTag('ORM\\Entity(repositoryClass="' . $repository . '")')); $doc->setTag(new Tag\GenericTag('ORM\\Table(name="' . strtolower($this->config->getName()) . '")')); return $doc; }
/** * Build generators * * @param State|\Scaffold\State $state * @return \Scaffold\State|void */ public function build(State $state) { $model = $state->getRepositoryModel(); $generator = new ClassGenerator($model->getName()); $generator->addUse('Doctrine\\ORM\\EntityRepository'); $generator->addUse($state->getEntityModel()->getName()); $generator->setExtendedClass('EntityRepository'); $this->buildFactory($generator); $model->setGenerator($generator); }
/** * Prepare models * * @param State|\Scaffold\State $state */ public function prepare(State $state) { $model = new Model(); $name = $this->buildNamespace()->addPart($this->config->getModule())->addPart('Exception')->addPart($this->name)->getNamespace(); $path = $this->buildPath()->setModule($this->config->getModule())->addPart('Exception')->addPart($this->name)->getSourcePath(); $model->setName($name); $model->setPath($path); $state->addModel($model, $this->name); $this->model = $model; }
protected function write(State $state, InputInterface $input, OutputInterface $output) { $writeState = new State($this->configWriter); if (!$input->getOption('no-repository')) { $writeState->addModel($state->getRepositoryModel()); } if (!$input->getOption('no-trait')) { $writeState->addModel($state->getModel('repository-trait')); } parent::write($writeState, $input, $output); }
/** * Build generators * * @param State|State $state */ public function build(State $state) { $model = $state->getModel('module'); if ($this->config->getBare()) { $data = file_get_contents(SCAFFOLD_ROOT . "/data/template/src/Module.bare.php"); } else { $data = file_get_contents(SCAFFOLD_ROOT . "/data/template/src/Module.php"); } $data = str_replace('__NAMESPACE_PLACEHOLDER__', ucfirst($this->config->getModule()), $data); $data = substr($data, 7); $model->setGenerator(new RawGenerator($data)); }
public function addTestIdMethod(ClassGenerator $generator, State $state) { $method = new MethodGenerator('testGetSetId'); $class = $state->getEntityModel()->getClassName(); $code = <<<EOF \$object = new {$class}(); \$object->setId(123); \$this->assertEquals(123, \$object->getId()); EOF; $method->setBody($code); $generator->addMethodFromGenerator($method); }
/** * 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 testWrite() { $state = new State(new ConfigWriter(new Config())); $modelA = new Model(); $modelB = new Model(); $state->addModel($modelA); $state->addModel($modelB); $output = new NullOutput(); $writer = $this->getWriter(['writeModel', 'mergeConfig']); $writer->expects($this->at(0))->method('writeModel')->with($modelA, $output); $writer->expects($this->at(1))->method('mergeConfig')->with($state, $modelA, $output); $writer->expects($this->at(2))->method('writeModel')->with($modelB, $output); $writer->expects($this->at(3))->method('mergeConfig')->with($state, $modelB, $output); $writer->write($state, $output); }
/** * Build generators * * @param State|\Scaffold\State $state * @return \Scaffold\State|void */ public function build(State $state) { $model = $this->model; $generator = new ClassGenerator($model->getName()); $generator->addUse('Zend\\ServiceManager\\FactoryInterface'); $generator->addUse('Zend\\ServiceManager\\ServiceLocatorInterface'); $generator->addUse('Zend\\ServiceManager\\ServiceManager'); $generator->addUse($state->getServiceModel()->getName()); $generator->setImplementedInterfaces(['FactoryInterface']); $method = new MethodGenerator('createService'); $method->setParameter(new ParameterGenerator('serviceLocator', 'ServiceLocatorInterface')); $method->setBody('return new ' . $state->getServiceModel()->getClassName() . '($serviceLocator);'); $doc = new DocBlockGenerator('Create service'); $doc->setTag(new Tag\GenericTag('param', 'ServiceLocatorInterface|ServiceManager $serviceLocator')); $doc->setTag(new Tag\GenericTag('return', $state->getServiceModel()->getClassName())); $method->setDocBlock($doc); $generator->addMethodFromGenerator($method); $model->setGenerator($generator); }
/** * Build generators * * @param State|\Scaffold\State $state * @return \Scaffold\State|void */ public function build(State $state) { $model = $this->model; $generator = new TraitGenerator($model->getName()); $generator->addUse($state->getRepositoryModel()->getName()); $property = lcfirst($state->getRepositoryModel()->getClassName()); $class = $state->getRepositoryModel()->getClassName(); $entity = $state->getEntityModel()->getName(); $code = <<<EOF if (null === \$this->{$property}) { \$this->{$property} = \$this->getEntityManager()->getRepository('{$entity}'); } return \$this->{$property}; EOF; $this->addProperty($generator, $property, $class); $this->addSetter($generator, $property, $class); $getter = $this->getGetter($property, $class); $getter->setBody($code); $generator->addMethodFromGenerator($getter); // $model->setGenerator($generator); }
/** * Build generators * * @param State|\Scaffold\State $state * @return \Scaffold\State|void */ public function build(State $state) { $model = $state->getModel('options-trait'); $options = $state->getModel('options'); $generator = new TraitGenerator($model->getName()); $generator->addUse($options->getName()); $generator->addUse($state->getModel('RuntimeException')->getName()); $generator->addUse('Zend\\ServiceManager\\ServiceLocatorAwareInterface'); $generator->addUse('Zend\\ServiceManager\\ServiceLocatorInterface'); $property = lcfirst($options->getClassName()); $class = $options->getClassName(); $alias = $options->getServiceName(); $code = <<<EOF if (null === \$this->{$property}) { if (\$this instanceof ServiceLocatorAwareInterface || method_exists(\$this, 'getServiceLocator')) { \$this->{$property} = \$this->getServiceLocator()->get('{$alias}'); } else { if (property_exists(\$this, 'serviceLocator') && \$this->serviceLocator instanceof ServiceLocatorInterface ) { \$this->{$property} = \$this->serviceLocator->get('{$alias}'); } else { throw new RuntimeException('Service locator not found'); } } } return \$this->{$property}; EOF; $this->addProperty($generator, $property, $class); $this->addSetter($generator, $property, $class); $getter = $this->getGetter($property, $class); $getter->setBody($code); $getter->getDocBlock()->setTag(new Tag(['name' => 'throws', 'description' => $state->getModel('RuntimeException')->getClassName()])); $generator->addMethodFromGenerator($getter); // $model->setGenerator($generator); }
protected function buildDelete(ClassGenerator $generator, State $state) { $body = '$this->getEntityManager()->remove($model);'; $method = new MethodGenerator('delete'); $method->setParameter(new ParameterGenerator('model', $state->getEntityModel()->getClassName())); $method->setDocBlock(new DocBlockGenerator()); $method->getDocBlock()->setTag(new Tag\GenericTag('param', $state->getEntityModel()->getClassName() . ' $model')); $method->setBody($body); $generator->addMethodFromGenerator($method); }
/** * @expectedException \Scaffold\Exception\RuntimeException */ public function testGetModelNotFound() { $state = new State($this->getConfigWriter()); $state->getModel('test'); }
protected function write(State $state, InputInterface $input, OutputInterface $output) { $writeState = new State($this->configWriter); $writeState->addModel($state->getControllerModel()); parent::write($writeState, $input, $output); }
public function buildEditAction(ClassGenerator $generator, State $state) { $service = 'get' . $state->getServiceModel()->getClassName(); $name = lcfirst($state->getEntityModel()->getClassName()); $method = new MethodGenerator('editAction'); $method->setDocBlock(new DocBlockGenerator('Show one entity')); $method->setBody(<<<EOF \$id = \$this->params()->fromRoute('id'); \${$name} = \$this->{$service}()->loadById(\$id); /** @var Form \$form */ \$form = \$this->getServiceLocator()->get('{$state->getFormFactoryModel()->getServiceName()}'); \$form->bind(\${$name}); if (\$this->getRequest()->isPost()) { \$form->setData(\$this->params()->fromPost()); if (\$form->isValid()) { \$this->{$service}()->save(\${$name}); \$this->getEntityManager()->flush(); \$this->flashMessenger()->addSuccessMessage('Saved'); \$this->redirect()->toRoute('home'); } } return array( 'form' => \$form ); EOF ); $generator->addMethodFromGenerator($method); }
/** * @param ClassGenerator $generator * @param State $state */ public function addGetRepository(ClassGenerator $generator, State $state) { $class = $state->getRepositoryModel()->getClassName(); $doc = "@return \\PHPUnit_Framework_MockObject_MockObject|" . $class; $class = $state->getRepositoryModel()->getName(); $body = <<<EOF return \$this->getMockBuilder('{$class}') ->disableOriginalConstructor() ->getMock(); EOF; $method = new MethodGenerator('getRepository', [], MethodGenerator::FLAG_PUBLIC, $body, $doc); $generator->addMethodFromGenerator($method); }