왜 protected메소드 용 플러그인을 만들 수 없는지 궁금했습니다 . 이 코드는 다음과 Magento\Framework\Interception\Code\Generator\Interceptor같습니다.
protected function _getClassMethods()
{
$methods = [$this->_getDefaultConstructorDefinition()];
$reflectionClass = new \ReflectionClass($this->getSourceClassName());
$publicMethods = $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC);
foreach ($publicMethods as $method) {
if ($this->isInterceptedMethod($method)) {
$methods[] = $this->_getMethodInfo($method);
}
}
return $methods;
}
메소드가 public인터셉트되기 전에 있는지 확인합니다 . 그것은 쉽게를 작성하여 변경 될 수 preference에서 di.xml다음과 같이 물론, 자신의 모듈 :
<?xml version="1.0"?>
<config>
<preference for="Magento\Framework\Interception\Code\Generator\Interceptor" type="MyVendor\MyModule\Model\MyInterceptorModel" />
</config>
및 재기록 _getClassMethods(가)로 \ReflectionMethod::IS_PUBLIC변경 \ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED하는 방법의 내부.
그러나 원래 메서드 정의에서 보호 된 메서드를 가로 챌 수없는 이유가 무엇입니까? 성능에 큰 영향을 미치거나 타사 모듈이 Magento 논리를 "지저분하게"만들도록 허용하는 것과 같은 다른 이유가 있습니까?