|
1
|
|
|
<?php |
|
2
|
|
|
namespace HtImgModule\Imagine\Resolver; |
|
3
|
|
|
|
|
4
|
|
|
use HtImgModule\Imagine\Resolver\Factory\ImageMapResolverFactory; |
|
5
|
|
|
use HtImgModule\Imagine\Resolver\Factory\ImagePathStackResolverFactory; |
|
6
|
|
|
use Zend\ServiceManager\AbstractPluginManager; |
|
7
|
|
|
use HtImgModule\Exception; |
|
8
|
|
|
use Zend\ServiceManager\Exception\InvalidServiceException; |
|
9
|
|
|
|
|
10
|
|
|
class ResolverManager extends AbstractPluginManager |
|
11
|
|
|
{ |
|
12
|
|
|
protected $instanceOf = ResolverInterface::class; |
|
13
|
|
|
/** |
|
14
|
|
|
* @var array |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $aliases = [ |
|
17
|
|
|
'image_path_stack' => 'imagepathstack', |
|
18
|
|
|
'imagePathStack' => 'imagepathstack', |
|
19
|
|
|
'ImagePathStack' => 'imagepathstack', |
|
20
|
|
|
'image_map' => 'imagemap', |
|
21
|
|
|
'imageMap' => 'imagemap', |
|
22
|
|
|
'ImageMap' => 'imagemap', |
|
23
|
|
|
]; |
|
24
|
|
|
|
|
25
|
|
|
protected $factories = [ |
|
26
|
|
|
'imagemap' => ImageMapResolverFactory::class, |
|
27
|
|
|
'imagepathstack' => ImagePathStackResolverFactory::class, |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
2 |
|
public function validate($instance) |
|
31
|
|
|
{ |
|
32
|
2 |
|
if (! $instance instanceof $this->instanceOf) { |
|
33
|
1 |
|
throw new InvalidServiceException(sprintf( |
|
34
|
1 |
|
'Invalid plugin "%s" created; not an instance of %s', |
|
35
|
1 |
|
get_class($instance), |
|
36
|
1 |
|
$this->instanceOf |
|
37
|
|
|
)); |
|
38
|
|
|
} |
|
39
|
1 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Checks if $plugin is instance of ResolverInterface |
|
43
|
|
|
* |
|
44
|
|
|
* @param mixed $instance |
|
45
|
|
|
* @return void |
|
46
|
|
|
* @throws Exception\InvalidArgumentException |
|
47
|
|
|
*/ |
|
48
|
2 |
|
public function validatePlugin($instance) |
|
49
|
|
|
{ |
|
50
|
|
|
try { |
|
51
|
2 |
|
$this->validate($instance); |
|
52
|
1 |
|
} catch (InvalidServiceException $e) { |
|
53
|
1 |
|
throw new Exception\InvalidArgumentException($e->getMessage(), $e->getCode(), $e); |
|
54
|
|
|
} |
|
55
|
1 |
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|