Statement

DECLARE tangent

The Aspect class is similar to any other normal bean and may have methods and fields like any other class, but they will use @Aspect comments, as follows:

use Swoft\Aop\Annotation\Mapping\Aspect;

/**
 * Class DemoAspect
 *
 * @since 2.0
 *
 * @Aspect(order=1)
 */
class DemoAspect
{
    // ...
}

@Aspect

Define a class as a tangent class

  • Order priority, multiple tangent, smaller pre-execution

Disclaimer entry Point

An entry point helps to identify the connection points (that is, methods) that are of interest to different opinion execution.

/**
 * Class DemoAspect
 *
 * @since 2.0
 *
 * @Aspect(order=1)
 *
 * @PointBean(
 *     include={"testOrderAop"}
 * )
 */
class DemoAspect
{
    // ...
}

@PointBean

Defines the bean pointcut, and the method execution in this bean class passes through the proxy of this tangent class

  • Include defines the collection of entity names that need to be cut in
  • Exclude define the collection of entity names that need to be excluded

@PointAnnotation

Defines the annotation entry point, and all methods that contain the corresponding annotation are passed through the proxy of this tangent class

  • Include definition _ annotation Name _ collection that needs to be cut in
  • Exclude defines the set of annotations that need to be excluded

PointExecution

Define matching pointcuts, indicating which methods to proxy the target class

  • Include definition matching collections that need to be cut in, matching class methods, supporting regular expressions
  • Exclude defines matching collections that need to be sorted, matching class methods, and supporting regular expressions

The relationship between the @PointBean, @PointAnnotation, @PointExecution three definitions is the same set, and the exclusions defined in the three kinds are also excluded after the set. It is recommended that, for ease of understanding and use, one facet class use only one of the above three

Disclaimer Notification

use Swoft\Aop\Annotation\Mapping\After;
use Swoft\Aop\Annotation\Mapping\AfterReturning;
use Swoft\Aop\Annotation\Mapping\AfterThrowing;
use Swoft\Aop\Annotation\Mapping\Around;
use Swoft\Aop\Annotation\Mapping\Aspect;
use Swoft\Aop\Annotation\Mapping\Before;
use Swoft\Aop\Annotation\Mapping\PointBean;
use Swoft\Aop\Point\JoinPoint;
use Swoft\Aop\Point\ProceedingJoinPoint;

/**
 * Class DemoAspect
 *
 * @since 2.0
 *
 * @Aspect(order=1)
 *
 * @PointBean(
 *     include={"testOrderAop"}
 * )
 */
class DemoAspect
{
    /**
     * @Before()
     */
    public function before()
    {
        // before
    }

    /**
     * @After()
     */
    public function after()
    {
        // After
    }

    /**
     * @AfterReturning()
     *
     * @param JoinPoint $joinPoint
     *
     * @return mixed
     */
    public function afterReturn(JoinPoint $joinPoint)
    {
        $ret = $joinPoint->getReturn();

        // After return

        return $ret;
    }

    /**
     * @Around()
     *
     * @param ProceedingJoinPoint $proceedingJoinPoint
     *
     * @return mixed
     */
    public function around(ProceedingJoinPoint $proceedingJoinPoint)
    {
        // Before around
        $result = $proceedingJoinPoint->proceed();
        // After around

        return $result;
    }

    /**
     * @param \Throwable $throwable
     *
     * @AfterThrowing()
     */
    public function afterThrowing(\Throwable $throwable)
    {
        // afterThrowing
    }
}
  • @Before a front-end notification to execute this method before the target method executes
  • @After post-Notification to execute this method after the target method is executed
  • @AfterReturning Final return notification
  • @AfterThrowing exception Notification that executes this method when the target method performs a throw exception
  • @Around Surround notification to execute this method before and after the target method executes
/docs/2.x/en/aop/statement.html
progress-bar