29 public function __construct(\
Magento\Framework\Code\Reader\ArgumentsReader $argumentsReader =
null)
31 $this->_argumentsReader = $argumentsReader ?: new \Magento\Framework\Code\Reader\ArgumentsReader();
45 public function validate($pluginClass, $interceptedType)
47 $interceptedType =
'\\' . trim($interceptedType,
'\\');
48 $pluginClass =
'\\' . trim($pluginClass,
'\\');
49 $plugin = new \ReflectionClass($pluginClass);
50 $type = new \ReflectionClass($interceptedType);
52 foreach ($plugin->getMethods(\ReflectionMethod::IS_PUBLIC) as $pluginMethod) {
55 if ($originMethodName ===
null) {
58 if (!
$type->hasMethod($originMethodName)) {
59 throw new ValidatorException(
61 'Incorrect interface in %1. There is no method [ %2 ] in %3 interface',
62 [$pluginClass, $originMethodName, $interceptedType]
66 $originMethod =
$type->getMethod($originMethodName);
73 $subject = array_shift($pluginMethodParameters);
74 if (!$this->_argumentsReader->isCompatibleType(
77 ) || $subject[
'type'] === null
79 throw new ValidatorException(
81 'Invalid [%1] $%2 type in %3::%4. It must be compatible with %5',
82 [$subject[
'type'], $subject[
'name'], $pluginClass, $pluginMethod->getName(), $interceptedType]
87 switch ($methodType) {
90 $pluginMethodParameters,
91 $originMethodParameters,
93 $pluginMethod->getName()
97 $proceed = array_shift($pluginMethodParameters);
98 if (!$this->_argumentsReader->isCompatibleType($proceed[
'type'],
'\\Closure')) {
99 throw new ValidatorException(
101 'Invalid [%1] $%2 type in %3::%4. It must be compatible with \\Closure',
102 [$proceed[
'type'], $proceed[
'name'], $pluginClass, $pluginMethod->getName()]
107 $pluginMethodParameters,
108 $originMethodParameters,
110 $pluginMethod->getName()
114 if (count($pluginMethodParameters) > 1) {
116 array_shift($pluginMethodParameters);
117 $matchedParameters = array_intersect_key($originMethodParameters, $pluginMethodParameters);
119 $pluginMethodParameters,
122 $pluginMethod->getName()
143 if (count($pluginParameters) != count($originParameters)) {
146 'Invalid method signature. Invalid method parameters count in %1::%2',
151 foreach ($pluginParameters as $position =>
$data) {
152 if (!$this->_argumentsReader->isCompatibleType(
$data[
'type'], $originParameters[$position][
'type'])) {
155 'Incompatible parameter type [%1 $%2] in %3::%4. It must be compatible with %5',
172 $parameterClass = $parameter->getClass();
173 $type = $parameterClass ?
'\\' . $parameterClass->getName() : ($parameter->isArray() ?
'array' :
null);
189 return lcfirst(substr($pluginMethodName, 6));
192 return lcfirst(substr($pluginMethodName, 5));
208 if (substr($pluginMethodName, 0, 6) == self::METHOD_BEFORE) {
210 }
elseif (substr($pluginMethodName, 0, 6) == self::METHOD_AROUND) {
212 }
elseif (substr($pluginMethodName, 0, 5) == self::METHOD_AFTER) {
229 foreach (
$method->getParameters() as $parameter) {
230 $output[$parameter->getPosition()] = [
231 'name' => $parameter->getName(),
getParametersType(\ReflectionParameter $parameter)
elseif(isset( $params[ 'redirect_parent']))
getOriginMethodName($pluginMethodName)
getMethodParameters(\ReflectionMethod $method)
$_option $_optionId $class
validateMethodsParameters(array $pluginParameters, array $originParameters, $class, $method)
__construct(\Magento\Framework\Code\Reader\ArgumentsReader $argumentsReader=null)
getMethodType($pluginMethodName)