Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Namespaces | Data Structures | Functions | Variables
Magento\Framework\Interception Namespace Reference

Namespaces

 Code
 
 Config
 
 Definition
 
 Fixture
 
 ObjectManager
 
 PluginList
 
 Test
 

Data Structures

class  AbstractPlugin
 
interface  ConfigInterface
 
interface  DefinitionInterface
 
class  GeneralTest
 
interface  InterceptorInterface
 
interface  PluginListInterface
 
class  TwoPluginTest
 

Functions

 ___init ()
 
 ___callParent ($method, array $arguments)
 
 __sleep ()
 
 __wakeup ()
 
 ___callPlugins ($method, array $arguments, array $pluginInfo)
 

Variables

trait Interceptor
 

Detailed Description

Interception config. Tells whether plugins have been added for type.

Copyright © Magento, Inc. All rights reserved. See COPYING.txt for license details.

Plugin method definitions. Provide the list of interception methods in specified plugin.

Copyright © Magento, Inc. All rights reserved. See COPYING.txt for license details.

Copyright © Magento, Inc. All rights reserved. See COPYING.txt for license details.

List of plugins configured in application

Copyright © Magento, Inc. All rights reserved. See COPYING.txt for license details.

Function Documentation

◆ ___callParent()

Magento\Framework\Interception\___callParent (   $method,
array  $arguments 
)

Calls parent class method

Parameters
string$method
array$arguments
Returns
mixed

Definition at line 56 of file Interceptor.php.

57  {
58  return parent::$method(...array_values($arguments));
59  }
$method
Definition: info.phtml:13
$arguments

◆ ___callPlugins()

Magento\Framework\Interception\___callPlugins (   $method,
array  $arguments,
array  $pluginInfo 
)
protected

Calls plugins for a given method.

Parameters
string$method
array$arguments
array$pluginInfo
Returns
mixed|null

Definition at line 98 of file Interceptor.php.

99  {
100  $subject = $this;
101  $type = $this->subjectType;
102  $pluginList = $this->pluginList;
103 
104  $next = function (...$arguments) use (
105  $method,
106  &$pluginInfo,
107  $subject,
108  $type,
109  $pluginList,
110  &$next
111  ) {
112  $capMethod = ucfirst($method);
113  $currentPluginInfo = $pluginInfo;
114  $result = null;
115 
116  if (isset($currentPluginInfo[DefinitionInterface::LISTENER_BEFORE])) {
117  // Call 'before' listeners
118  foreach ($currentPluginInfo[DefinitionInterface::LISTENER_BEFORE] as $code) {
119  $pluginInstance = $pluginList->getPlugin($type, $code);
120  $pluginMethod = 'before' . $capMethod;
121  $beforeResult = $pluginInstance->$pluginMethod($this, ...array_values($arguments));
122 
123  if ($beforeResult !== null) {
124  $arguments = (array)$beforeResult;
125  }
126  }
127  }
128 
129  if (isset($currentPluginInfo[DefinitionInterface::LISTENER_AROUND])) {
130  // Call 'around' listener
131  $code = $currentPluginInfo[DefinitionInterface::LISTENER_AROUND];
132  $pluginInfo = $pluginList->getNext($type, $method, $code);
133  $pluginInstance = $pluginList->getPlugin($type, $code);
134  $pluginMethod = 'around' . $capMethod;
135  $result = $pluginInstance->$pluginMethod($subject, $next, ...array_values($arguments));
136  } else {
137  // Call original method
138  $result = $subject->___callParent($method, $arguments);
139  }
140 
141  if (isset($currentPluginInfo[DefinitionInterface::LISTENER_AFTER])) {
142  // Call 'after' listeners
143  foreach ($currentPluginInfo[DefinitionInterface::LISTENER_AFTER] as $code) {
144  $pluginInstance = $pluginList->getPlugin($type, $code);
145  $pluginMethod = 'after' . $capMethod;
146  $result = $pluginInstance->$pluginMethod($subject, $result, ...array_values($arguments));
147  }
148  }
149 
150  return $result;
151  };
152 
153  $result = $next(...array_values($arguments));
154  $next = null;
155 
156  return $result;
157  }
$type
Definition: item.phtml:13
$method
Definition: info.phtml:13
$arguments
$code
Definition: info.phtml:12

◆ ___init()

Magento\Framework\Interception\___init ( )

Initialize the Interceptor

Returns
void

Definition at line 40 of file Interceptor.php.

41  {
42  $this->pluginList = ObjectManager::getInstance()->get(PluginListInterface::class);
43  $this->subjectType = get_parent_class($this);
44  if (method_exists($this->subjectType, '___init')) {
46  }
47  }

◆ __sleep()

Magento\Framework\Interception\__sleep ( )

Calls parent class sleep if defined, otherwise provides own implementation

Returns
array

Definition at line 66 of file Interceptor.php.

67  {
68  if (method_exists(get_parent_class($this), '__sleep')) {
70  } else {
71  $properties = array_keys(get_object_vars($this));
72  }
73  $properties = array_diff($properties, ['pluginList', 'subjectType']);
74  return $properties;
75  }
$properties
Definition: categories.php:26

◆ __wakeup()

Magento\Framework\Interception\__wakeup ( )

Causes Interceptor to be initialized

Returns
void

Definition at line 82 of file Interceptor.php.

83  {
84  if (method_exists(get_parent_class($this), '__wakeup')) {
86  }
87  $this->___init();
88  }

Variable Documentation

◆ Interceptor

trait Interceptor
Initial value:
{
private $pluginList

Interceptor trait that contains the common logic for all interceptor classes.

A trait is used because our interceptor classes need to extend the class that they are intercepting.

Any class using this trait is required to implement \Magento\Framework\Interception\InterceptorInterface

See also
\Magento\Framework\Interception\InterceptorInterface

Definition at line 20 of file Interceptor.php.