Completed
Pull Request — master (#459)
by Vytautas
14:01
created

FormAnnotationBuilderFactory::getFormFactory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 10
ccs 0
cts 0
cp 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 6
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace DoctrineORMModule\Service;
21
22
use DoctrineModule\Service\AbstractFactory;
23
use DoctrineORMModule\Form\Annotation\AnnotationBuilder;
24
use Interop\Container\ContainerInterface;
25
use Zend\Form\Factory;
26
use Zend\ServiceManager\ServiceLocatorInterface;
27
28
/**
29
 * Service factory responsible for instantiating {@see \DoctrineORMModule\Form\Annotation\AnnotationBuilder}
30
 *
31
 * @license MIT
32
 * @link    http://www.doctrine-project.org/
33
 * @author  Marco Pivetta <[email protected]>
34
 */
35
class FormAnnotationBuilderFactory extends AbstractFactory
36
{
37
    /**
38
     * {@inheritDoc}
39
     *
40
     * @return \DoctrineORMModule\Form\Annotation\AnnotationBuilder
41 1
     */
42
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
43
    {
44 1
        /* @var $entityManager \Doctrine\ORM\EntityManager */
45
        $entityManager = $container->get('doctrine.entitymanager.' . $this->getName());
46 1
47
        $annotationBuilder = new AnnotationBuilder($entityManager);
48 1
49
        $annotationBuilder->setFormFactory($this->getFormFactory($container));
50 1
51
        return $annotationBuilder;
52
    }
53
54
    /**
55
     * {@inheritDoc}
56
     *
57
     * @return \DoctrineORMModule\Form\Annotation\AnnotationBuilder
58
     */
59
    public function createService(ServiceLocatorInterface $container)
60
    {
61
        return $this($container, \DoctrineORMModule\Form\Annotation\AnnotationBuilder::class);
62
    }
63
64
    /**
65
     * {@inheritDoc}
66 1
     */
67
    public function getOptionsClass()
68 1
    {
69
    }
70 1
71 1
    /**
72 1
     * Retrieve the form factory
73
     *
74 1
     * @param  ContainerInterface $services
75
     * @return Factory
76
     */
77
    private function getFormFactory(ContainerInterface $services)
78
    {
79
        $elements = null;
80
        
81
        if ($services->has('FormElementManager')) {
82
            $elements = $services->get('FormElementManager');
83
        }
84
85
        return new Factory($elements);
86
    }
87
}
88