sfAspectPlugin - 1.0.2

Symfony plugin for AOP

You are currently browsing
the website for symfony 1

Visit the Symfony2 website

« Back to the Plugins Home


Forgot your password?
Create an account



advanced search
Information Readme Releases Changelog Contribute
Show source

sfAspectPlugin (for symfony 1.2)

The sfAspectPlugin allows you implement symfony aplication using the paradigm of Aspect oriented programming. This plugin was implemented using the classes library located in PHP Classes, but some changes were made to adapt it to symfony framework.


To install the latest release, execute:

> symfony plugin:install sfAspectPlugin

or to install the current revision, checkout the HEAD revision into a plugins/sfAspectPlugin folder:

> svn co http://svn.symfony-project.com/plugins/sfAspectPlugin

Now let's configure plugin.



The first thing you must do, is to create a folder with name "aspect" within of the folder "config" of the project. Within "aspect" folder, you must put a file with the name "config_aspect.yml". The structure of this file is similar to file "autoload.yml". There is an example of this file bellow.

  project:                       # Entrance of configuration, the name depends on the
                                 # developer appropriateness, it's just a label.

    path:           %SF_LIB_DIR% # Path of the folder where classes are found to which
                                 # aspects must be applied . To give value to path you
                                 # can take the file "autoload.yml" as example.

    recursive:      on           # If it is set in "on" all classes in subdirectories
                                 # will be processed , but if it is set in "off" only
                                 # the classes in the root directory will be processed.

    exclude_dir:    [model]      # Name of the subdirectories must be excluded. In this
                                 # case  the  "model" folder is excluded, If nothing
                                 # is put, no subdirectories will be excluded.

    exclude_class:  []           # Name of classes must be excluded, in this case any
                                 # class is excluded.

    file_aspect:    []           # Name of Files which contain the aspect that must be
                                 # applied, if nothing is specified,all the aspects
                                 # will be applied  declared in file ".xml" in folder
                                 # "config/aspect". If you put a name to the file, you
                                 # must not put the extension ".xml"

Definition of aspects

The definition of aspects must be put in XML file, located in the folder "config/aspect" of the project. You can create as many files XML as you needed. a simple example is given bellow.


Suppose we have a class located in the directory "lib/" of the project with name "TestAspect" with this statement.

class TestAspect{
  var $message;
  function TestAspect($m) {
  function setMessage($m) {
    $this->message = $m;
  function getMessage() {
    return $this->message;
  function display() {
    echo $this->message;

In a XML file located in the folder "config/aspect", you must declare the aspect that must be applied to the classes. This file can have any name, in this case we will put "debugger.xml". the declaration is given bellow.

<?xml version="1.0" encoding="utf-8"?>
    <pointcut auto="after" function="setMessage">
        echo "End of " . __FUNCTION__ ."(" . $m . ") call.<br />";

    <pointcut auto="after" class="Test" nfunction="display">
        echo "End of " . __FUNCTION__ ." call.<br />";

    <pointcut auto="before" nfunction="display">
        echo "Beginning of " . __FUNCTION__ ." call.<br />";

    <pointcut auto="around" function="display" class="Test">
        echo "<b>Message: </b>";
    echo "<br />";

After this, you can put a configuration similar to the sections "config_aspect.yml".

There is a manual within the plugin that explains the filosofy of the work with aspect in details.


If you have any question or suggestion about the use of this plugin, please send it to: renierricardo@uci.cu