diff --git a/src/AnnotationManager.php b/src/AnnotationManager.php index 7d06bfe..f38b710 100644 --- a/src/AnnotationManager.php +++ b/src/AnnotationManager.php @@ -18,6 +18,7 @@ namespace Ytake\LaravelAspect; use Illuminate\Support\Manager; +use Doctrine\Common\Annotations\AnnotationReader; /** * Class AnnotationManager @@ -39,6 +40,7 @@ public function getDefaultDriver() */ protected function createArrayDriver() { + $this->ignoredAnnotations($this->app['config']->get('ytake-laravel-aop.annotation.ignores', [])); return new ArrayReader(); } @@ -47,6 +49,7 @@ protected function createArrayDriver() */ protected function createFileDriver() { + $this->ignoredAnnotations($this->app['config']->get('ytake-laravel-aop.annotation.ignores', [])); return new FileReader($this->getConfigure('file')); } @@ -60,4 +63,15 @@ protected function getConfigure($driver) return $annotationConfigure[$driver]; } + + /** + * Add a new annotation to the globally ignored annotation names with regard to exception handling. + * @param array $ignores + */ + private function ignoredAnnotations(array $ignores = []) + { + foreach ($ignores as $ignore) { + AnnotationReader::addGlobalIgnoredName($ignore); + } + } } diff --git a/src/Modules/AspectModule.php b/src/Modules/AspectModule.php index f1b4260..428c8e1 100644 --- a/src/Modules/AspectModule.php +++ b/src/Modules/AspectModule.php @@ -36,10 +36,10 @@ abstract class AspectModule /** @var CompilerInterface */ protected $compiler; - /** @var array */ + /** @var array */ protected static $pointcuts = []; - /** @var array */ + /** @var array */ protected static $resolve = []; /** @var array */ @@ -55,6 +55,7 @@ public function __construct(Application $app) /** * attach pointcut + * * @return void */ public function attach() diff --git a/src/config/ytake-laravel-aop.php b/src/config/ytake-laravel-aop.php index 640315b..33c0895 100644 --- a/src/config/ytake-laravel-aop.php +++ b/src/config/ytake-laravel-aop.php @@ -57,5 +57,20 @@ 'debug' => env('ASPECT_ANNOTATION_DEBUG', false), ], ], + + 'ignores' => [ + // global Ignored Annotations + 'Hears', + 'Get', + 'Post', + 'Put', + 'Patch', + 'Options', + 'Delete', + 'Any', + 'Middleware', + 'Resource', + 'Controller' + ], ], ]; diff --git a/tests/IgnoreAnnotationTest.php b/tests/IgnoreAnnotationTest.php new file mode 100644 index 0000000..8343aac --- /dev/null +++ b/tests/IgnoreAnnotationTest.php @@ -0,0 +1,36 @@ +manager = new \Ytake\LaravelAspect\AspectManager($this->app); + $this->resolveManager(); + } + + public function testGenerateCacheNameRemoveNullKey() + { + /** @var \__Test\AnnotationStub $class */ + $class = $this->app->make(\__Test\AnnotationStub::class); + $this->assertNull($class->testing()); + } + + + /** + * + */ + protected function resolveManager() + { + /** @var \Ytake\LaravelAspect\RayAspectKernel $aspect */ + $aspect = $this->manager->driver('ray'); + $aspect->register(\__Test\LogExceptionsModule::class); + $aspect->dispatch(); + } +} diff --git a/tests/config/ytake-laravel-aop.php b/tests/config/ytake-laravel-aop.php index 1d0b47a..c460c4c 100644 --- a/tests/config/ytake-laravel-aop.php +++ b/tests/config/ytake-laravel-aop.php @@ -42,5 +42,10 @@ 'debug' => true, ], ], + 'ignores' => [ + // global Ignored Annotations + 'Get', + 'Resource' + ], ], ]; diff --git a/tests/src/AnnotationStub.php b/tests/src/AnnotationStub.php new file mode 100644 index 0000000..f61f3b5 --- /dev/null +++ b/tests/src/AnnotationStub.php @@ -0,0 +1,25 @@ +