Skip to content

Commit

Permalink
Merge pull request #26 from ytake/feature-ignore-annotations
Browse files Browse the repository at this point in the history
Feature ignore annotations
  • Loading branch information
ytake committed Apr 27, 2016
2 parents 4e0c783 + dbf542e commit 203a68c
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/AnnotationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace Ytake\LaravelAspect;

use Illuminate\Support\Manager;
use Doctrine\Common\Annotations\AnnotationReader;

/**
* Class AnnotationManager
Expand All @@ -39,6 +40,7 @@ public function getDefaultDriver()
*/
protected function createArrayDriver()
{
$this->ignoredAnnotations($this->app['config']->get('ytake-laravel-aop.annotation.ignores', []));
return new ArrayReader();
}

Expand All @@ -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'));
}

Expand All @@ -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);
}
}
}
5 changes: 3 additions & 2 deletions src/Modules/AspectModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -55,6 +55,7 @@ public function __construct(Application $app)

/**
* attach pointcut
*
* @return void
*/
public function attach()
Expand Down
15 changes: 15 additions & 0 deletions src/config/ytake-laravel-aop.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
],
],
];
36 changes: 36 additions & 0 deletions tests/IgnoreAnnotationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* Class IgnoreAnnotationTest
*/
class IgnoreAnnotationTest extends AspectTestCase
{
/** @var \Ytake\LaravelAspect\AspectManager $manager */
protected $manager;

protected function setUp()
{
parent::setUp();
$this->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();
}
}
5 changes: 5 additions & 0 deletions tests/config/ytake-laravel-aop.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,10 @@
'debug' => true,
],
],
'ignores' => [
// global Ignored Annotations
'Get',
'Resource'
],
],
];
25 changes: 25 additions & 0 deletions tests/src/AnnotationStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php


namespace __Test;

use Ytake\LaravelAspect\Annotation\LogExceptions;

/**
* Class AnnotationStub
* for tests
* @Resource
*/
class AnnotationStub
{
/**
* @LogExceptions
* @Get
* @param null $id
* @return null
*/
public function testing($id = null)
{
return $id;
}
}
1 change: 1 addition & 0 deletions tests/src/LogExceptionsModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ class LogExceptionsModule extends Loggable
*/
protected $classes = [
\__Test\AspectLogExceptions::class,
\__Test\AnnotationStub::class
];
}

0 comments on commit 203a68c

Please sign in to comment.