PHP code example of w7 / rangine-aspect

1. Go to this page and download the library: Download w7/rangine-aspect 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/ */

    

w7 / rangine-aspect example snippets




namespace W7\App\Services;

class TestAspectService {
	public function test($arg) {
		return $arg;
	}

	public function test1() {
		return 1;
	}

	public function test2() {
		return 2;
	}
}



namespace W7\App\Aspect;

use W7\App\Services\TestAspectService;
use W7\Aspect\Aop\AspectAbstract;
use W7\Aspect\Aop\AspectJoinPoint;

class TestAspect extends AspectAbstract {
    //表示切入到TestAspectService类的test和test1方法
	public static $classMethodMap = [
		TestAspectService::class => [
			'test',
			'test1'
		]
	];

	public function process(AspectJoinPoint $aspectJoinPoint, \Closure $next) {
		var_dump('aspect before ' . $aspectJoinPoint->class . ':' . $aspectJoinPoint->method);

		$result = $next($aspectJoinPoint);

		var_dump('aspect after ' . $aspectJoinPoint->class . ':' . $aspectJoinPoint->method);

		return $result;
	}
}

(new TestAspectService())->test('woshishui');
var_dump((new TestAspectService())->test1());
var_dump((new TestAspectService())->test2());

php artisan aspect:build