1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Svycka\Settings\Collection; |
4
|
|
|
|
5
|
|
|
use Svycka\Settings\Collection\Factory\SettingsCollectionAbstractFactory; |
6
|
|
|
use Zend\ServiceManager\AbstractPluginManager; |
7
|
|
|
use Zend\ServiceManager\Exception\InvalidServiceException; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class CollectionsManager |
11
|
|
|
* |
12
|
|
|
* CollectionsManager implementation for managing settings collection |
13
|
|
|
* |
14
|
|
|
* @method CollectionInterface get($name) |
15
|
|
|
* |
16
|
|
|
* @author Vytautas Stankus <[email protected]> |
17
|
|
|
* @license MIT |
18
|
|
|
*/ |
19
|
|
|
class CollectionsManager extends AbstractPluginManager |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* An object type that the created instance must be instanced of |
23
|
|
|
* |
24
|
|
|
* @var null|string |
25
|
|
|
*/ |
26
|
|
|
protected $instanceOf = CollectionInterface::class; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
27 |
|
public function __construct($configInstanceOrParentLocator = null, array $config = []) |
32
|
|
|
{ |
33
|
27 |
|
parent::__construct($configInstanceOrParentLocator, $config); |
34
|
|
|
|
35
|
27 |
|
$this->addAbstractFactory(SettingsCollectionAbstractFactory::class); |
36
|
27 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Validate the plugin |
40
|
|
|
* |
41
|
|
|
* Checks that the collection loaded is instance of CollectionInterface. |
42
|
|
|
* |
43
|
|
|
* @param CollectionInterface $instance |
44
|
|
|
* |
45
|
|
|
* @return void |
46
|
|
|
* @throws InvalidServiceException if invalid |
47
|
|
|
* |
48
|
|
|
* @deprecated will be removed after zf2 support drop (only required to prevent deprecated warning) |
49
|
|
|
*/ |
50
|
|
|
public function validate($instance) |
51
|
|
|
{ |
52
|
|
|
if (empty($this->instanceOf) || $instance instanceof $this->instanceOf) { |
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
throw new InvalidServiceException(sprintf( |
57
|
|
|
'Plugin manager "%s" expected an instance of type "%s", but "%s" was received', |
58
|
|
|
__CLASS__, |
59
|
|
|
$this->instanceOf, |
60
|
|
|
is_object($instance) ? get_class($instance) : gettype($instance) |
61
|
|
|
)); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Validate the plugin |
66
|
|
|
* |
67
|
|
|
* Checks that the collection loaded is instance of CollectionInterface. |
68
|
|
|
* |
69
|
|
|
* @param CollectionInterface $instance |
70
|
|
|
* |
71
|
|
|
* @return void |
72
|
|
|
* @throws InvalidServiceException if invalid |
73
|
|
|
* |
74
|
|
|
* @deprecated will be removed after zf2 support drop |
75
|
|
|
*/ |
76
|
|
|
public function validatePlugin($instance) |
77
|
|
|
{ |
78
|
|
|
$this->validate($instance); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.