- /**
- * Calls plugins for a given method.
- *
- * @param string $method
- * @param array $arguments
- * @param array $pluginInfo
- * @return mixed|null
- */
- protected function ___callPlugins($method, array $arguments, array $pluginInfo)
- {
- $capMethod = ucfirst($method);
- $result = null;
- if (isset($pluginInfo[DefinitionInterface::LISTENER_BEFORE])) {
- // Call 'before' listeners
- foreach ($pluginInfo[DefinitionInterface::LISTENER_BEFORE] as $code) {
- $pluginInstance = $this->pluginList->getPlugin($this->subjectType, $code);
- $pluginMethod = 'before' . $capMethod;
- $beforeResult = $pluginInstance->$pluginMethod($this, ...array_values($arguments));
- if ($beforeResult) {
- $arguments = $beforeResult;
- }
- unset($pluginInstance, $pluginMethod);
- }
- }
- if (isset($pluginInfo[DefinitionInterface::LISTENER_AROUND])) {
- // Call 'around' listener
- $chain = $this->chain;
- $type = $this->subjectType;
- /** @var \Magento\Framework\Interception\InterceptorInterface $subject */
- $subject = $this;
- $code = $pluginInfo[DefinitionInterface::LISTENER_AROUND];
- $next = function () use ($chain, $type, $method, $subject, $code) {
- return $chain->invokeNext($type, $method, $subject, func_get_args(), $code);
- };
- $pluginInstance = $this->pluginList->getPlugin($this->subjectType, $code);
- $pluginMethod = 'around' . $capMethod;
- $result = $pluginInstance->$pluginMethod($this, $next, ...array_values($arguments));
- unset($pluginInstance, $pluginMethod);
- } else {
- // Call original method
- $result = parent::$method(...array_values($arguments));
- }
- if (isset($pluginInfo[DefinitionInterface::LISTENER_AFTER])) {
- // Call 'after' listeners
- foreach ($pluginInfo[DefinitionInterface::LISTENER_AFTER] as $code) {
- $result = $this->pluginList->getPlugin($this->subjectType, $code)
- ->{'after' . $capMethod}($this, $result);
- }
- }
- return $result;
- }