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 Zend\Form\Factory; |
25
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Service factory responsible for instantiating {@see \DoctrineORMModule\Form\Annotation\AnnotationBuilder} |
29
|
|
|
* |
30
|
|
|
* @license MIT |
31
|
|
|
* @link http://www.doctrine-project.org/ |
32
|
|
|
* @author Marco Pivetta <[email protected]> |
33
|
|
|
*/ |
34
|
|
|
class FormAnnotationBuilderFactory extends AbstractFactory |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* {@inheritDoc} |
38
|
|
|
* |
39
|
|
|
* @return \DoctrineORMModule\Form\Annotation\AnnotationBuilder |
40
|
|
|
*/ |
41
|
1 |
|
public function createService(ServiceLocatorInterface $serviceLocator) |
42
|
|
|
{ |
43
|
|
|
/* @var $entityManager \Doctrine\ORM\EntityManager */ |
44
|
1 |
|
$entityManager = $serviceLocator->get('doctrine.entitymanager.' . $this->getName()); |
45
|
|
|
|
46
|
1 |
|
$annotationBuilder = new AnnotationBuilder($entityManager); |
47
|
|
|
|
48
|
1 |
|
$annotationBuilder->setFormFactory($this->getFormFactory($serviceLocator)); |
49
|
|
|
|
50
|
1 |
|
return $annotationBuilder; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritDoc} |
55
|
|
|
*/ |
56
|
|
|
public function getOptionsClass() |
57
|
|
|
{ |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Retrieve the form factory |
62
|
|
|
* |
63
|
|
|
* @param ServiceLocatorInterface $services |
64
|
|
|
* @return Factory |
65
|
|
|
*/ |
66
|
1 |
|
private function getFormFactory(ServiceLocatorInterface $services) |
67
|
|
|
{ |
68
|
1 |
|
$elements = null; |
69
|
|
|
|
70
|
1 |
|
if ($services->has('FormElementManager')) { |
71
|
1 |
|
$elements = $services->get('FormElementManager'); |
72
|
1 |
|
} |
73
|
|
|
|
74
|
1 |
|
return new Factory($elements); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.