Bringing the goaop to Coole. - 将 goaop 集成到 Coole。
- Coole >= 1.0
$ composer require coolephp/goaop -vvv
- Copy
goaop/config/goaop.php
tocoole-skeleton/config/goaop.php
. - Config
\Coole\Goaop\GoAopServiceProvider::class
service provider.
<?php
return [
/*
* App 名称
*/
'name' => env('APP_NAME', 'Coole'),
...
/*
* 第三方服务
*/
'providers' => [
\Coole\Goaop\GoAopServiceProvider::class
],
...
];
- Add a aspect configuration for
config/goaop.php
.
<?php
return [
/*
* AOP Debug Mode
*/
'debug' => env('GOAOP_DEBUG', env('APP_DEBUG', false)),
...
/*
* Yours aspects
*/
'aspects' => [
\App\Aspect\LoggingServiceAspect::class,
],
];
<?php
namespace App\Service;
class LoggingService
{
public static function logging()
{
return true;
}
}
<?php
namespace App\Aspect;
use Go\Aop\Aspect;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Annotation\After;
use Go\Lang\Annotation\Before;
class LoggingServiceAspect implements Aspect
{
/**
* Method that will be called before real method.
*
* @param MethodInvocation $invocation Invocation
* @Before("execution(public App\Service\LoggingService::logging(*))")
*/
public function beforeMethodExecution(MethodInvocation $invocation)
{
file_put_contents(base_path('runtime/logging.log'), 'this is a before method testing.'.PHP_EOL, FILE_APPEND);
}
/**
* Method that will be called after real method.
*
* @param MethodInvocation $invocation Invocation
* @After("execution(public App\Service\LoggingService::logging(*))")
*/
public function afterMethodExecution(MethodInvocation $invocation)
{
file_put_contents(base_path('runtime/logging.log'), 'this is a after method testing.'.PHP_EOL, FILE_APPEND);
}
}
cat runtime/logging.log
───────┬───────────────────────────────────────────────────────────────────
│ File: runtime/logging.log
───────┼───────────────────────────────────────────────────────────────────
1 │ this is a before method testing.
2 │ this is a after method testing.
───────┴───────────────────────────────────────────────────────────────────
$ composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.