dev-master
9999999-dev http://raymondkolbe.comA Zend Framework 2 module for wrapping the PECL extension AOP.
MIT
The Requires
- php >=5.3.0
- doctrine/common *
- ext-aop 0.1.0
zf2 aop
A Zend Framework 2 module for wrapping the PECL extension AOP.
An Aspect Oriented Programming (AOP) Module for Zend Framework 2., (*1)
This AOP module wraps the PHP PECL extension AOP into Zend Framework 2. If you're not familiar with AOP, take some time to read up on AspectJ (the Java implementation) and the PHP PECL extension AOP documentation., (*2)
Installation of AOPModule uses PHP Composer. For more information about PHP Composer, please visit the official PHP Composer site., (*3)
cd my/project/directory
create a composer.json
file with following contents:, (*4)
json
{
"minimum-stability" : "dev",
"require": {
"dino/aop-module": "dev-master"
}
}
, (*5)
curl -s http://getcomposer.org/installer | php
(on windows, download
http://getcomposer.org/installer and execute it with PHP)php composer.phar install
open my/project/directory/config/application.config.php
and add the following key to your modules
:, (*6)
php
'AOP',
, (*7)
The only configuration option is an array of paths to where your aspects (classes) are., (*8)
<?php return array( 'aop' => array( 'aspect_class_paths' => array( __DIR__ . '/../src/' . __NAMESPACE__ . '/Aspect' ) ) );
An aspect looks like this:, (*9)
<?php namespace Application\Aspect; use AOP\Annotation\Pointcut; class Security { /** * The pointcut rule can be a standalone rule or an array of rules, * denoted by the curly braces. * * @Pointcut(rule={ * "before Application\Controller\IndexController->*Action()", * "before Application\Controller\AdminController->*Action()" * }) */ public function checkActionPrecondition(\AOPTriggeredJoinPoint $triggeredJoinPoint) { error_log("Check Access Precondition!"); } /** * Take note that the rule is not in array notation. * * @Pointcut(rule="before Application\Controller\IndexController->*Action()") */ public function checkFooBarPrecondition(\AOPTriggeredJoinPoint $triggeredJoinPoint) { error_log("Check Foo Bar Precondition!"); } /** * @Pointcut(rule="after Application\Controller\IndexController->*Action()") */ public function logActionDispatched(\AOPTriggeredJoinPoint $triggeredJoinPoint) { /** * If ServiceLocatorAwareInterface was implemented, we could call: * * $this->getServiceLocator() * ->get('logger') * ->info('We dispatched an action.'); */ error_log("My logging advice!"); } }
The syntax follows that of the AOP PECL extension with the exception of the prepended "before", "after", or "around" keywords to the rule., (*10)
Zend\ServiceManager\ServiceLocatorAwareInterface
, the ServiceManager instance on Application will be injected.A Zend Framework 2 module for wrapping the PECL extension AOP.
MIT
zf2 aop