phpAspect Logo

Chapter 5. Joinpoints

The current implementation of phpAspect counts 3 kinded joinpoints, a lot more will come very soon:

  • Method execution
  • Method call
  • Object construction

There is also 3 non-kinded joinpoints:

  • File
  • Within
  • This

Kinded joinpoints match a specific type of joinpoint using a signature and non-kinded joinpoints match all type of joinpoints using variety of properties.

Method execution joinpoint

The method execution joinpoint identifies certains method executions in the program call graph. The signature of this joinpoint is the following:

exec(method_modifiers ClassName::MethodName(ParametersNumber))

Example 5.1: Exemples of the method execution joinpoint.

<?php
aspect BankTransfer{
    /*Identify all the execution of the public withdraw method
      in the Account class taking one parameter.*/
    poincut withdraw:exec(public Account::withdraw(1));
    /*Identify all the execution of the public deposit method
      in the Account class taking one parameter.*/
    poincut deposit:exec(public Account::deposit(1));
}
?>


Method call joinpoint

The method execution joinpoint identifies certains method calls in the program call graph. The difference with the method execution joinpoint is the context: this joinpoint access the calling context and doesn't see the execution context. The signature of this joinpoint is the following:

call( ClassName->MethodName(ParametersNumber))

Example 5.2: Exemples of the method call joinpoint.

<?php
aspect Chekchout{
    /*Identify all the call of the addItem method
    of the Cart class taking two parameters.*/
    poincut addItem:call(Cart->AddItem(2));
    /*Identify all the call of the checkout method
    of the Cart class with any parameters.*/
    poincut checkout:call(Cart->checkout(0));
}
?>


Construction joinpoint

The construction joinpoint identifies object constructions the program call graph. The signature of this joinpoint is the following:

new(ClassName(ParametersNumber))

Example 5.3: Exemples of the construction joinpoint.

<?php
aspect Singleton{
    /*Identify all the construction of Foo objects with any parameters.*/
    poincut newFoo:new(Foo(*));
    /*Identify all the construction of Bar objects with any parameters.*/
    poincut newBar:new(Bar(*));
}
?>


File joinpoint

This joinpoint is a predicate on the filename where kinded joinpoints can be matched. The signature of this joinpoint is the following:

file(ClassName)

Example 5.4: Exemples of the file joinpoint.

<?php
aspect Context{
   //Match all the foo() calls in the Bar.php filename
   pointcut fooInBar:call(*->bar(*)) && file('Bar.php');
}
?>


Within joinpoint

This joinpoint is a predicate on the class where kinded joinpoints can be matched. The signature of this joinpoint is the following:

within(ClassName)

Example 5.5: Exemples of the within joinpoint.

<?php
aspect Context{
    //Match all the foo() calls in the Bar class.
    pointcut fooInBar:call(*->bar(*)) && within(Bar);
}
?>