3
保護されたメソッドを傍受できないのはなぜですか?
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インターセプトされる前にするします。もちろん、次のようにpreferencein di.xmlofのモジュールを作成することで簡単に変更できます。 <?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のロジックを「乱雑」にできるようにするなど、他の理由がありますか?
14
magento2