Completed
Pull Request — master (#479)
by Michał
09:53
created

FormAnnotationBuilderFactory::getOptionsClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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 Doctrine\ORM\EntityManager;
23
use DoctrineModule\Service\AbstractFactory;
24
use DoctrineORMModule\Form\Annotation\AnnotationBuilder;
25
use Interop\Container\ContainerInterface;
26
use Zend\Form\Factory;
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 AnnotationBuilder
41
     */
42 1
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
43
    {
44
        /** @var $entityManager EntityManager */
45 1
        $entityManager = $container->get('doctrine.entitymanager.' . $this->getName());
46
47 1
        $annotationBuilder = new AnnotationBuilder($entityManager);
48 1
        $annotationBuilder->setFormFactory($this->getFormFactory($container));
49
50 1
        return $annotationBuilder;
51
    }
52
53
    /**
54
     * {@inheritDoc}
55
     */
56
    public function getOptionsClass()
57
    {
58
        throw new \BadMethodCallException('Not implemented');
59
    }
60
61
    /**
62
     * Retrieve the form factory
63
     *
64
     * @param  ContainerInterface $services
65
     * @return Factory
66
     */
67 1
    private function getFormFactory(ContainerInterface $services)
68
    {
69 1
        $elements = null;
70
71 1
        if ($services->has('FormElementManager')) {
72 1
            $elements = $services->get('FormElementManager');
73 1
        }
74
75 1
        return new Factory($elements);
76
    }
77
}
78