-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Base interfaces for function invocation and interception #53
- Loading branch information
1 parent
fbd8d10
commit cc9b8d5
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |