Completed
Push — master ( 2c5e12...fa3f3b )
by Walter
15:22
created

EntityServiceManager::validate()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 2
nop 1
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
    public function __construct($configInstanceOrParentLocator, array $config)
23
    {
24
        parent::__construct($configInstanceOrParentLocator, $config);
25
26
        $this->addAbstractFactory(EntityServiceAbstractServiceFactory::class);
27
28
        $this->autoAddInvokableClass = false;
29
30
        $this->instanceOf = EntityServiceInterface::class;
31
    }
32
33
    public function validate($instance)
34
    {
35
        if (empty($this->instanceOf) || $instance instanceof $this->instanceOf) {
36
            return;
37
        }
38
39
        throw new InvalidServiceException(sprintf(
40
            'Plugin manager "%s" expected an instance of type "%s", but "%s" was received',
41
            __CLASS__,
42
            $this->instanceOf,
43
            is_object($instance) ? get_class($instance) : gettype($instance)
44
        ));
45
    }
46
47
    // @codeCoverageIgnoreStart
48
    public function validatePlugin($plugin)
49
    {
50
        $this->validate($plugin);
51
    }
52
    // @codeCoverageIgnoreEnds
53
}
54