Created
April 1, 2015 10:11
-
-
Save andreyvk/e7e9ad97d735fba42037 to your computer and use it in GitHub Desktop.
Simple go-aop-php problem
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
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(); |
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
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); | |
} | |
} |
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
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()); | |
} | |
} |
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
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