Skip to content

Commit

Permalink
Base interfaces for function invocation and interception #53
Browse files Browse the repository at this point in the history
  • Loading branch information
lisachenko committed Jul 27, 2013
1 parent fbd8d10 commit cc9b8d5
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/Go/Aop/Intercept/FunctionInterceptor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Go! OOP&AOP PHP framework
*
* @copyright Copyright 2013, Lissachenko Alexander <[email protected]>
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/

namespace Go\Aop\Intercept;

/**
* Intercepts calls on an interface on its way to the target. These
* are nested "on top" of the target.
*
* <p>The user should implement the {@link invoke(FunctionInvocation)}
* method to modify the original behavior. E.g. the following class
* implements a tracing interceptor (traces all the calls on the
* intercepted method(s)):
*
* <pre class=code>
* class TracingInterceptor implements FunctionInterceptor {
* public function invoke(FunctionInvocation $i) {
* print("method ".$i->getFunction()." is called".
* " with args ".$i->getArguments());
* $ret=$i->proceed();
* print("function ".$i->getFunction()." returns ".$ret);
* return $ret;
* }
* }
* </pre>
*/
interface FunctionInterceptor extends Interceptor
{

/**
* Implement this method to perform extra treatments before and
* after the invocation. Polite implementations would certainly
* like to invoke {@link Joinpoint::proceed()}.
*
* @param FunctionInvocation $invocation the function invocation joinpoint
* @return mixed the result of the call to {@link Joinpoint::proceed()},
* might be intercepted by the interceptor.
*/
public function invoke(FunctionInvocation $invocation);
}
41 changes: 41 additions & 0 deletions src/Go/Aop/Intercept/FunctionInvocation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Go! OOP&AOP PHP framework
*
* @copyright Copyright 2013, Lissachenko Alexander <[email protected]>
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/

namespace Go\Aop\Intercept;

use ReflectionFunction;

/**
* Description of an invocation to a function, given to an interceptor
* upon function-call.
*
* <p>A function invocation is a joinpoint and can be intercepted by a function
* interceptor.
*
* @see FunctionInterceptor
*/
interface FunctionInvocation extends Invocation
{

/**
* Gets the function being called.
*
* <p>This method is a friendly implementation of the
* {@link Joinpoint::getStaticPart()} method (same result).
*
* @return ReflectionFunction the function being called.
*/
public function getFunction();

/**
* Invokes current function invocation with all interceptors
*
* @return mixed
*/
public function __invoke();
}

0 comments on commit cc9b8d5

Please sign in to comment.