use zend router
[GitHub/Stricted/Domain-Control-Panel.git] / vendor / Zend / Mvc / Service / EventManagerFactory.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 ReflectionClass;
14 use Zend\EventManager\EventManager;
15 use Zend\ServiceManager\FactoryInterface;
16 use Zend\ServiceManager\ServiceLocatorInterface;
17
18 class EventManagerFactory implements FactoryInterface
19 {
20 /**
21 * Create an EventManager instance
22 *
23 * Creates a new EventManager instance, seeding it with a shared instance
24 * of SharedEventManager.
25 *
26 * @param ContainerInterface $container
27 * @param string $name
28 * @param null|array $options
29 * @return EventManager
30 */
31 public function __invoke(ContainerInterface $container, $name, array $options = null)
32 {
33 if ($this->acceptsSharedManagerToConstructor()) {
34 // zend-eventmanager v3
35 return new EventManager(
36 $container->has('SharedEventManager') ? $container->get('SharedEventManager') : null
37 );
38 }
39
40 // zend-eventmanager v2
41 $events = new EventManager();
42
43 if ($container->has('SharedEventManager')) {
44 $events->setSharedManager($container->get('SharedEventManager'));
45 }
46
47 return $events;
48 }
49
50 /**
51 * Create and return EventManager instance
52 *
53 * For use with zend-servicemanager v2; proxies to __invoke().
54 *
55 * @param ServiceLocatorInterface $container
56 * @return EventManager
57 */
58 public function createService(ServiceLocatorInterface $container)
59 {
60 return $this($container, EventManager::class);
61 }
62
63 /**
64 * Does the EventManager accept the shared manager to the constructor?
65 *
66 * In zend-eventmanager v3, the EventManager accepts the shared manager
67 * instance to the constructor *only*, while in v2, it must be injected
68 * via the setSharedManager() method.
69 *
70 * @return bool
71 */
72 private function acceptsSharedManagerToConstructor()
73 {
74 $r = new ReflectionClass(EventManager::class);
75 return ! $r->hasMethod('setSharedManager');
76 }
77 }