coolephp / goaop
Bringing the goaop to Coole. - 将 goaop 集成到 Coole。
Fund package maintenance!
Wechat
Requires
- goaop/framework: ^2.0
- guanguans/coole: ^1.0
Requires (Dev)
- brainmaestro/composer-git-hooks: ^2.7
- friendsofphp/php-cs-fixer: ^2.16
- mockery/mockery: ^1.2
- phpunit/phpunit: ^7 || ^8
- vimeo/psalm: ^3.11
README
Bringing the goaop to Coole. - 将 goaop 集成到 Coole。
Requirement
- Coole >= 1.0
Installation
$ composer require coolephp/goaop -vvv
Usage
Configuration
- 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, ], ];
Create a class app\Service\LoggingService
<?php namespace App\Service; class LoggingService { public static function logging() { return true; } }
Create a aspect App\Aspect\LoggingServiceAspect
<?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); } }
Run App\Service\LoggingService::logging()
cat runtime/logging.log
───────┬─────────────────────────────────────────────────────────────────── │ File: runtime/logging.log ───────┼─────────────────────────────────────────────────────────────────── 1 │ this is a before method testing. 2 │ this is a after method testing. ───────┴───────────────────────────────────────────────────────────────────
Testing
$ composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.