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);
    }
 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);
 }
 /**
  * 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);
 }
 /**
  * @param  State|\Scaffold\State $state
  * @return State|void
  */
 public function build(State $state)
 {
     $model = $state->getEntityModel();
     $generator = new ClassGenerator($model->getName());
     $model->setGenerator($generator);
     $generator->addUse('Doctrine\\ORM\\Mapping', 'ORM');
     $generator->setDocBlock($this->getClassDocBlock($state));
     $generator->addPropertyFromGenerator($this->getIdProperty());
     $this->addGetter($generator, 'id', 'int');
     $this->addSetter($generator, 'id', 'int');
 }
    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|\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);
    }
 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);
 }
    /**
     * @param ClassGenerator $generator
     * @param State          $state
     */
    public function addDelete(ClassGenerator $generator, State $state)
    {
        $entity = $state->getEntityModel()->getClassName();
        $code = <<<EOF
\$entity = new {$entity}();

\$object = \$this->getObject();
\$object->getEntityManager()->expects(\$this->once())->method('remove')->with(\$entity);
\$object->delete(\$entity);
EOF;
        $generator->addMethodFromGenerator(new MethodGenerator('testDelete', [], MethodGenerator::FLAG_PUBLIC, $code));
    }
    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);
    }