The before plugin, as its name suggests, runs before the observed method.
When writing a before plugin, there are a few key points to remember:
- The before keyword is appended to the observed instance method. If the observed method is called getSomeValue, then the plugin method is called beforeGetSomeValue.
- The first parameter of the before plugin method is always the observed instance type, often abbreviated as $subject or directly by the class type – which is $processor in our example. We can typecast it for greater readability.
- All other parameters of the plugin method must match the parameters of the observed method.
- The plugin method must return an array with the same type and number of parameters as the observed method's ...