TransformerPluginManager::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace Abacaphiliac\Zend\Transformer\PluginManager;
4
5
use Abacaphiliac\Zend\Transformer\Factory\AbstractTransformerFactory;
6
use Abacaphiliac\Zend\Transformer\TransformerInterface;
7
use Zend\ServiceManager\AbstractPluginManager;
8
use Zend\ServiceManager\Exception;
9
10
class TransformerPluginManager extends AbstractPluginManager
11
{
12
    /**
13
     * TransformerPluginManager constructor.
14
     * @param mixed $configOrContainerInstance
15
     * @param array $v3config
16
     * @throws \Zend\ServiceManager\Exception\InvalidArgumentException
17
     */
18
    public function __construct($configOrContainerInstance = null, array $v3config = [])
19
    {
20
        parent::__construct($configOrContainerInstance, $v3config);
21
        
22
        $this->abstractFactories[] = new AbstractTransformerFactory();
23
    }
24
    
25
    /**
26
     * Validate the plugin
27
     *
28
     * Checks that the filter loaded is either a valid callback or an instance
29
     * of FilterInterface.
30
     *
31
     * @param  mixed $plugin
32
     * @return void
33
     * @throws Exception\RuntimeException if invalid
34
     */
35
    public function validatePlugin($plugin)
36
    {
37
        if (!$plugin instanceof TransformerInterface) {
38
            throw new Exception\RuntimeException(sprintf(
39
                'Expected class %s. Actual type %s class %s.',
40
                TransformerInterface::class,
41
                gettype($plugin),
42
                is_object($plugin) ? get_class($plugin) : null
43
            ));
44
        }
45
    }
46
}
47