Skip to content

Instantly share code, notes, and snippets.

@ranacseruet
Created January 3, 2014 06:33
Show Gist options
  • Save ranacseruet/8233791 to your computer and use it in GitHub Desktop.
Save ranacseruet/8233791 to your computer and use it in GitHub Desktop.
Go! AOP Test
<?php
use \Go\Core\AspectKernel;
use \Go\Core\AspectContainer;
/**
* Application Aspect Kernel
*/
class ApplicationAspectKernel extends AspectKernel
{
/**
* Configure an AspectContainer with advisors, aspects and pointcuts
*
* @param AspectContainer $container
*
* @return void
*/
protected function configureAop(AspectContainer $container)
{
$container->registerAspect(new \Aspect\MonitorAspect());
}
}
*********************************************************
<?php
namespace Aspect;
use \Go\Aop\Aspect;
use \Go\Aop\Intercept\MethodInvocation;
use \Go\Lang\Annotation\Before;
/**
* Monitor aspect
*/
class MonitorAspect implements Aspect
{
function __construct() {
echo "initialized<br>";
}
/**
* @Before("call(public Test->*(*))")
*/
public function beforeMethodExecution(MethodInvocation $invocation)
{
echo "caught here";
/*$obj = $invocation->getThis();
echo 'Calling Before Interceptor for method: ',
is_object($obj) ? get_class($obj) : $obj,
$invocation->getMethod()->isStatic() ? '::' : '->',
$invocation->getMethod()->getName(),
'()',
' with arguments: ',
json_encode($invocation->getArguments()),
"<br>\n";*/
}
}
************************************
<?php
namespace Test;
class Test
{
function __construct() {
;
}
function show()
{
echo "showing something";
}
//put your code here
}
**********************************************
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
require_once __DIR__.'/vendor/autoload.php';
include "src/Test/Test.php";
include "src/ApplicationAspectKernel.php";
include "src/Aspect/MonitorAspect.php";
use \ApplicationAspectKernel, Test\Test;
$applicationAspectKernel = ApplicationAspectKernel::getInstance();
$applicationAspectKernel->init(array(
'debug' => true, // Use 'false' for production mode
// Cache directory
'cacheDir' => __DIR__ . '/cache/',
'includePaths' => array(
__DIR__ . '/src/'
)
));
$test = new Test();
$test->show();
@lisachenko
Copy link

You have wrong definition of pointcut. There is no "call" join point, only "execution", look at examples in documentation. There are also examples in the smoke test: https://github.com/lisachenko/go-aop-php/blob/master/tests/Go/Aop/Pointcut/PointcutParserTest.php#L57-L96

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment