1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Polder Knowledge / entityservice-module (https://polderknowledge.com) |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/polderknowledge/entityservice-module for the canonical source repository |
6
|
|
|
* @copyright Copyright (c) 2016 Polder Knowledge (https://polderknowledge.com) |
7
|
|
|
* @license https://github.com/polderknowledge/entityservice-module/blob/master/LICENSE.md MIT |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace PolderKnowledge\EntityService\Service; |
11
|
|
|
|
12
|
|
|
use PolderKnowledge\EntityService\EntityServiceInterface; |
13
|
|
|
use PolderKnowledge\EntityService\Event\EventManagerInitializer; |
14
|
|
|
use Zend\ServiceManager\AbstractPluginManager; |
15
|
|
|
use Zend\ServiceManager\Exception\InvalidServiceException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Plugin manager for EntityServiceInterfaces |
19
|
|
|
*/ |
20
|
|
|
class EntityServiceManager extends AbstractPluginManager |
21
|
|
|
{ |
22
|
6 |
|
public function __construct($configInstanceOrParentLocator, array $config) |
23
|
|
|
{ |
24
|
6 |
|
parent::__construct($configInstanceOrParentLocator, $config); |
25
|
|
|
|
26
|
6 |
|
$this->addAbstractFactory(EntityServiceAbstractServiceFactory::class); |
27
|
|
|
|
28
|
6 |
|
$this->autoAddInvokableClass = false; |
29
|
|
|
|
30
|
6 |
|
$this->instanceOf = EntityServiceInterface::class; |
31
|
6 |
|
} |
32
|
|
|
|
33
|
6 |
|
public function validate($instance) |
34
|
|
|
{ |
35
|
6 |
|
if (empty($this->instanceOf) || $instance instanceof $this->instanceOf) { |
36
|
3 |
|
return; |
37
|
|
|
} |
38
|
|
|
|
39
|
3 |
|
throw new InvalidServiceException(sprintf( |
40
|
3 |
|
'Plugin manager "%s" expected an instance of type "%s", but "%s" was received', |
41
|
3 |
|
__CLASS__, |
42
|
3 |
|
$this->instanceOf, |
43
|
3 |
|
is_object($instance) ? get_class($instance) : gettype($instance) |
44
|
3 |
|
)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
// @codeCoverageIgnoreStart |
48
|
|
|
public function validatePlugin($plugin) |
49
|
|
|
{ |
50
|
|
|
$this->validate($plugin); |
51
|
|
|
} |
52
|
|
|
// @codeCoverageIgnoreEnds |
53
|
|
|
} |
54
|
|
|
|