use zend router
[GitHub/Stricted/Domain-Control-Panel.git] / vendor / Zend / Mvc / Service / FormAnnotationBuilderFactory.php
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
4 *
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
9
10 namespace Zend\Mvc\Service;
11
12 use Interop\Container\ContainerInterface;
13 use Zend\EventManager\ListenerAggregateInterface;
14 use Zend\Form\Annotation\AnnotationBuilder;
15 use Zend\ServiceManager\Exception\ServiceNotCreatedException;
16 use Zend\ServiceManager\FactoryInterface;
17 use Zend\ServiceManager\ServiceLocatorInterface;
18
19 class FormAnnotationBuilderFactory implements FactoryInterface
20 {
21 /**
22 * Create service
23 *
24 * @param ContainerInterface $container
25 * @param string $name
26 * @param null|array $options
27 * @return AnnotationBuilder
28 * @throws ServiceNotCreatedException for invalid listener configuration.
29 */
30 public function __invoke(ContainerInterface $container, $name, array $options = null)
31 {
32 //setup a form factory which can use custom form elements
33 $annotationBuilder = new AnnotationBuilder();
34 $eventManager = $container->get('EventManager');
35 $annotationBuilder->setEventManager($eventManager);
36
37 $formElementManager = $container->get('FormElementManager');
38 $formElementManager->injectFactory($container, $annotationBuilder);
39
40 $config = $container->get('config');
41 if (isset($config['form_annotation_builder'])) {
42 $config = $config['form_annotation_builder'];
43
44 if (isset($config['annotations'])) {
45 foreach ((array) $config['annotations'] as $fullyQualifiedClassName) {
46 $annotationBuilder->getAnnotationParser()->registerAnnotation($fullyQualifiedClassName);
47 }
48 }
49
50 if (isset($config['listeners'])) {
51 foreach ((array) $config['listeners'] as $listenerName) {
52 $listener = $container->get($listenerName);
53 if (!($listener instanceof ListenerAggregateInterface)) {
54 throw new ServiceNotCreatedException(sprintf('Invalid event listener (%s) provided', $listenerName));
55 }
56 $listener->attach($eventManager);
57 }
58 }
59
60 if (isset($config['preserve_defined_order'])) {
61 $annotationBuilder->setPreserveDefinedOrder($config['preserve_defined_order']);
62 }
63 }
64
65 return $annotationBuilder;
66 }
67
68 /**
69 * Create and return AnnotationBuilder instance
70 *
71 * For use with zend-servicemanager v2; proxies to __invoke().
72 *
73 * @param ServiceLocatorInterface $container
74 * @return AnnotationBuilder
75 */
76 public function createService(ServiceLocatorInterface $container)
77 {
78 return $this($container, AnnotationBuilder::class);
79 }
80 }