Skip to content

Instantly share code, notes, and snippets.

@andreyvk
Created April 1, 2015 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreyvk/e7e9ad97d735fba42037 to your computer and use it in GitHub Desktop.
Save andreyvk/e7e9ad97d735fba42037 to your computer and use it in GitHub Desktop.
Simple go-aop-php problem
namespace php_tests;
use php_tests\aop\TestAspectKernel;
use php_tests\classes\TestClass;
require_once __DIR__.'/lib/vendor/autoload.php';
require_once __DIR__.'/aop/TestAspectKernel.php';
require_once __DIR__.'/aop/TestAspect.php';
require_once __DIR__.'/classes/TestClass.php';
$testAspectKernel = TestAspectKernel::getInstance();
$testAspectKernel->init(array(
'debug' => true, // Use 'false' for production mode
// Cache directory
'cacheDir' => '/tmp', // Adjust this path if needed
// Include paths restricts the directories where aspects should be applied, or empty for all source files
'includePaths' => [
__DIR__,
__DIR__.'/classes'
]
));
$testInst = new TestClass();
$testInst->test();
namespace php_tests\aop;
use Go\Aop\Aspect;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Annotation\Before;
class TestAspect implements Aspect
{
/**
* @param MethodInvocation $invocation Invocation
* @Before("@execution(public TestClass->*(*))")
*/
public function beforeMethodExecution(MethodInvocation $invocation)
{
print_r("Before test is called" . PHP_EOL);
}
}
namespace php_tests\aop;
use Go\Core\AspectKernel;
use Go\Core\AspectContainer;
class TestAspectKernel extends AspectKernel
{
/**
* Configure an AspectContainer with advisors, aspects and pointcuts
* @param AspectContainer $container
* @return void
*/
protected function configureAop(AspectContainer $container)
{
$container->registerAspect(new TestAspect());
}
}
namespace php_tests\classes;
class TestClass
{
public function test()
{
print_r("Test is being called" . PHP_EOL);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment