PHP code example of yuanzhihai / think-aop

1. Go to this page and download the library: Download yuanzhihai/think-aop library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yuanzhihai / think-aop example snippets



return [
    'scans'        => [
        base_path('aspect') => 'app\aspect',
    ],
    'storage_path' => runtime_path('aop') . 'aopProxyClasses',
    'aspect' => [
        \app\aspect\UserAspect::class,
    ],
];


namespace app\service;

class UserService
{
    public function info()
    {
        echo 'UserService info' . PHP_EOL;
    }
}


namespace app\aspect;

use app\service\UserService;
use Ting\Aop\AbstractAspect;
use Ting\Aop\interfaces\ProceedingJoinPointInterface;

/**
 * Class UserAspect
 * @package app\aspect
 */
class UserAspect extends AbstractAspect
{
    public $classes = [
        UserService::class . '::info',
    ];

    /**
     * @param ProceedingJoinPointInterface $entryClass
     * @return mixed
     */
    public function process(ProceedingJoinPointInterface $entryClass)
    {
        echo 'UserAspect before <br>';
        $res = $entryClass->process();
        echo '<br> UserAspect after';
        return $res;
    }
}


    public function index()
    {
        /** @var UserService $userService */
        $userService = app()->get(UserService::class);
        $userService->info();
    }