Skip to content

Commit 132f10d

Browse files
committed
Merge pull request #7 from ytake/develop
removed packages
2 parents ebe7458 + 9de22b9 commit 132f10d

10 files changed

Lines changed: 88 additions & 12 deletions

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,26 @@ public function throwExceptionCache()
169169
}
170170
```
171171

172+
## add Interceptors
173+
174+
your service provider's
175+
176+
```php
177+
public function boot()
178+
{
179+
$this->app['aspect.annotation.register']->registerAnnotations([
180+
app_path() . '/Annotation/Finder.php',
181+
]);
182+
183+
$this->app['aspect.manager']->setAspects([
184+
\App\Interceptor\SampleInterceptor::class
185+
]);
186+
}
187+
```
188+
189+
## for testing
190+
use none driver
191+
192+
```xml
193+
<env name="ASPECT_DRIVER" value="none"/>
194+
```

composer.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"symfony/framework-bundle": "2.*",
3030
"symfony/console": "2.*",
3131
"phpunit/phpunit": "4.*",
32-
"ytake/lom": "~0.0",
3332
"mockery/mockery": "*",
3433
"satooshi/php-coveralls": "*",
3534
"illuminate/database": "~5.0",
@@ -47,8 +46,5 @@
4746
"psr-4": {
4847
"__Test\\": "tests/src"
4948
}
50-
},
51-
"suggest": {
52-
"ext-aop": "for extension driver"
5349
}
5450
}

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<whitelist>
2020
<directory>./src</directory>
2121
<exclude>
22+
<directory>./src/config</directory>
2223
<file>./src/AspectServiceProvider.php</file>
2324
<file>./src/CompileServiceProvider.php</file>
2425
<file>./src/ConsoleServiceProvider.php</file>

src/Aspect/AspectKernel.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,27 @@
2222
*/
2323
final class AspectKernel extends LaravelKernel
2424
{
25+
/** @var array */
26+
protected $aspects;
27+
28+
/**
29+
* @param array $classes
30+
*/
31+
public function setAop(array $classes)
32+
{
33+
$this->aspects = $classes;
34+
}
35+
2536
/**
2637
* @inheritdoc
2738
*/
2839
protected function configureAop(AspectContainer $container)
2940
{
41+
if ($this->aspects) {
42+
foreach ($this->aspects as $aspect) {
43+
$container->registerAspect($this->laravel->make($aspect));
44+
}
45+
}
3046
$container->registerAspect(new TransactionalAspect($this->laravel['db']));
3147
$container->registerAspect(new CacheableAspect($this->laravel['cache']));
3248
$container->registerAspect(new CacheEvictAspect($this->laravel['cache']));

src/AspectDriverInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ interface AspectDriverInterface
2424
* @return mixed
2525
*/
2626
public function register();
27+
28+
/**
29+
* add user aspect script
30+
*/
31+
public function setAspects(array $classes);
2732
}

src/GoAspect.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class GoAspect implements AspectDriverInterface
2929
/** @var LaravelApplication */
3030
protected $laravel;
3131

32+
/** @var AspectKernel */
33+
protected $kernel;
34+
3235
/**
3336
* @param LaravelApplication $laravel
3437
* @param array $configure
@@ -37,6 +40,7 @@ public function __construct(LaravelApplication $laravel, array $configure)
3740
{
3841
$this->laravel = $laravel;
3942
$this->configure = $configure;
43+
$this->kernel = AspectKernel::getInstance();
4044
}
4145

4246
/**
@@ -47,9 +51,16 @@ public function __construct(LaravelApplication $laravel, array $configure)
4751
public function register()
4852
{
4953
if (!defined('AOP_CACHE_DIR')) {
50-
$kernel = AspectKernel::getInstance();
51-
$kernel->setLaravel($this->laravel);
52-
$kernel->init($this->configure);
54+
$this->kernel->setLaravel($this->laravel);
55+
$this->kernel->init($this->configure);
5356
}
5457
}
58+
59+
/**
60+
* @param array $classes
61+
*/
62+
public function setAspects(array $classes)
63+
{
64+
$this->kernel->setAop($classes);
65+
}
5566
}

src/NullAspect.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,12 @@ public function register()
2929
{
3030
return;
3131
}
32+
33+
/**
34+
* @param array $classes
35+
*/
36+
public function setAspects(array $classes)
37+
{
38+
return;
39+
}
3240
}

src/config/ytake-laravel-aop.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717

1818
/**
1919
* choose aop library
20-
* "go"(go-aop), "ext"(aop-ext)
20+
* "go"(go-aop), "none"(for testing)
2121
*
2222
* @see https://github.com/goaop/framework
2323
*/
24-
'default' => 'go',
24+
'default' => env('ASPECT_DRIVER', 'go'),
25+
2526
/**
2627
*
2728
*/
@@ -42,5 +43,9 @@
4243
// array BlackList of directories or files where aspects shouldn't be applied.
4344
// 'excludePaths' => []
4445
],
46+
'none' => [
47+
// for testing driver
48+
// no use aspect
49+
]
4550
],
4651
];

tests/AspectManagerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,14 @@ public function testCreateGoDriverInstance()
2222
\Ytake\LaravelAspect\GoAspect::class, $this->manager->driver('go')
2323
);
2424
}
25+
26+
public function testCreateNullDriverInstance()
27+
{
28+
$driver = $this->manager->driver('none');
29+
$this->assertInstanceOf(\Ytake\LaravelAspect\NullAspect::class, $driver);
30+
$this->assertNull($driver->setAspects([]));
31+
$this->assertNull($driver->register());
32+
$class = new \ReflectionClass($driver);
33+
$this->assertSame(0, count($class->getProperties()));
34+
}
2535
}

tests/config/ytake-laravel-aop.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
/**
1919
* choose aop library
20-
* "go"(go-aop), "ext"(aop-ext)
20+
* "go"(go-aop), "none"(for testing)
2121
*
2222
* @see https://github.com/goaop/framework
2323
*/
@@ -42,8 +42,9 @@
4242
// array BlackList of directories or files where aspects shouldn't be applied.
4343
// 'excludePaths' => []
4444
],
45-
'ext' => [
46-
45+
'none' => [
46+
// for testing driver
47+
// no use aspect
4748
]
4849
],
4950
];

0 commit comments

Comments
 (0)