2.6. Aspect Anotation

You can set up registration of Aspect also @S2Aspect annotation. In the following example, TraceInterceptor is aspected to the findById method of Dao class.

<?php
class Dao {
    /**
     * S2Aspect('new seasar\aop\interceptor\TraceInterceptor')
     */
    public function findById($id) {
        return 2009;
    }
}

Let's create the following Action class. The setDao setter method which receives the Dao component is implemented. Within the getById method of Action class, processing is performed using the findById method of Dao class.

<?php
/**
 * @S2Component('name' => 'act')
 */
class Action{
    private $dao = null;
    public function setDao(Dao $dao) {
        $this->dao = $dao;
    }
    public function getById() {
        return $this->dao->findById(10);
    }
}

When Action component is taken out by the s2get function and the getById method is called, the trace log at the time of the findById method of Dao class being performed will be outputted.

require_once('S2Container.php');

s2import(dirname(__FILE__) . '/classes');
$action = s2get('Action');
$action->getById();
[Note]NOTE

This Example is located at "examples/quickstart/quickstart040.php".



© Copyright The Seasar Foundation and the others 2005-2010, all rights reserved.