Completed
Pull Request — master (#562)
by Oliver
04:48 queued 02:59
created

FormAnnotationBuilderFactory::getOptionsClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace DoctrineORMModule\Service;
4
5
use DoctrineModule\Service\AbstractFactory;
6
use DoctrineORMModule\Form\Annotation\AnnotationBuilder;
7
use Interop\Container\ContainerInterface;
8
use Zend\Form\Factory;
9
use Zend\ServiceManager\ServiceLocatorInterface;
10
11
/**
12
 * Service factory responsible for instantiating {@see \DoctrineORMModule\Form\Annotation\AnnotationBuilder}
13
 *
14
 * @license MIT
15
 * @link    http://www.doctrine-project.org/
16
 * @author  Marco Pivetta <[email protected]>
17
 */
18
class FormAnnotationBuilderFactory extends AbstractFactory
19
{
20
    /**
21
     * {@inheritDoc}
22
     *
23
     * @return \DoctrineORMModule\Form\Annotation\AnnotationBuilder
24
     */
25 1
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
26
    {
27
        /* @var $entityManager \Doctrine\ORM\EntityManager */
28 1
        $entityManager = $container->get('doctrine.entitymanager.' . $this->getName());
29
30 1
        $annotationBuilder = new AnnotationBuilder($entityManager);
31
32 1
        $annotationBuilder->setFormFactory($this->getFormFactory($container));
33
34 1
        return $annotationBuilder;
35
    }
36
37
    /**
38
     * {@inheritDoc}
39
     *
40
     * @return \DoctrineORMModule\Form\Annotation\AnnotationBuilder
41
     */
42 1
    public function createService(ServiceLocatorInterface $container)
43
    {
44 1
        return $this($container, \DoctrineORMModule\Form\Annotation\AnnotationBuilder::class);
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50
    public function getOptionsClass()
51
    {
52
    }
53
54
    /**
55
     * Retrieve the form factory
56
     *
57
     * @param  ContainerInterface $services
58
     * @return Factory
59
     */
60 1
    private function getFormFactory(ContainerInterface $services)
61
    {
62 1
        $elements = null;
63
64 1
        if ($services->has('FormElementManager')) {
65 1
            $elements = $services->get('FormElementManager');
66
        }
67
68 1
        return new Factory($elements);
69
    }
70
}
71