diff --git a/.gitattributes b/.gitattributes
index 606a7cb9..d7c1c1e7 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -16,3 +16,5 @@
# Configure diff output for .php and .phar files.
*.php diff=php
*.phar -diff
+
+/vendor-bin/**/composer.lock binary
diff --git a/README.ja.md b/README.ja.md
index 232b33ee..d2444f14 100644
--- a/README.ja.md
+++ b/README.ja.md
@@ -155,6 +155,23 @@ $bind = (new Bind)->bind(RealBillingService::class, [$pointcut]);
$billing = (new Weaver($bind, $tmpDir))->newInstance(RealBillingService::class, [$arg1, $arg2]);
```
+マッチャーはdoctrineアノテーション、またはPHP8アトリビュートの読み込みをサポートします。
+
+```php
+ public function matchesClass(\ReflectionClass $class, array $arguments) : bool
+ {
+ assert($class instanceof \Ray\Aop\ReflectionClass);
+ $classAnnotation = $class->getAnnotation(Foo::class); // @Foo or #[Foo]
+ // ...
+ }
+
+ public function matchesMethod(\ReflectionMethod $method, array $arguments) : bool
+ {
+ assert($method instanceof \Ray\Aop\ReflectionMethod);
+ $methodAnnotation = $method->getAnnotation(Bar::class);
+ }
+```
+
## パフォーマンス
`Weaver`オブジェクトはキャッシュ可能です。コンパイル、束縛、アノテーション読み込みコストを削減します。
@@ -242,11 +259,6 @@ $class = $invocation->getMethod()->getDeclaringClass();
このメソッドインターセプターのAPIは[AOPアライアンス](http://aopalliance.sourceforge.net/doc/org/aopalliance/intercept/MethodInterceptor.html)の部分実装です。
-## 要件
-
-* PHP 5.6+
-* hhvm
-
## インストール
Ray.Aopの推奨インストール方法は、[Composer](https://github.com/composer/composer)でのインストールです。
@@ -256,18 +268,24 @@ Ray.Aopの推奨インストール方法は、[Composer](https://github.com/comp
$ composer require ray/aop ~2.0
```
-## Ray.Aopのテスト
+## パフォーマンス
+
+AOPクラスのコンパイルにより、Ray.Aopは高速に動作します。アノテーションの読み込みは初回コンパイル時のみなので、ランタイムのパフォーマンスに影響を与えません。開発段階や最初の実行時にも、ファイルのタイムスタンプを利用してPHPファイルがキャッシュされ、通常はアノテーション生成のコストを気にする必要はありませんが、アプリケーションのブートストラップでアノテーションリーダーの設定を行うことで、初回コンパイル時のパフォーマンスが向上します。特に大規模なアプリケーションでこの設定は役立ちます。
-Ray.Aopをソースからインストールし、ユニットテストとデモを実行するには次のようにします。
+### APCu
-```bash
-git clone https://github.com/ray-di/Ray.Aop.git
-cd Ray.Aop
-composer install
-vendor/bin/phpunit
-php demo/run.php
+```php
+SevericeLocator::setReader(new PsrCachedReader(new Reader(), $apcuCache));
```
+### アトリビュートのみ使用(推奨)
+
+```php
+SevericeLocator::setReader(new AttributeReader);`
+```
+
+## DI Framework
+
DIとAOPを統合したDIフレームワーク[Ray.Di](https://github.com/ray-di/Ray.Di)もご覧ください。
* この文書の大部分は [Guice/AOP](https://github.com/google/guice/wiki/AOP) から借用しています。
diff --git a/README.md b/README.md
index 2acf6bdd..cfebf780 100644
--- a/README.md
+++ b/README.md
@@ -150,6 +150,23 @@ $bind = (new Bind())->bind(RealBillingService::class, [$pointcut]);
$billing = (new Weaver($bind, $tmpDir))->newInstance(RealBillingService::class, [$arg1, $arg2]);
```
+The matcher supports reading doctrine annotations or PHP8 attributes.
+
+```php
+ public function matchesClass(\ReflectionClass $class, array $arguments) : bool
+ {
+ assert($class instanceof \Ray\Aop\ReflectionClass);
+ $classAnnotation = $class->getAnnotation(Foo::class); // @Foo or #[Foo]
+ // ...
+ }
+
+ public function matchesMethod(\ReflectionMethod $method, array $arguments) : bool
+ {
+ assert($method instanceof \Ray\Aop\ReflectionMethod);
+ $methodAnnotation = $method->getAnnotation(Bar::class);
+ }
+```
+
## Performance boost
Cached `Weaver` object can save the compiling, binding, annotation reading costs.
@@ -245,16 +262,20 @@ The recommended way to install Ray.Aop is through [Composer](https://github.com/
$ composer require ray/aop ^2.0
```
-## Testing Ray.Aop
+## Performance
-Here's how to install Ray.Aop from source and run the unit tests and demos.
+Compilation of the AOP class allows Ray.Aop to run faster. Annotations are only loaded at first compile time, so they do not affect runtime performance. During the development phase and even at first runtime, PHP files are cached using the file timestamps, so normally you do not need to worry about the cost of annotation generation, but by setting up an annotation reader in the application bootstrap, first-time compile time performance. This setting is especially useful for large applications.
-```bash
-git clone https://github.com/ray-di/Ray.Aop.git
-cd Ray.Aop
-composer install
-composer test
-php demo/run.php
+### APCu
+
+```php
+SevericeLocator::setReader(new PsrCachedReader(new Reader(), $apcuCache));
+```
+
+### PHP8 attributes only (recommended)
+
+```php
+SevericeLocator::setReader(new AttributeReader);`
```
## Integrated DI framework
diff --git a/annotation_loader.php b/annotation_loader.php
index 455624b9..9f890289 100644
--- a/annotation_loader.php
+++ b/annotation_loader.php
@@ -4,4 +4,6 @@
use Doctrine\Common\Annotations\AnnotationRegistry;
-AnnotationRegistry::registerLoader('class_exists');
+if (method_exists(AnnotationRegistry::class, 'registerLoader')) {
+ AnnotationRegistry::registerLoader('class_exists');
+}
diff --git a/composer.json b/composer.json
index c5d7697d..87c49b4c 100644
--- a/composer.json
+++ b/composer.json
@@ -11,7 +11,7 @@
],
"require": {
"php": "^7.2 || ^8.0",
- "doctrine/annotations": "^1.12",
+ "doctrine/annotations": "^1.12 || ^2.0",
"koriym/attributes": "^1.0.3",
"nikic/php-parser": "^4.16"
},
@@ -42,19 +42,16 @@
"ray/di": "A dependency injection framework"
},
"scripts" :{
- "bin": "echo 'bin not installed'",
- "post-install-cmd": ["@composer bin all install --ansi"],
- "post-update-cmd": ["@composer bin all update --ansi"],
- "test": ["./vendor/bin/phpunit"],
+ "test": ["phpunit"],
"tests": ["@cs", "@test", "@sa"],
- "coverage": ["php -dzend_extension=xdebug.so -dxdebug.mode=coverage ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage"],
- "pcov": ["php -dextension=pcov.so -d pcov.enabled=1 ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage --coverage-clover=coverage.xml"],
- "cs": ["phpcs --standard=./phpcs.xml src tests"],
- "cs-fix": ["./vendor/bin/phpcbf src tests"],
- "clean": ["./vendor/bin/phpstan clear-result-cache", "./vendor/bin/psalm --clear-cache", "rm -rf tests/tmp/*.php"],
- "sa": ["./vendor/bin/psalm --show-info=true", "./vendor/bin/phpstan analyse -c phpstan.neon"],
- "metrics": ["./vendor/bin/phpmetrics --report-html=build/metrics --exclude=Exception src"],
- "phpmd": ["./vendor/bin/phpmd src text ./phpmd.xml"],
+ "coverage": ["php -dzend_extension=xdebug.so -dxdebug.mode=coverage phpunit --coverage-text --coverage-html=build/coverage"],
+ "pcov": ["php -dextension=pcov.so -d pcov.enabled=1 phpunit --coverage-text --coverage-html=build/coverage --coverage-clover=coverage.xml"],
+ "cs": ["phpcs --standard=./phpcs.xml sl-src src tests"],
+ "cs-fix": ["phpcbf sl-src src tests"],
+ "clean": ["phpstan clear-result-cache", "psalm --clear-cache", "rm -rf tests/tmp/*.php"],
+ "sa": ["psalm --monochrome --show-info=true", "phpstan --memory-limit=-1 analyse -c phpstan.neon"],
+ "metrics": ["phpmetrics --report-html=build/metrics --exclude=Exception src"],
+ "phpmd": ["phpmd src text ./phpmd.xml"],
"build": ["@cs", "@sa", "@pcov", "@metrics"]
},
"extra": {
@@ -62,6 +59,5 @@
"forward-command": true,
"bin-links": true
}
- },
- "minimum-stability": "alpha"
+ }
}
diff --git a/phpcs.xml b/phpcs.xml
index 8bdf94bd..15d1f034 100755
--- a/phpcs.xml
+++ b/phpcs.xml
@@ -41,6 +41,7 @@ com
+
diff --git a/phpstan.neon b/phpstan.neon
index 2e552471..e05600cf 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -1,6 +1,7 @@
parameters:
level: max
paths:
+ - sl-src
- src
- tests
excludePaths:
diff --git a/psalm.xml b/psalm.xml
index e1c8ce11..59c3c010 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -1,12 +1,14 @@
+
diff --git a/sl-src/Cache.php b/sl-src/Cache.php
new file mode 100644
index 00000000..0aebcb76
--- /dev/null
+++ b/sl-src/Cache.php
@@ -0,0 +1,101 @@
+tmpDir = $tmpDir;
+ }
+
+ /**
+ * @psalm-param callable():array