1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* MtMail - e-mail module for Zend Framework |
4
|
|
|
* |
5
|
|
|
* @link http://github.com/mtymek/MtMail |
6
|
|
|
* @copyright Copyright (c) 2013-2017 Mateusz Tymek |
7
|
|
|
* @license BSD 2-Clause |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace MtMail\Service; |
11
|
|
|
|
12
|
|
|
use MtMail\ComposerPlugin\PluginInterface; |
13
|
|
|
use MtMail\Exception\RuntimeException; |
14
|
|
|
use Zend\ServiceManager\AbstractPluginManager; |
15
|
|
|
use Zend\ServiceManager\Exception; |
16
|
|
|
use Zend\ServiceManager\Exception\InvalidServiceException; |
17
|
|
|
|
18
|
|
|
class ComposerPluginManager extends AbstractPluginManager |
19
|
|
|
{ |
20
|
|
|
protected $instanceOf = PluginInterface::class; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Validate the plugin is of the expected type (v3). |
24
|
|
|
* |
25
|
|
|
* Validates against `$instanceOf`. |
26
|
|
|
* |
27
|
|
|
* @param mixed $instance |
28
|
|
|
* @throws InvalidServiceException |
29
|
|
|
*/ |
30
|
16 |
|
public function validate($instance) |
31
|
|
|
{ |
32
|
16 |
|
if (! $instance instanceof $this->instanceOf) { |
33
|
3 |
|
throw new InvalidServiceException(sprintf( |
34
|
3 |
|
'%s can only create instances of %s; %s is invalid', |
35
|
3 |
|
get_class($this), |
36
|
3 |
|
$this->instanceOf, |
37
|
3 |
|
(is_object($instance) ? get_class($instance) : gettype($instance)) |
38
|
|
|
)); |
39
|
|
|
} |
40
|
13 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Validate the plugin is of the expected type (v2). |
44
|
|
|
* |
45
|
|
|
* Proxies to `validate()`. |
46
|
|
|
* |
47
|
|
|
* @param mixed $instance |
48
|
|
|
* @throws RuntimeException |
49
|
|
|
*/ |
50
|
2 |
|
public function validatePlugin($instance) |
51
|
|
|
{ |
52
|
|
|
try { |
53
|
2 |
|
$this->validate($instance); |
54
|
1 |
|
} catch (InvalidServiceException $e) { |
55
|
1 |
|
throw new RuntimeException($e->getMessage(), $e->getCode(), $e); |
56
|
|
|
} |
57
|
1 |
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Canonicalize name |
61
|
|
|
* |
62
|
|
|
* @param string $name |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
|
|
protected function canonicalizeName($name) |
66
|
|
|
{ |
67
|
|
|
return $name; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|