My favorites | Sign in
Project Home Wiki Issues Source
Project Information
Members
Links

A lightweight framework for bringing AOP to PHP.

Usage

Entry Point Script

<?php
// Include the framework at the very beginning
require 'aop/aop.php';

/* 
   Add include paths. This serves two purposes:
   1- for the framework to "autoload" the classes
      without having to manage complicated interdependencies
   2- for the framework to "intercept" and "weave"
      the classes before completing the autoloading process
*/
aop::register_class_path( some-path-here );
aop::register_class_path( some-other-path-here );

Pointcut Definition

<?php
/**
 * TestPointcut test class
 * 
 * @author Jean-Lou Dupont
 * http://php-aop.googlecode.com/
 * http://www.ohloh.net/projects/php-aop
 */

class TestClass_pointcuts #the suffix _pointcuts is mandatory

	extends aop_pointcut_definition {

	/**
	 * Pointcut definition
	 *  Will be applied only to the constructor  
	 *  of the class "TestClass"
	 * 
	 *  The code contained in method "before_show" (below)
	 *  will be applied "before" (i.e. at the beginning) of
	 *  the constructor whilst "after_show" will be applied 
	 *  at the end of the method.
	 */
	public function cut_constructor() {

		return array(	'cp' 	=> 'TestClass', 
				'mp'	=> '__construct', 
				'am'	=> array(	'before'=> 'before_show', 
							'after'	=> 'after_show' ) );
	
	}
	
	/**
	 * Pointcut definition
	 *  Will be applied to *all* classes of the project 
	 *  but *only* to the method "show" when present in the said classes.  
	 * 
	 *  The code contained in method "before_show" (below)
	 *  will be applied "before" (i.e. at the beginning) of
	 *  the constructor whilst "after_show" will be applied 
	 *  at the end of the method.
	 */
	public function cut_show() {

		return array(	'cp' 	=> '~',	#all classes 
				'mp'	=> 'show', 
				'am'	=> array(	'before'=> 'before_show', 
							'after'	=> 'after_show' ) );
	
	}

	/**
	 * Advice definition 'before'
	 */
	public function before_show() {
		echo "#BEFORE\n";
	}
	/**
	 * Advice definition 'after'
	 */
	public function after_show() {
		echo "#AFTER\n";		
	}
	
}

Help

Use the group. Some additional information can be found here .

Installation

The extensions are available either through the tags directory in this SVN or better still throught the PEAR channel (see below).

SVN

A more direct link to the SVN and to the TAGS.

PEAR Channel

The PEAR channel can be discovered through the shell command:

pear channel-discover php-aop.googlecode.com/svn

RSS feed

An RSS feed is available [http://feeds.feedburner.com/jldupont/phpaop

Powered by Google Project Hosting