Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 827576c

Browse files
atwixfirsterjeff-matthews
authored andcommitted
magento/devdocs#: Plugins (Interceptors). Add plugin method naming convention. (#5200)
* magento/devdocs#: Plugins. Add plugin method naming convention. https://devdocs.magento.com/guides/v2.2/extension-dev-guide/plugins.html https://devdocs.magento.com/guides/v2.3/extension-dev-guide/plugins.html * magento/devdocs#: Plugins. Add plugin method naming convention. * magento/devdocs#: Plugins. Add plugin method naming convention. * magento/devdocs#: Plugins. Add plugin method naming convention.
1 parent e8168f4 commit 827576c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

guides/v2.2/extension-dev-guide/plugins.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,44 @@ By applying code before, after, or around a public method, a plugin extends or m
5757

5858
The first argument for the before, after, and around methods is an object that provides access to all public methods of the observed method's class.
5959

60+
### Plugin method naming convention
61+
62+
It is a Magento best practice to capitalize the first letter of the class method name for which you want to create a plugin before adding `before`, `around` or `after` prefixes to it.
63+
64+
For example, to create a plugin for the `setName` method of some class:
65+
66+
```php
67+
...
68+
public function setName($name)
69+
{
70+
...
71+
}
72+
...
73+
```
74+
75+
In the plugin class, the `setName` method may have one of the following names:
76+
- `beforeSetName`
77+
- `aroundSetName`
78+
- `afterSetName`
79+
80+
If the first letter in the name of the class method name for which you want to create a plugin is the `underscore` character, then you do not need to capitalize it in the plugin class.
81+
82+
For example, to create a plugin for the `_construct` method of some class:
83+
84+
```php
85+
...
86+
public function _construct()
87+
{
88+
...
89+
}
90+
...
91+
```
92+
93+
Use the following method names for the `_construct` method in the plugin class:
94+
- `before_construct`
95+
- `around_construct`
96+
- `after_construct`
97+
6098
#### Before methods
6199

62100
Magento runs all before methods ahead of the call to an observed method. These methods must have the same name as the observed method with 'before' as the prefix.

0 commit comments

Comments
 (0)