Skip to content

Commit 203a68c

Browse files
committed
Merge pull request #26 from ytake/feature-ignore-annotations
Feature ignore annotations
2 parents 4e0c783 + dbf542e commit 203a68c

7 files changed

Lines changed: 99 additions & 2 deletions

File tree

src/AnnotationManager.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
namespace Ytake\LaravelAspect;
1919

2020
use Illuminate\Support\Manager;
21+
use Doctrine\Common\Annotations\AnnotationReader;
2122

2223
/**
2324
* Class AnnotationManager
@@ -39,6 +40,7 @@ public function getDefaultDriver()
3940
*/
4041
protected function createArrayDriver()
4142
{
43+
$this->ignoredAnnotations($this->app['config']->get('ytake-laravel-aop.annotation.ignores', []));
4244
return new ArrayReader();
4345
}
4446

@@ -47,6 +49,7 @@ protected function createArrayDriver()
4749
*/
4850
protected function createFileDriver()
4951
{
52+
$this->ignoredAnnotations($this->app['config']->get('ytake-laravel-aop.annotation.ignores', []));
5053
return new FileReader($this->getConfigure('file'));
5154
}
5255

@@ -60,4 +63,15 @@ protected function getConfigure($driver)
6063

6164
return $annotationConfigure[$driver];
6265
}
66+
67+
/**
68+
* Add a new annotation to the globally ignored annotation names with regard to exception handling.
69+
* @param array $ignores
70+
*/
71+
private function ignoredAnnotations(array $ignores = [])
72+
{
73+
foreach ($ignores as $ignore) {
74+
AnnotationReader::addGlobalIgnoredName($ignore);
75+
}
76+
}
6377
}

src/Modules/AspectModule.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ abstract class AspectModule
3636
/** @var CompilerInterface */
3737
protected $compiler;
3838

39-
/** @var array */
39+
/** @var array */
4040
protected static $pointcuts = [];
4141

42-
/** @var array */
42+
/** @var array */
4343
protected static $resolve = [];
4444

4545
/** @var array */
@@ -55,6 +55,7 @@ public function __construct(Application $app)
5555

5656
/**
5757
* attach pointcut
58+
*
5859
* @return void
5960
*/
6061
public function attach()

src/config/ytake-laravel-aop.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,20 @@
5757
'debug' => env('ASPECT_ANNOTATION_DEBUG', false),
5858
],
5959
],
60+
61+
'ignores' => [
62+
// global Ignored Annotations
63+
'Hears',
64+
'Get',
65+
'Post',
66+
'Put',
67+
'Patch',
68+
'Options',
69+
'Delete',
70+
'Any',
71+
'Middleware',
72+
'Resource',
73+
'Controller'
74+
],
6075
],
6176
];

tests/IgnoreAnnotationTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/**
4+
* Class IgnoreAnnotationTest
5+
*/
6+
class IgnoreAnnotationTest extends AspectTestCase
7+
{
8+
/** @var \Ytake\LaravelAspect\AspectManager $manager */
9+
protected $manager;
10+
11+
protected function setUp()
12+
{
13+
parent::setUp();
14+
$this->manager = new \Ytake\LaravelAspect\AspectManager($this->app);
15+
$this->resolveManager();
16+
}
17+
18+
public function testGenerateCacheNameRemoveNullKey()
19+
{
20+
/** @var \__Test\AnnotationStub $class */
21+
$class = $this->app->make(\__Test\AnnotationStub::class);
22+
$this->assertNull($class->testing());
23+
}
24+
25+
26+
/**
27+
*
28+
*/
29+
protected function resolveManager()
30+
{
31+
/** @var \Ytake\LaravelAspect\RayAspectKernel $aspect */
32+
$aspect = $this->manager->driver('ray');
33+
$aspect->register(\__Test\LogExceptionsModule::class);
34+
$aspect->dispatch();
35+
}
36+
}

tests/config/ytake-laravel-aop.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,10 @@
4242
'debug' => true,
4343
],
4444
],
45+
'ignores' => [
46+
// global Ignored Annotations
47+
'Get',
48+
'Resource'
49+
],
4550
],
4651
];

tests/src/AnnotationStub.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
4+
namespace __Test;
5+
6+
use Ytake\LaravelAspect\Annotation\LogExceptions;
7+
8+
/**
9+
* Class AnnotationStub
10+
* for tests
11+
* @Resource
12+
*/
13+
class AnnotationStub
14+
{
15+
/**
16+
* @LogExceptions
17+
* @Get
18+
* @param null $id
19+
* @return null
20+
*/
21+
public function testing($id = null)
22+
{
23+
return $id;
24+
}
25+
}

tests/src/LogExceptionsModule.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ class LogExceptionsModule extends Loggable
1111
*/
1212
protected $classes = [
1313
\__Test\AspectLogExceptions::class,
14+
\__Test\AnnotationStub::class
1415
];
1516
}

0 commit comments

Comments
 (0)