From ae30c257c26aa5951068407edfec53bc0eb428d4 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Fri, 28 Nov 2014 10:37:49 +0900 Subject: [PATCH 01/12] add onion test --- tests/BindTest.php | 15 +++++++++++++++ tests/Fake/FakeAnnotateClass.php | 2 ++ tests/Fake/FakeMarker2.php | 15 +++++++++++++++ tests/Fake/FakeMarker3.php | 15 +++++++++++++++ tests/Fake/FakeOnionInterceptor1.php | 11 +++++++++++ tests/Fake/FakeOnionInterceptor2.php | 11 +++++++++++ tests/Fake/FakeOnionInterceptor3.php | 11 +++++++++++ 7 files changed, 80 insertions(+) create mode 100644 tests/Fake/FakeMarker2.php create mode 100644 tests/Fake/FakeMarker3.php create mode 100644 tests/Fake/FakeOnionInterceptor1.php create mode 100644 tests/Fake/FakeOnionInterceptor2.php create mode 100644 tests/Fake/FakeOnionInterceptor3.php diff --git a/tests/BindTest.php b/tests/BindTest.php index b1a50e02..59384f28 100644 --- a/tests/BindTest.php +++ b/tests/BindTest.php @@ -74,5 +74,20 @@ public function testNotClassMatch() $this->assertArrayNotHasKey('getDouble', $this->bind->getBindings()); } + public function testOnionAnnotation() + { + $onion1 = new FakeOnionInterceptor1; + $onion2 = new FakeOnionInterceptor2; + $onion3 = new FakeOnionInterceptor3; + $pointcut = new Pointcut((new Matcher)->any(), (new Matcher)->annotatedWith(FakeMarker::class), [$onion1]); + $pointcut2 = new Pointcut((new Matcher)->any(), (new Matcher)->annotatedWith(FakeMarker2::class), [$onion2]); + $pointcut3 = new Pointcut((new Matcher)->any(), (new Matcher)->annotatedWith(FakeMarker3::class), [$onion3]); + $this->bind->bind(FakeAnnotateClass::class, [$pointcut, $pointcut2, $pointcut3]); + $actual = $this->bind->getBindings(); + $expect = [ + 'getDouble' => [$onion3, $onion2, $onion1] + ]; + $this->assertSame($expect, $actual); + } } diff --git a/tests/Fake/FakeAnnotateClass.php b/tests/Fake/FakeAnnotateClass.php index 2468f9cb..a358e865 100644 --- a/tests/Fake/FakeAnnotateClass.php +++ b/tests/Fake/FakeAnnotateClass.php @@ -10,6 +10,8 @@ class FakeAnnotateClass public $a = 0; /** + * @Ray\Aop\FakeMarker3 + * @Ray\Aop\FakeMarker2 * @Ray\Aop\FakeMarker */ public function getDouble($a) diff --git a/tests/Fake/FakeMarker2.php b/tests/Fake/FakeMarker2.php new file mode 100644 index 00000000..84b4e87d --- /dev/null +++ b/tests/Fake/FakeMarker2.php @@ -0,0 +1,15 @@ +proceed(); + } +} diff --git a/tests/Fake/FakeOnionInterceptor2.php b/tests/Fake/FakeOnionInterceptor2.php new file mode 100644 index 00000000..cac20213 --- /dev/null +++ b/tests/Fake/FakeOnionInterceptor2.php @@ -0,0 +1,11 @@ +proceed(); + } +} diff --git a/tests/Fake/FakeOnionInterceptor3.php b/tests/Fake/FakeOnionInterceptor3.php new file mode 100644 index 00000000..15daf9be --- /dev/null +++ b/tests/Fake/FakeOnionInterceptor3.php @@ -0,0 +1,11 @@ +proceed(); + } +} From 8a5aea96d3866ff8a2b1143e44cfd61e89fbd239 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Thu, 4 Dec 2014 11:45:55 +0900 Subject: [PATCH 02/12] intercept as method annotated order --- src/AnnotatedMatcher.php | 18 ++++++++ src/AnnotationMatcher.php | 54 ++++++++++++++++++++++ src/Bind.php | 94 ++++++++++++++++++++++++++++----------- src/BindInterface.php | 2 +- src/BuiltinMatcher.php | 4 +- src/Matcher.php | 2 +- tests/BindTest.php | 5 ++- 7 files changed, 147 insertions(+), 32 deletions(-) create mode 100644 src/AnnotatedMatcher.php create mode 100644 src/AnnotationMatcher.php diff --git a/src/AnnotatedMatcher.php b/src/AnnotatedMatcher.php new file mode 100644 index 00000000..469f3530 --- /dev/null +++ b/src/AnnotatedMatcher.php @@ -0,0 +1,18 @@ +annotation = $arguments[0]; + } +} diff --git a/src/AnnotationMatcher.php b/src/AnnotationMatcher.php new file mode 100644 index 00000000..41ee5e8e --- /dev/null +++ b/src/AnnotationMatcher.php @@ -0,0 +1,54 @@ +matcherName = $matcherName; + $this->arguments = $arguments; + $this->matcher = new AnnotatedWithMatcher; + } + + /** + * {@inheritdoc} + */ + public function matchesClass(\ReflectionClass $class, array $arguments) + { + return $this->matcher->matchesClass($class, $arguments); + } + + /** + * {@inheritdoc} + */ + public function matchesMethod(\ReflectionMethod $method, array $arguments) + { + return $this->matcher->matchesMethod($method, $arguments); + } +} diff --git a/src/Bind.php b/src/Bind.php index d3f5f373..f7a6b7c6 100644 --- a/src/Bind.php +++ b/src/Bind.php @@ -6,8 +6,10 @@ */ namespace Ray\Aop; +use Doctrine\Common\Annotations\AnnotationReader; use ReflectionClass; use ReflectionMethod; +use Doctrine\Common\Annotations\Reader; final class Bind implements BindInterface { @@ -17,58 +19,84 @@ final class Bind implements BindInterface private $bindings = []; /** - * {@inheritdoc} + * @var AnnotationReader + */ + private $reader; + + public function __construct(Reader $reader = null) + { + $this->reader = $reader ?: new AnnotationReader; + } + + /** + * @param string $class + * @param array $pointcuts + * + * @return $this */ public function bind($class, array $pointcuts) { - foreach ($pointcuts as $pointcut) { - /** @var $pointcut Pointcut */ - $this->bindPointcut(new \ReflectionClass($class), $pointcut); - } + $pointcuts = $this->getAnnnotationPointcuts($pointcuts); + $this->annotatedMethodsMatch(new \ReflectionClass($class), $pointcuts); +// foreach ($pointcuts as $pointcut) { +// /** @var $pointcut Pointcut */ +// $this->bindPointcut(new \ReflectionClass($class), $pointcut); +// } return $this; } /** * @param ReflectionClass $class - * @param Pointcut $pointcut + * @param array $pointcuts */ - private function bindPointcut(\ReflectionClass $class, Pointcut $pointcut) + private function annotatedMethodsMatch(\ReflectionClass $class, array &$pointcuts) { - $isClassMatch = $pointcut->classMatcher->matchesClass($class, $pointcut->classMatcher->getArguments()); - if ($isClassMatch === false) { - - return; + $methods = $class->getMethods(ReflectionMethod::IS_PUBLIC); + foreach ($methods as $method) { + $this->annotatedMethodMatch($class, $method, $pointcuts); } - $this->methodsMatch($class, $pointcut->methodMatcher, $pointcut->interceptors); } /** - * @param ReflectionClass $class - * @param AbstractMatcher $methodMatcher - * @param Interceptor[] $interceptors + * @param ReflectionClass $class + * @param ReflectionMethod $method + * @param array $pointcuts */ - private function methodsMatch(\ReflectionClass $class, AbstractMatcher $methodMatcher, array $interceptors) + private function annotatedMethodMatch(\ReflectionClass $class, \ReflectionMethod $method, array &$pointcuts) { - $methods = $class->getMethods(ReflectionMethod::IS_PUBLIC); - foreach ($methods as $method) { - $this->methodMatch($method, $methodMatcher, $interceptors); + $annotations = $this->reader->getMethodAnnotations($method); + foreach ($annotations as $annotation) { + $annotationIndex = get_class($annotation); + if (isset($pointcuts[$annotationIndex])) { + $this->annotatedMethodMatchBind($class, $method, $pointcuts[$annotationIndex]); + unset($pointcuts[$annotationIndex]); + } + } + foreach ($pointcuts as $pointcut) { + $this->annotatedMethodMatchBind($class, $method, $pointcut); } } /** + * @param ReflectionClass $class * @param ReflectionMethod $method - * @param AbstractMatcher $methodMatcher - * @param Interceptor[] $interceptors + * @param PointCut $pointCut */ - private function methodMatch(\ReflectionMethod $method, AbstractMatcher $methodMatcher, array $interceptors) + private function annotatedMethodMatchBind(\ReflectionClass $class, \ReflectionMethod $method, PointCut $pointCut) { - $isMethodMatch = $methodMatcher->matchesMethod($method, $methodMatcher->getArguments()); - if ($isMethodMatch) { - $this->bindInterceptors($method->name, $interceptors); + $isMethodMatch = $pointCut->methodMatcher->matchesMethod($method, $pointCut->methodMatcher->getArguments()); + if (! $isMethodMatch) { + return; + } + $isClassMatch = $pointCut->classMatcher->matchesClass($class, $pointCut->classMatcher->getArguments()); + if (! $isClassMatch) { + return; } + $this->bindInterceptors($method->name, $pointCut->interceptors); } + /** * {@inheritdoc} */ @@ -101,4 +129,20 @@ public function __toString() return $shortHash(serialize($this->bindings)); } + + /** + * @param Pointcut[] $pointcuts + */ + public function getAnnnotationPointcuts(array &$pointcuts) + { + $keyPointcuts = []; + foreach ($pointcuts as $key => $pointcut) { + if ($pointcut->methodMatcher instanceof AnnotatedMatcher) { + $key = $pointcut->methodMatcher->annotation; + } + $keyPointcuts[$key] = $pointcut; + } + + return $keyPointcuts; + } } diff --git a/src/BindInterface.php b/src/BindInterface.php index 63461193..82cc51d7 100644 --- a/src/BindInterface.php +++ b/src/BindInterface.php @@ -6,7 +6,7 @@ */ namespace Ray\Aop; -interface BIndInterface +interface BindInterface { /** * Bind pointcuts diff --git a/src/BuiltinMatcher.php b/src/BuiltinMatcher.php index be4debf4..c664e3bb 100644 --- a/src/BuiltinMatcher.php +++ b/src/BuiltinMatcher.php @@ -6,9 +6,8 @@ */ namespace Ray\Aop; -final class BuiltinMatcher extends AbstractMatcher +class BuiltinMatcher extends AbstractMatcher { - /** * @var array */ @@ -34,7 +33,6 @@ public function __construct($matcherName, array $arguments) $this->arguments = $arguments; $matcher = 'Ray\Aop\Matcher\\' . ucwords($this->matcherName) . 'Matcher'; $this->matcher = (new \ReflectionClass($matcher))->newInstance(); - } /** diff --git a/src/Matcher.php b/src/Matcher.php index d39efe2e..0fba0515 100644 --- a/src/Matcher.php +++ b/src/Matcher.php @@ -28,7 +28,7 @@ public function annotatedWith($annotationName) throw new InvalidAnnotation($annotationName); } - return new BuiltinMatcher(__FUNCTION__, [$annotationName]); + return new AnnotatedMatcher(__FUNCTION__, [$annotationName]); } /** diff --git a/tests/BindTest.php b/tests/BindTest.php index 59384f28..5f04068a 100644 --- a/tests/BindTest.php +++ b/tests/BindTest.php @@ -79,10 +79,11 @@ public function testOnionAnnotation() $onion1 = new FakeOnionInterceptor1; $onion2 = new FakeOnionInterceptor2; $onion3 = new FakeOnionInterceptor3; - $pointcut = new Pointcut((new Matcher)->any(), (new Matcher)->annotatedWith(FakeMarker::class), [$onion1]); + $pointcut0 = new Pointcut((new Matcher)->any(), (new Matcher)->startsWith('XXX'), [$onion1]); + $pointcut1 = new Pointcut((new Matcher)->any(), (new Matcher)->annotatedWith(FakeMarker::class), [$onion1]); $pointcut2 = new Pointcut((new Matcher)->any(), (new Matcher)->annotatedWith(FakeMarker2::class), [$onion2]); $pointcut3 = new Pointcut((new Matcher)->any(), (new Matcher)->annotatedWith(FakeMarker3::class), [$onion3]); - $this->bind->bind(FakeAnnotateClass::class, [$pointcut, $pointcut2, $pointcut3]); + $this->bind->bind(FakeAnnotateClass::class, [$pointcut0, $pointcut1, $pointcut2, $pointcut3]); $actual = $this->bind->getBindings(); $expect = [ 'getDouble' => [$onion3, $onion2, $onion1] From 0645c2ae115e7913762ec47dc3c85d8db6d6c2ab Mon Sep 17 00:00:00 2001 From: koriym Date: Wed, 10 Dec 2014 20:54:58 +0900 Subject: [PATCH 03/12] autoload-dev --- composer.json | 5 +++++ tests/bootstrap.php | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index a9c41d4b..c47dcf27 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,11 @@ "autoload": { "psr-4": { "Ray\\Aop\\": "src/" } }, + "autoload-dev": { + "psr-4": { "Ray\\Aop\\": "tests/" }, + "psr-4": { "Ray\\Aop\\": "tests/Fake/" }, + "files": ["tests/Fake/FakeAnnotateClassNoName.php"] + }, "suggest": { "ray/di": "Guice style annotation-driven dependency injection framework" }, diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d200fdfa..52b09c6b 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,9 +2,9 @@ $loader = require dirname(__DIR__) . '/vendor/autoload.php'; /** @var $loader \Composer\Autoload\ClassLoader */ -$loader->addPsr4('Ray\Aop\\', [__DIR__, __DIR__ . '/Fake']); -$loader->add('', 'template'); \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader([$loader, 'loadClass']); + +// cleanup $clear = function ($dir) { $iterator = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($dir), From 2d28b72ac7f52d258ec0108640d2b9e178915b9e Mon Sep 17 00:00:00 2001 From: koriym Date: Wed, 10 Dec 2014 20:55:57 +0900 Subject: [PATCH 04/12] node traversation to collect use statements --- src/CodeGen.php | 26 +++++++++++++++++++- src/CodeGenVisitor.php | 34 ++++++++++++++++++++++++++ tests/CompilerTest.php | 17 +++++++++++-- tests/Fake/FakeAnnotateClass.php | 7 ++++-- tests/Fake/FakeAnnotateClassNoName.php | 22 +++++++++++++++++ 5 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 src/CodeGenVisitor.php create mode 100644 tests/Fake/FakeAnnotateClassNoName.php diff --git a/src/CodeGen.php b/src/CodeGen.php index d3b4ce82..36a2d6b3 100644 --- a/src/CodeGen.php +++ b/src/CodeGen.php @@ -8,8 +8,11 @@ use PhpParser\BuilderFactory; use PhpParser\Node\Stmt\Class_; +use PhpParser\NodeTraverser; use PhpParser\Parser; use PhpParser\PrettyPrinter\Standard; +use PhpParser\Node\Stmt; +use PhpParser\Lexer\Emulative; final class CodeGen implements CodeGenInterface { @@ -63,8 +66,29 @@ public function generate($class, \ReflectionClass $sourceClass) ->getNode(); $stmt = $this->addClassDocComment($stmt, $sourceClass); $code = $this->printer->prettyPrint([$stmt]); + $statements = $this->getUseStatements($sourceClass); - return $code; + return $statements . $code; + } + + /** + * @param \ReflectionClass $class + * + * @return string + */ + private function getUseStatements(\ReflectionClass $class) + { + $traverser = new NodeTraverser; + $useStmtsVisitor = new CodeGenVisitor; + $traverser->addVisitor($useStmtsVisitor); + // parse + $stmts = (new Parser(new Emulative))->parse(file_get_contents($class->getFileName())); + // traverse + $traverser->traverse($stmts); + // pretty print + $code = $this->printer->prettyPrint($useStmtsVisitor()); + + return (string) $code; } /** diff --git a/src/CodeGenVisitor.php b/src/CodeGenVisitor.php new file mode 100644 index 00000000..4770003d --- /dev/null +++ b/src/CodeGenVisitor.php @@ -0,0 +1,34 @@ +use[] = $node; + } + } + + /** + * @return Node\Stmt\Use_[] + */ + public function __invoke() + { + return $this->use; + } +} \ No newline at end of file diff --git a/tests/CompilerTest.php b/tests/CompilerTest.php index bc4bfda0..70d7e226 100644 --- a/tests/CompilerTest.php +++ b/tests/CompilerTest.php @@ -4,8 +4,6 @@ use Doctrine\Common\Annotations\AnnotationReader; use PhpParser\Lexer; -use Ray\Aop\Interceptor\AbortProceedInterceptor; -use Ray\Aop\Interceptor\DoubleInterceptor; class CompilerTest extends \PHPUnit_Framework_TestCase { @@ -177,4 +175,19 @@ public function testCompileNoBInd() $class = $this->compiler->compile(FakeMock::class, new Bind); $this->assertSame(FakeMock::class, $class); } + + public function testAnnotation() + { + $class = $this->compiler->compile(FakeAnnotateClass::class, $this->bind); + $annotations = (new AnnotationReader)->getMethodAnnotations(new \ReflectionMethod($class, 'getDouble')); + $this->assertSame(3, count($annotations)); + } + + public function testNoNamespace() + { + $class = $this->compiler->compile(\FakeAnnotateClassNoName::class, $this->bind); + $annotations = (new AnnotationReader)->getMethodAnnotations(new \ReflectionMethod($class, 'getDouble')); + $this->assertSame(3, count($annotations)); + + } } diff --git a/tests/Fake/FakeAnnotateClass.php b/tests/Fake/FakeAnnotateClass.php index a358e865..6da2aa20 100644 --- a/tests/Fake/FakeAnnotateClass.php +++ b/tests/Fake/FakeAnnotateClass.php @@ -2,6 +2,9 @@ namespace Ray\Aop; +use Ray\Aop\FakeMarker; +use Ray\Aop\FakeMarker2; + /** * @Ray\Aop\FakeResource */ @@ -11,8 +14,8 @@ class FakeAnnotateClass /** * @Ray\Aop\FakeMarker3 - * @Ray\Aop\FakeMarker2 - * @Ray\Aop\FakeMarker + * @FakeMarker2 + * @FakeMarker */ public function getDouble($a) { diff --git a/tests/Fake/FakeAnnotateClassNoName.php b/tests/Fake/FakeAnnotateClassNoName.php new file mode 100644 index 00000000..841d77fa --- /dev/null +++ b/tests/Fake/FakeAnnotateClassNoName.php @@ -0,0 +1,22 @@ + Date: Wed, 10 Dec 2014 20:59:42 +0900 Subject: [PATCH 05/12] use existing parser --- src/CodeGen.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CodeGen.php b/src/CodeGen.php index 36a2d6b3..d1d121ba 100644 --- a/src/CodeGen.php +++ b/src/CodeGen.php @@ -82,7 +82,7 @@ private function getUseStatements(\ReflectionClass $class) $useStmtsVisitor = new CodeGenVisitor; $traverser->addVisitor($useStmtsVisitor); // parse - $stmts = (new Parser(new Emulative))->parse(file_get_contents($class->getFileName())); + $stmts = $this->parser->parse(file_get_contents($class->getFileName())); // traverse $traverser->traverse($stmts); // pretty print From 214af128d606c41e21043f424f6cfbd30234a683 Mon Sep 17 00:00:00 2001 From: koriym Date: Wed, 10 Dec 2014 21:19:53 +0900 Subject: [PATCH 06/12] remove annotation mathcer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit annotated matching is not executed by matcher, it’s matched internal for aspect ordering (onion aspect) --- src/AnnotationMatcher.php | 54 --------------------------------------- 1 file changed, 54 deletions(-) delete mode 100644 src/AnnotationMatcher.php diff --git a/src/AnnotationMatcher.php b/src/AnnotationMatcher.php deleted file mode 100644 index 41ee5e8e..00000000 --- a/src/AnnotationMatcher.php +++ /dev/null @@ -1,54 +0,0 @@ -matcherName = $matcherName; - $this->arguments = $arguments; - $this->matcher = new AnnotatedWithMatcher; - } - - /** - * {@inheritdoc} - */ - public function matchesClass(\ReflectionClass $class, array $arguments) - { - return $this->matcher->matchesClass($class, $arguments); - } - - /** - * {@inheritdoc} - */ - public function matchesMethod(\ReflectionMethod $method, array $arguments) - { - return $this->matcher->matchesMethod($method, $arguments); - } -} From 70f86de44587ced6836ecc61dbb7a8ea57d8617e Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Fri, 12 Dec 2014 18:16:15 +0900 Subject: [PATCH 07/12] remove composer.lock --- .gitignore | 3 +- composer.lock | 184 -------------------------------------------------- 2 files changed, 1 insertion(+), 186 deletions(-) delete mode 100644 composer.lock diff --git a/.gitignore b/.gitignore index e9f9cb43..ff44bfcc 100644 --- a/.gitignore +++ b/.gitignore @@ -10,5 +10,4 @@ vendor cache.properties build composer.phar -docs/demo/tmp/* -tests/tmp/* +composer.lock diff --git a/composer.lock b/composer.lock deleted file mode 100644 index 7c4b63d9..00000000 --- a/composer.lock +++ /dev/null @@ -1,184 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", - "This file is @generated automatically" - ], - "hash": "d77523f903fa09fb49fb9be60f1ef959", - "packages": [ - { - "name": "doctrine/annotations", - "version": "v1.2.1", - "source": { - "type": "git", - "url": "https://github.com/doctrine/annotations.git", - "reference": "6a6bec0670bb6e71a263b08bc1b98ea242928633" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/6a6bec0670bb6e71a263b08bc1b98ea242928633", - "reference": "6a6bec0670bb6e71a263b08bc1b98ea242928633", - "shasum": "" - }, - "require": { - "doctrine/lexer": "1.*", - "php": ">=5.3.2" - }, - "require-dev": { - "doctrine/cache": "1.*", - "phpunit/phpunit": "4.*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.3.x-dev" - } - }, - "autoload": { - "psr-0": { - "Doctrine\\Common\\Annotations\\": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Benjamin Eberlei", - "email": "kontakt@beberlei.de" - }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, - { - "name": "Jonathan Wage", - "email": "jonwage@gmail.com" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "Docblock Annotations Parser", - "homepage": "http://www.doctrine-project.org", - "keywords": [ - "annotations", - "docblock", - "parser" - ], - "time": "2014-09-25 16:45:30" - }, - { - "name": "doctrine/lexer", - "version": "v1.0", - "source": { - "type": "git", - "url": "https://github.com/doctrine/lexer.git", - "reference": "v1.0" - }, - "dist": { - "type": "zip", - "url": "https://github.com/doctrine/lexer/archive/v1.0.zip", - "reference": "v1.0", - "shasum": "" - }, - "require": { - "php": ">=5.3.2" - }, - "type": "library", - "autoload": { - "psr-0": { - "Doctrine\\Common\\Lexer\\": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com", - "homepage": "http://www.instaclick.com" - }, - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com", - "homepage": "https://github.com/schmittjoh", - "role": "Developer of wrapped JMSSerializerBundle" - } - ], - "description": "Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.", - "homepage": "http://www.doctrine-project.org", - "keywords": [ - "lexer", - "parser" - ], - "time": "2013-01-12 18:59:04" - }, - { - "name": "nikic/php-parser", - "version": "v1.0.1", - "source": { - "type": "git", - "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "b9a60372f26356feb85b4b9ca50a395a5f0d7f34" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/b9a60372f26356feb85b4b9ca50a395a5f0d7f34", - "reference": "b9a60372f26356feb85b4b9ca50a395a5f0d7f34", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "php": ">=5.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "files": [ - "lib/bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Nikita Popov" - } - ], - "description": "A PHP parser written in PHP", - "keywords": [ - "parser", - "php" - ], - "time": "2014-10-14 19:40:07" - } - ], - "packages-dev": [], - "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], - "prefer-stable": false, - "platform": { - "php": ">=5.4.0" - }, - "platform-dev": [] -} From f143128dd042146d1c37d60c7ed99fd8a6413f03 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Wed, 17 Dec 2014 22:57:04 +0900 Subject: [PATCH 08/12] Update README.md --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3d8ddd29..7b154aef 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ -Aspect Oriented Framework for PHP -======= +# Ray.Aop + +## Aspect Oriented Framework for PHP [![Latest Stable Version](https://poser.pugx.org/ray/aop/v/stable.png)](https://packagist.org/packages/ray/aop) -[![Build Status](https://secure.travis-ci.org/koriym/Ray.Aop.png?branch=master)](http://travis-ci.org/koriym/Ray.Aop) -[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/koriym/Ray.Aop/badges/quality-score.png?s=bb5414751b994336b6310caf61029ac09b907779)](https://scrutinizer-ci.com/g/koriym/Ray.Aop/) +[![Latest Unstable Version](http://img.shields.io/badge/unstable-~2.0%40dev-green.svg)](https://packagist.org/packages/ray/aop) +[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/koriym/Ray.Aop/badges/quality-score.png?develop-2)](https://scrutinizer-ci.com/g/koriym/Ray.Aop/) [![Code Coverage](https://scrutinizer-ci.com/g/koriym/Ray.Aop/badges/coverage.png?s=5604fdfae48a5a31242d3e46018515e2f30083d7)](https://scrutinizer-ci.com/g/koriym/Ray.Aop/) +[![Build Status](https://secure.travis-ci.org/koriym/Ray.Aop.png?branch=develop-2)](http://travis-ci.org/koriym/Ray.Aop) [[Japanese]](https://github.com/koriym/Ray.Aop/blob/develop/README.ja.md) From 3b9af00a101590966ac6ff42cf6c1e0edd38d2c5 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Mon, 22 Dec 2014 10:29:39 +0900 Subject: [PATCH 09/12] update metafile --- .gitignore | 1 + .php_cs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 .php_cs diff --git a/.gitignore b/.gitignore index ff44bfcc..552e45a6 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ cache.properties build composer.phar composer.lock +tmp diff --git a/.php_cs b/.php_cs new file mode 100644 index 00000000..141f75bd --- /dev/null +++ b/.php_cs @@ -0,0 +1,20 @@ +level(null); +$config->fixers( + array( + 'indentation', + 'linefeed', + 'trailing_spaces', + 'short_tag', + 'visibility', + 'php_closing_tag', + 'braces', + 'function_declaration', + 'psr0', + 'elseif', + 'eof_ending', + 'unused_use', + ) +); +return $config; From db8b634a124050305f5da9aac8b1b502cb48ff27 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Mon, 22 Dec 2014 10:33:05 +0900 Subject: [PATCH 10/12] clean up code --- src/Bind.php | 9 ++++----- src/CodeGen.php | 1 - src/CodeGenVisitor.php | 2 +- src/Joinpoint.php | 8 -------- src/Matcher/LogicalAndMatcher.php | 2 +- tests/BindTest.php | 2 -- tests/BuiltInMatcherTest.php | 2 +- tests/CompilerTest.php | 2 -- tests/Fake/FakeMarker.php | 6 +----- tests/Fake/FakeMarker2.php | 6 +----- tests/Fake/FakeMarker3.php | 6 +----- tests/Fake/FakeMethodInterceptor.php | 1 + tests/Fake/FakeResource.php | 6 +----- 13 files changed, 12 insertions(+), 41 deletions(-) diff --git a/src/Bind.php b/src/Bind.php index f7a6b7c6..96a6a4bb 100644 --- a/src/Bind.php +++ b/src/Bind.php @@ -23,6 +23,9 @@ final class Bind implements BindInterface */ private $reader; + /** + * @param Reader $reader + */ public function __construct(Reader $reader = null) { $this->reader = $reader ?: new AnnotationReader; @@ -38,10 +41,6 @@ public function bind($class, array $pointcuts) { $pointcuts = $this->getAnnnotationPointcuts($pointcuts); $this->annotatedMethodsMatch(new \ReflectionClass($class), $pointcuts); -// foreach ($pointcuts as $pointcut) { -// /** @var $pointcut Pointcut */ -// $this->bindPointcut(new \ReflectionClass($class), $pointcut); -// } return $this; } @@ -119,7 +118,7 @@ public function getBindings() } /** - * {@inheritdoc} + * @return string */ public function __toString() { diff --git a/src/CodeGen.php b/src/CodeGen.php index d1d121ba..d8126a80 100644 --- a/src/CodeGen.php +++ b/src/CodeGen.php @@ -12,7 +12,6 @@ use PhpParser\Parser; use PhpParser\PrettyPrinter\Standard; use PhpParser\Node\Stmt; -use PhpParser\Lexer\Emulative; final class CodeGen implements CodeGenInterface { diff --git a/src/CodeGenVisitor.php b/src/CodeGenVisitor.php index 4770003d..10673b13 100644 --- a/src/CodeGenVisitor.php +++ b/src/CodeGenVisitor.php @@ -31,4 +31,4 @@ public function __invoke() { return $this->use; } -} \ No newline at end of file +} diff --git a/src/Joinpoint.php b/src/Joinpoint.php index 149b2e5c..01b6d6fa 100644 --- a/src/Joinpoint.php +++ b/src/Joinpoint.php @@ -46,12 +46,4 @@ public function proceed(); * @return object (can be null if the accessible object is static). */ public function getThis(); - - /* - * Returns the static part of this joinpoint. - * - *

The static part is an accessible object on which a chain of - * interceptors are installed. - */ - // public function getStaticPart(); } diff --git a/src/Matcher/LogicalAndMatcher.php b/src/Matcher/LogicalAndMatcher.php index 1f20a6b5..d60ed60c 100644 --- a/src/Matcher/LogicalAndMatcher.php +++ b/src/Matcher/LogicalAndMatcher.php @@ -1,6 +1,6 @@ assertSame($expect, $actual); } } - diff --git a/tests/BuiltInMatcherTest.php b/tests/BuiltInMatcherTest.php index 5e26774c..75cbd033 100644 --- a/tests/BuiltInMatcherTest.php +++ b/tests/BuiltInMatcherTest.php @@ -2,7 +2,7 @@ namespace Ray\Aop; -class BuiltinMatcherTest extends \PHPUnit_Framework_TestCase +class BuiltInMatcherTest extends \PHPUnit_Framework_TestCase { /** * @var BuiltinMatcher diff --git a/tests/CompilerTest.php b/tests/CompilerTest.php index 70d7e226..1d7c0d2a 100644 --- a/tests/CompilerTest.php +++ b/tests/CompilerTest.php @@ -3,7 +3,6 @@ namespace Ray\Aop; use Doctrine\Common\Annotations\AnnotationReader; -use PhpParser\Lexer; class CompilerTest extends \PHPUnit_Framework_TestCase { @@ -188,6 +187,5 @@ public function testNoNamespace() $class = $this->compiler->compile(\FakeAnnotateClassNoName::class, $this->bind); $annotations = (new AnnotationReader)->getMethodAnnotations(new \ReflectionMethod($class, 'getDouble')); $this->assertSame(3, count($annotations)); - } } diff --git a/tests/Fake/FakeMarker.php b/tests/Fake/FakeMarker.php index 11eff235..fef7ce47 100644 --- a/tests/Fake/FakeMarker.php +++ b/tests/Fake/FakeMarker.php @@ -1,9 +1,5 @@ Date: Mon, 22 Dec 2014 10:41:32 +0900 Subject: [PATCH 11/12] fix phpdoc --- src/ReflectiveMethodInvocation.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/ReflectiveMethodInvocation.php b/src/ReflectiveMethodInvocation.php index f6e352da..805b21a8 100644 --- a/src/ReflectiveMethodInvocation.php +++ b/src/ReflectiveMethodInvocation.php @@ -28,10 +28,6 @@ final class ReflectiveMethodInvocation implements MethodInvocation */ private $interceptors; - /** - * @param Arguments $arguments - * @param Interceptor[] $interceptors - */ /** * @param object $object * @param \ReflectionMethod $method @@ -40,7 +36,7 @@ final class ReflectiveMethodInvocation implements MethodInvocation */ public function __construct( $object, - $method, + \ReflectionMethod $method, Arguments $arguments, array $interceptors = [] ) { @@ -79,6 +75,7 @@ public function proceed() return $this->method->invokeArgs($this->object, $this->arguments->getArrayCopy()); } $interceptor = array_shift($this->interceptors); + /** @var $interceptor MethodInterceptor */ return $interceptor->invoke($this); } From 2a794b4dbcc12b4758686541ced912f94cffb1e4 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Mon, 22 Dec 2014 11:35:52 +0900 Subject: [PATCH 12/12] hard code annotation reader class --- src/Bind.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Bind.php b/src/Bind.php index 96a6a4bb..4f093861 100644 --- a/src/Bind.php +++ b/src/Bind.php @@ -23,12 +23,9 @@ final class Bind implements BindInterface */ private $reader; - /** - * @param Reader $reader - */ - public function __construct(Reader $reader = null) + public function __construct() { - $this->reader = $reader ?: new AnnotationReader; + $this->reader = new AnnotationReader; } /**