https://github.com/lisachenko/yii-aspect
Playground for integration of aspect-oriented programming with YII
https://github.com/lisachenko/yii-aspect
Last synced: about 1 year ago
JSON representation
Playground for integration of aspect-oriented programming with YII
- Host: GitHub
- URL: https://github.com/lisachenko/yii-aspect
- Owner: lisachenko
- Created: 2013-02-06T14:47:12.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2013-09-28T15:12:16.000Z (over 12 years ago)
- Last Synced: 2025-03-23T22:14:03.872Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 409 KB
- Stars: 10
- Watchers: 5
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Description
------------
Yii skeleton with some tweaks + [Go AOP PHP](https://github.com/lisachenko/go-aop-php).
This project allows you to test [aspect-oriented programming](http://en.wikipedia.org/wiki/Aspect-oriented_programming) with Yii framework.
Installation
------------
Installation process is pretty easy, only few steps:
```bash
git clone https://github.com/lisachenko/yii-aspect.git && cd yii-aspect
composer install
```
After that add a `/app` folder as a home directory for web server and just open it in browser.
Aspect definition
-----------------
Aspect class is defined in [TestMonitorAspect](https://github.com/lisachenko/yii-aspect/blob/master/app/protected/extensions/go-aop-php/TestMonitorAspect.php) class:
```php
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()),
"
\n";
}
}
```
How it works?
-------------
Main feature of AOP is that it doesn't require any changes in the original source code. There is a weaver that modifies logic of original classes and methods according to the rules defined in aspects. So in our example we create an advice (body of the beforeMethodExecution() method) that will receive a MethodInvocation instance as an argument. Next step is to decide where this advice should be applied (it's a pointcut). Here we define "within" pointcut for all public and protected methods (both dynamic and static) with the help of "**" that will match any class. Annotation "@Before" is used to specify, that we want our hook to be called before original method.
Each aspect should be registed in the application [aspect kernel](https://github.com/lisachenko/yii-aspect/blob/master/app/protected/extensions/go-aop-php/ApplicationAspectKernel.php).