PUGX/aop — pull request #5 by kpacha (2013-07-23 00:40:22+00:00)
Title: Inspecting parameters

I added a new stage between 'Before' and 'Execution' where the aspect execution could inspect and alter a parameter. I called this stage 'Validation' but I think 'Inspection' or 'Enforce' would be more accurated. That's because the aspects triggered here could return a value to replace the original value of the inspected parameter.

The enhaced code for

/**
* @Validator(parameter="a",value=Validator::POSITIVE)
*/
public function getSquareRoot($a)

is like this:

public function getSquareRoot($a)
{
...

// Validation stage
if(($result = $this->__CG_PUGX_AOP__aspectValidator->trigger(new \PUGX\AOP\Aspect\Validator\Annotation(array('when' => 'validation', 'parameter' => 'a', 'value' => '0')), $this, 'getSquareRoot', array($a))) !== null) $a = $result;

...

}

With this stage you could inspect and enforce the parameter value, without changing the method implementation. You can imagine some kind of Fail Fast aspect (like the Validator one) or an adapter to fit some new requirements not implemented yet in the clients (say your API has change and you can not force your clients to be updated)