1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Svycka\Settings\Type; |
4
|
|
|
|
5
|
|
|
use Zend\ServiceManager\AbstractPluginManager; |
6
|
|
|
use Zend\ServiceManager\Exception\InvalidServiceException; |
7
|
|
|
use Zend\ServiceManager\Factory\InvokableFactory; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class TypesManager |
11
|
|
|
* |
12
|
|
|
* TypesManager implementation for managing settings type |
13
|
|
|
* |
14
|
|
|
* @method SettingTypeInterface get($name) |
15
|
|
|
* |
16
|
|
|
* @author Vytautas Stankus <[email protected]> |
17
|
|
|
* @license MIT |
18
|
|
|
*/ |
19
|
|
|
final class TypesManager extends AbstractPluginManager |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
protected $factories = [ |
25
|
|
|
InArrayType::class => InvokableFactory::class, |
26
|
|
|
RegexType::class => InvokableFactory::class, |
27
|
|
|
IntegerType::class => InvokableFactory::class, |
28
|
|
|
FloatType::class => InvokableFactory::class, |
29
|
|
|
StringType::class => InvokableFactory::class, |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
protected $aliases = [ |
36
|
|
|
'inarray' => InArrayType::class, |
37
|
|
|
'regex' => RegexType::class, |
38
|
|
|
'integer' => IntegerType::class, |
39
|
|
|
'float' => FloatType::class, |
40
|
|
|
'string' => StringType::class, |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Whether or not to share by default; default to false |
45
|
|
|
* |
46
|
|
|
* @var bool |
47
|
|
|
*/ |
48
|
|
|
protected $shareByDefault = false; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Validate the plugin |
52
|
|
|
* |
53
|
|
|
* Checks that the type loaded is instance of SettingTypeInterface. |
54
|
|
|
* |
55
|
|
|
* @param SettingTypeInterface $type |
56
|
|
|
* |
57
|
|
|
* @return void |
58
|
|
|
* @throws \RuntimeException if invalid |
59
|
|
|
*/ |
60
|
13 |
|
public function validate($type) |
61
|
|
|
{ |
62
|
13 |
|
if ($type instanceof SettingTypeInterface) { |
63
|
12 |
|
return; // we're okay |
64
|
|
|
} |
65
|
1 |
|
throw new InvalidServiceException(sprintf( |
66
|
1 |
|
'SettingType of type "%s" is invalid; must implement "%s"', |
67
|
1 |
|
(is_object($type) ? get_class($type) : gettype($type)), |
68
|
|
|
SettingTypeInterface::class |
69
|
1 |
|
)); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|