मैं सोच रहा था कि 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
लेकिन मुझे आश्चर्य है कि मूल विधि परिभाषा में संरक्षित विधियों को रोकना क्यों संभव नहीं है? क्या यह प्रदर्शन पर एक बड़ा प्रभाव डालता है, या इसके लिए कोई अन्य कारण है, जैसे कि 3 पार्टी मॉड्यूल को मैगेंटो लॉजिक को भी "गड़बड़" बनाने की अनुमति है?