Skip to content

Commit

Permalink
Merge pull request #7 from ytake/develop
Browse files Browse the repository at this point in the history
removed packages
  • Loading branch information
ytake committed Oct 15, 2015
2 parents ebe7458 + 9de22b9 commit 132f10d
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 12 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,26 @@ public function throwExceptionCache()
}
```

## add Interceptors

your service provider's

```php
public function boot()
{
$this->app['aspect.annotation.register']->registerAnnotations([
app_path() . '/Annotation/Finder.php',
]);

$this->app['aspect.manager']->setAspects([
\App\Interceptor\SampleInterceptor::class
]);
}
```

## for testing
use none driver

```xml
<env name="ASPECT_DRIVER" value="none"/>
```
4 changes: 0 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"symfony/framework-bundle": "2.*",
"symfony/console": "2.*",
"phpunit/phpunit": "4.*",
"ytake/lom": "~0.0",
"mockery/mockery": "*",
"satooshi/php-coveralls": "*",
"illuminate/database": "~5.0",
Expand All @@ -47,8 +46,5 @@
"psr-4": {
"__Test\\": "tests/src"
}
},
"suggest": {
"ext-aop": "for extension driver"
}
}
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<whitelist>
<directory>./src</directory>
<exclude>
<directory>./src/config</directory>
<file>./src/AspectServiceProvider.php</file>
<file>./src/CompileServiceProvider.php</file>
<file>./src/ConsoleServiceProvider.php</file>
Expand Down
16 changes: 16 additions & 0 deletions src/Aspect/AspectKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,27 @@
*/
final class AspectKernel extends LaravelKernel
{
/** @var array */
protected $aspects;

/**
* @param array $classes
*/
public function setAop(array $classes)
{
$this->aspects = $classes;
}

/**
* @inheritdoc
*/
protected function configureAop(AspectContainer $container)
{
if ($this->aspects) {
foreach ($this->aspects as $aspect) {
$container->registerAspect($this->laravel->make($aspect));
}
}
$container->registerAspect(new TransactionalAspect($this->laravel['db']));
$container->registerAspect(new CacheableAspect($this->laravel['cache']));
$container->registerAspect(new CacheEvictAspect($this->laravel['cache']));
Expand Down
5 changes: 5 additions & 0 deletions src/AspectDriverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ interface AspectDriverInterface
* @return mixed
*/
public function register();

/**
* add user aspect script
*/
public function setAspects(array $classes);
}
17 changes: 14 additions & 3 deletions src/GoAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class GoAspect implements AspectDriverInterface
/** @var LaravelApplication */
protected $laravel;

/** @var AspectKernel */
protected $kernel;

/**
* @param LaravelApplication $laravel
* @param array $configure
Expand All @@ -37,6 +40,7 @@ public function __construct(LaravelApplication $laravel, array $configure)
{
$this->laravel = $laravel;
$this->configure = $configure;
$this->kernel = AspectKernel::getInstance();
}

/**
Expand All @@ -47,9 +51,16 @@ public function __construct(LaravelApplication $laravel, array $configure)
public function register()
{
if (!defined('AOP_CACHE_DIR')) {
$kernel = AspectKernel::getInstance();
$kernel->setLaravel($this->laravel);
$kernel->init($this->configure);
$this->kernel->setLaravel($this->laravel);
$this->kernel->init($this->configure);
}
}

/**
* @param array $classes
*/
public function setAspects(array $classes)
{
$this->kernel->setAop($classes);
}
}
8 changes: 8 additions & 0 deletions src/NullAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,12 @@ public function register()
{
return;
}

/**
* @param array $classes
*/
public function setAspects(array $classes)
{
return;
}
}
9 changes: 7 additions & 2 deletions src/config/ytake-laravel-aop.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@

/**
* choose aop library
* "go"(go-aop), "ext"(aop-ext)
* "go"(go-aop), "none"(for testing)
*
* @see https://github.com/goaop/framework
*/
'default' => 'go',
'default' => env('ASPECT_DRIVER', 'go'),

/**
*
*/
Expand All @@ -42,5 +43,9 @@
// array BlackList of directories or files where aspects shouldn't be applied.
// 'excludePaths' => []
],
'none' => [
// for testing driver
// no use aspect
]
],
];
10 changes: 10 additions & 0 deletions tests/AspectManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,14 @@ public function testCreateGoDriverInstance()
\Ytake\LaravelAspect\GoAspect::class, $this->manager->driver('go')
);
}

public function testCreateNullDriverInstance()
{
$driver = $this->manager->driver('none');
$this->assertInstanceOf(\Ytake\LaravelAspect\NullAspect::class, $driver);
$this->assertNull($driver->setAspects([]));
$this->assertNull($driver->register());
$class = new \ReflectionClass($driver);
$this->assertSame(0, count($class->getProperties()));
}
}
7 changes: 4 additions & 3 deletions tests/config/ytake-laravel-aop.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

/**
* choose aop library
* "go"(go-aop), "ext"(aop-ext)
* "go"(go-aop), "none"(for testing)
*
* @see https://github.com/goaop/framework
*/
Expand All @@ -42,8 +42,9 @@
// array BlackList of directories or files where aspects shouldn't be applied.
// 'excludePaths' => []
],
'ext' => [

'none' => [
// for testing driver
// no use aspect
]
],
];

0 comments on commit 132f10d

Please sign in to comment.