1
|
|
|
<?php |
2
|
|
|
namespace mxdiModule\ServiceManager; |
3
|
|
|
|
4
|
|
|
use Zend\ServiceManager\AbstractFactoryInterface; |
5
|
|
|
use Zend\ServiceManager\AbstractPluginManager; |
6
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
7
|
|
|
use mxdiModule\Service\Instantiator; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @TODO DELETE THIS FILE BECAUSE IT IS NOT NEEDED |
11
|
|
|
* DEFAULT FACTORY WORKS FOR ABSTRACT MANAGERS AS WELL |
12
|
|
|
*/ |
13
|
|
|
class DiAbstractPluginFactory implements AbstractFactoryInterface |
14
|
|
|
{ |
15
|
|
|
/** @var DiAbstractFactory */ |
16
|
|
|
protected $factory; |
17
|
|
|
|
18
|
2 |
|
public function __construct(DiAbstractFactory $factory = null) |
19
|
|
|
{ |
20
|
2 |
|
$this->factory = $factory ?: new DiAbstractFactory(new Instantiator()); |
21
|
2 |
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Determine if we can create a service with name |
25
|
|
|
* |
26
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
27
|
|
|
* @param string $name |
28
|
|
|
* @param string $requestedName |
29
|
|
|
* @return bool |
30
|
|
|
*/ |
31
|
1 |
View Code Duplication |
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) |
32
|
|
|
{ |
33
|
1 |
|
if ($serviceLocator instanceof AbstractPluginManager) { |
34
|
1 |
|
$serviceLocator = $serviceLocator->getServiceLocator(); |
35
|
1 |
|
} |
36
|
|
|
|
37
|
1 |
|
return $this->factory->canCreateServiceWithName($serviceLocator, $name, $requestedName); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Create service with name |
42
|
|
|
* |
43
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
44
|
|
|
* @param string $name |
45
|
|
|
* @param string $requestedName |
46
|
|
|
* @return object |
47
|
|
|
*/ |
48
|
1 |
View Code Duplication |
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) |
49
|
|
|
{ |
50
|
1 |
|
if ($serviceLocator instanceof AbstractPluginManager) { |
51
|
1 |
|
$serviceLocator = $serviceLocator->getServiceLocator(); |
52
|
1 |
|
} |
53
|
|
|
|
54
|
1 |
|
return $this->factory->createServiceWithName($serviceLocator, $name, $requestedName); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|