1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* RulePluginManager |
4
|
|
|
* |
5
|
|
|
* @category StrokerForm\Renderer\JqueryValidate\Rule |
6
|
|
|
* @package StrokerForm\Renderer\JqueryValidate\Rule |
7
|
|
|
* @copyright 2013 ACSI Holding bv (http://www.acsi.eu) |
8
|
|
|
* @version SVN: $Id$ |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace StrokerForm\Renderer\JqueryValidate\Rule; |
12
|
|
|
|
13
|
|
|
use Zend\I18n\Translator\TranslatorAwareInterface; |
14
|
|
|
use Zend\ServiceManager\AbstractPluginManager; |
15
|
|
|
use Zend\ServiceManager\ConfigInterface; |
16
|
|
|
|
17
|
|
|
class RulePluginManager extends AbstractPluginManager |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Default set of rules |
21
|
|
|
* |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
protected $invokableClasses = [ |
26
|
|
|
'between' => 'StrokerForm\Renderer\JqueryValidate\Rule\Between', |
27
|
|
|
'creditcard' => 'StrokerForm\Renderer\JqueryValidate\Rule\CreditCard', |
28
|
|
|
'digits' => 'StrokerForm\Renderer\JqueryValidate\Rule\Digits', |
29
|
|
|
'emailaddress' => 'StrokerForm\Renderer\JqueryValidate\Rule\EmailAddress', |
30
|
|
|
'greaterthan' => 'StrokerForm\Renderer\JqueryValidate\Rule\GreaterThan', |
31
|
|
|
'identical' => 'StrokerForm\Renderer\JqueryValidate\Rule\Identical', |
32
|
|
|
'lessthan' => 'StrokerForm\Renderer\JqueryValidate\Rule\LessThan', |
33
|
|
|
'notempty' => 'StrokerForm\Renderer\JqueryValidate\Rule\NotEmpty', |
34
|
|
|
'stringlength' => 'StrokerForm\Renderer\JqueryValidate\Rule\StringLength', |
35
|
|
|
'uri' => 'StrokerForm\Renderer\JqueryValidate\Rule\Uri', |
36
|
|
|
'inarray' => 'StrokerForm\Renderer\JqueryValidate\Rule\InArray', |
37
|
|
|
'regex' => 'StrokerForm\Renderer\JqueryValidate\Rule\Regex', |
38
|
|
|
]; |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Constructor |
43
|
|
|
* |
44
|
|
|
* After invoking parent constructor, add an initializer to inject the |
45
|
|
|
* attached renderer and translator, if any, to the currently requested helper. |
46
|
|
|
* |
47
|
|
|
* @param null|ConfigInterface $configuration |
48
|
|
|
*/ |
49
|
|
|
public function __construct(ConfigInterface $configuration = null) |
50
|
|
|
{ |
51
|
|
|
parent::__construct($configuration); |
52
|
|
|
|
53
|
|
|
$this->addInitializer([$this, 'injectTranslator']); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritDoc} |
58
|
|
|
*/ |
59
|
|
|
public function validatePlugin($plugin) |
60
|
|
|
{ |
61
|
|
|
if ($plugin instanceof RuleInterface) { |
62
|
|
|
// we're okay |
63
|
|
|
return; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
throw new \InvalidArgumentException( |
67
|
|
|
sprintf( |
68
|
|
|
'Plugin of type %s is invalid; must implement %s\RuleInterface', |
69
|
|
|
(is_object($plugin) ? get_class($plugin) : gettype($plugin)), |
70
|
|
|
__NAMESPACE__ |
71
|
|
|
) |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Inject a helper instance with the registered translator |
77
|
|
|
* |
78
|
|
|
* @param RuleInterface $rule |
79
|
|
|
* |
80
|
|
|
* @return void |
81
|
|
|
*/ |
82
|
|
|
public function injectTranslator($rule) |
83
|
|
|
{ |
84
|
|
|
if ($rule instanceof TranslatorAwareInterface) { |
85
|
|
|
$locator = $this->getServiceLocator(); |
86
|
|
|
if ($locator && $locator->has('MvcTranslator')) { |
87
|
|
|
$rule->setTranslator($locator->get('MvcTranslator')); |
|
|
|
|
88
|
|
|
} elseif ($locator && $locator->has('translator')) { |
89
|
|
|
$rule->setTranslator($locator->get('translator')); |
|
|
|
|
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: