diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 9cf0c43..35f0b8f 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -23,7 +23,7 @@ jobs:
strategy:
matrix:
- php-version: ["7.4"]
+ php-version: ["8.0"]
operating-system: ["ubuntu-latest"]
fail-fast: false
@@ -80,11 +80,11 @@ jobs:
runs-on: "${{ matrix.operating-system }}"
strategy:
matrix:
- php-version: ["7.4"]
+ php-version: ["8.0"]
operating-system: ["ubuntu-latest"]
composer-args: [ "" ]
include:
- - php-version: "7.4"
+ - php-version: "8.0"
operating-system: "ubuntu-latest"
composer-args: "--prefer-lowest"
- php-version: "8.0"
@@ -92,8 +92,6 @@ jobs:
composer-args: "--ignore-platform-reqs"
fail-fast: false
- continue-on-error: "${{ matrix.php-version == '8.0' }}"
-
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
@@ -149,7 +147,7 @@ jobs:
strategy:
matrix:
- php-version: ["7.4"]
+ php-version: ["8.0"]
operating-system: ["ubuntu-latest"]
fail-fast: false
@@ -205,7 +203,7 @@ jobs:
strategy:
matrix:
- php-version: ["7.4"]
+ php-version: ["8.0"]
operating-system: ["ubuntu-latest"]
fail-fast: false
diff --git a/composer.json b/composer.json
index 91f8768..01916c6 100644
--- a/composer.json
+++ b/composer.json
@@ -14,32 +14,29 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
- "php": ">=7.4",
+ "php": ">=8.0",
"nette/di": "^3.0.3",
- "nette/php-generator": "^3.0",
+ "nette/php-generator": "^3.5",
"nette/tokenizer": "~3.0",
- "nettrine/annotations": "^0.7",
- "doctrine/annotations": "^1.11",
- "symfony/property-access": "^4.4|~5.0",
- "nettrine/cache": "^0.3"
+ "symfony/property-access": "^4.4|~5.0"
},
"require-dev": {
- "nette/application": "^3.0.1",
- "nette/bootstrap": "~3.0",
- "nette/caching": "~3.0",
+ "nette/application": "^3.1",
+ "nette/bootstrap": "~3.1",
+ "nette/caching": "~3.1",
"nette/component-model": "~3.0",
- "nette/database": "~3.0",
+ "nette/database": "~3.1",
"nette/finder": "~2.5",
- "nette/forms": "~3.0",
- "nette/http": "~3.0",
- "nette/mail": "~3.0",
- "nette/neon": "~3.0",
- "nette/robot-loader": "^3.0",
+ "nette/forms": "~3.1",
+ "nette/http": "~3.1",
+ "nette/mail": "~3.1",
+ "nette/neon": "~3.1",
+ "nette/robot-loader": "^3.4",
"nette/safe-stream": "~2.4",
"nette/security": "~3.0",
- "nette/utils": "^3.1",
- "latte/latte": "~2.5",
- "tracy/tracy": "~2.6",
+ "nette/utils": "^3.2",
+ "latte/latte": "~2.10",
+ "tracy/tracy": "~2.8",
"doctrine/collections": "~1.6",
"ninjify/qa": "^0.12",
"phpstan/phpstan-nette": "^0.12",
diff --git a/ruleset.xml b/ruleset.xml
index dc49d2c..c70f840 100644
--- a/ruleset.xml
+++ b/ruleset.xml
@@ -3,6 +3,7 @@
+
diff --git a/src/Annotations/AdviceAnnotation.php b/src/Annotations/AdviceAnnotation.php
deleted file mode 100644
index 434c940..0000000
--- a/src/Annotations/AdviceAnnotation.php
+++ /dev/null
@@ -1,8 +0,0 @@
-value = $value;
+ }
+
+
+ public static function getClassName(): string
+ {
+ return static::class;
+ }
+
+ public function getValue(): string
+ {
+ return $this->value;
+ }
+
+}
diff --git a/src/Attributes/Before.php b/src/Attributes/Before.php
new file mode 100644
index 0000000..26ac5f9
--- /dev/null
+++ b/src/Attributes/Before.php
@@ -0,0 +1,14 @@
+getContainerBuilder();
@@ -152,9 +144,8 @@ private function findAdvisedMethods(): array
$builder = $this->getContainerBuilder();
$builder->resolve();
- $annotationReader = new AnnotationReader();
- $matcherFactory = new Pointcut\MatcherFactory($builder, $annotationReader);
- $analyzer = new Pointcut\AspectAnalyzer(new Pointcut\Parser($matcherFactory), $annotationReader);
+ $matcherFactory = new Pointcut\MatcherFactory($builder);
+ $analyzer = new Pointcut\AspectAnalyzer(new Pointcut\Parser($matcherFactory));
$advisedMethods = [];
$this->classes = null;
diff --git a/src/JoinPoint/MethodInvocation.php b/src/JoinPoint/MethodInvocation.php
index 0082b33..66becb3 100644
--- a/src/JoinPoint/MethodInvocation.php
+++ b/src/JoinPoint/MethodInvocation.php
@@ -2,7 +2,6 @@
namespace Contributte\Aop\JoinPoint;
-use Doctrine\Common\Annotations\AnnotationReader;
use Nette;
use ReflectionClass;
use ReflectionMethod;
@@ -19,8 +18,6 @@ abstract class MethodInvocation
/** @var mixed[] $arguments */
protected array $arguments;
- private AnnotationReader $annotationReader;
-
/**
* @param mixed[] $arguments
*/
@@ -29,7 +26,6 @@ public function __construct(object $targetObject, string $targetMethod, array $a
$this->targetObject = $targetObject;
$this->targetMethod = $targetMethod;
$this->arguments = $arguments;
- $this->annotationReader = new AnnotationReader();
}
@@ -61,22 +57,4 @@ public function getTargetReflection(): ReflectionMethod
return new ReflectionMethod($this->targetObject, $this->targetMethod);
}
-
- /**
- * @param class-string $name
- */
- public function getAnnotation(string $name): ?object
- {
- return $this->annotationReader->getMethodAnnotation($this->getTargetReflection(), $name);
- }
-
-
- /**
- * @return object[]
- */
- public function getAnnotations(): array
- {
- return $this->annotationReader->getMethodAnnotations($this->getTargetReflection());
- }
-
}
diff --git a/src/PhpGenerator/PointcutMethod.php b/src/PhpGenerator/PointcutMethod.php
index 291401c..b4c806d 100644
--- a/src/PhpGenerator/PointcutMethod.php
+++ b/src/PhpGenerator/PointcutMethod.php
@@ -2,16 +2,15 @@
namespace Contributte\Aop\PhpGenerator;
-use Contributte\Aop\Annotations\After;
-use Contributte\Aop\Annotations\AfterReturning;
-use Contributte\Aop\Annotations\AfterThrowing;
-use Contributte\Aop\Annotations\Around;
-use Contributte\Aop\Annotations\Before;
+use Contributte\Aop\Attributes\After;
+use Contributte\Aop\Attributes\AfterReturning;
+use Contributte\Aop\Attributes\AfterThrowing;
+use Contributte\Aop\Attributes\Around;
+use Contributte\Aop\Attributes\Before;
use Contributte\Aop\DI\AdviceDefinition;
use Contributte\Aop\Exceptions\InvalidArgumentException;
use Contributte\Aop\Exceptions\NotImplementedException;
use Contributte\Aop\Pointcut\RuntimeFilter;
-use Doctrine\Common\Annotations\AnnotationReader;
use Nette;
use Nette\PhpGenerator as Code;
use ReflectionException;
@@ -72,14 +71,6 @@ public static function from(ReflectionMethod $from): PointcutMethod
$method->method->setVariadic($from->isVariadic());
$docComment = $from->getDocComment();
if ($docComment !== false) {
- $annotations = (new AnnotationReader())->getMethodAnnotations($from);
- foreach ($annotations as $annotation) {
- $annotationFqn = get_class($annotation);
- $annotationShortClassName = Nette\Utils\Strings::after($annotationFqn, '\\', -1);
-
- $docComment = str_replace('@' . $annotationShortClassName, '@' . $annotationFqn, $docComment);
- }
-
$method->method->setComment(Code\Helpers::unformatDocComment($docComment));
}
diff --git a/src/Pointcut/AspectAnalyzer.php b/src/Pointcut/AspectAnalyzer.php
index 48f41c2..1bd7cf7 100644
--- a/src/Pointcut/AspectAnalyzer.php
+++ b/src/Pointcut/AspectAnalyzer.php
@@ -2,25 +2,20 @@
namespace Contributte\Aop\Pointcut;
-use Contributte\Aop\Annotations\AdviceAnnotation;
+use Contributte\Aop\Attributes\AdviceAttribute;
use Contributte\Aop\Exceptions\InvalidAspectExceptions;
-use Doctrine\Common\Annotations\Annotation;
-use Doctrine\Common\Annotations\AnnotationReader;
-use Doctrine\Common\Annotations\Reader;
use Nette;
+use ReflectionAttribute;
class AspectAnalyzer
{
use Nette\SmartObject;
- private Reader $annotationReader;
-
private Parser $pointcutParser;
- public function __construct(Parser $parser, ?Reader $reader = null)
+ public function __construct(Parser $parser)
{
- $this->annotationReader = $reader ?: new AnnotationReader();
$this->pointcutParser = $parser;
}
@@ -34,13 +29,13 @@ public function analyze(ServiceDefinition $service): array
{
$pointcuts = [];
foreach ($service->getOpenMethods() as $method) {
- if (!$annotations = $this->filterAopAnnotations($method->getAnnotations($this->annotationReader))) {
+ if (!$attributes = $this->getAopAdviceAttributes($method->getAttributes())) {
continue;
}
$rules = [];
- foreach ($annotations as $annotation) {
- $rules[get_class($annotation)] = $this->pointcutParser->parse($annotation->value);
+ foreach ($attributes as $attr) {
+ $rules[get_class($attr)] = $this->pointcutParser->parse($attr->getValue());
}
$pointcuts[$method->getName()] = $rules;
@@ -56,14 +51,20 @@ public function analyze(ServiceDefinition $service): array
/**
- * @param Annotation[] $annotations
- * @return AdviceAnnotation[]
+ * @param ReflectionAttribute[] $attributes
+ * @return AdviceAttribute[]
*/
- private function filterAopAnnotations(array $annotations): array
+ private function getAopAdviceAttributes(array $attributes): array
{
- return array_filter($annotations, function ($annotation) {
- return $annotation instanceof AdviceAnnotation;
- });
+ $result = [];
+ foreach ($attributes as $attribute) {
+ $instance = $attribute->newInstance();
+ if ($instance instanceof AdviceAttribute) {
+ $result[] = $instance;
+ }
+ }
+
+ return $result;
}
}
diff --git a/src/Pointcut/Matcher/ClassAnnotateWithMatcher.php b/src/Pointcut/Matcher/ClassAnnotateWithMatcher.php
deleted file mode 100644
index a43cf01..0000000
--- a/src/Pointcut/Matcher/ClassAnnotateWithMatcher.php
+++ /dev/null
@@ -1,50 +0,0 @@
-annotationClass = $annotationClass;
- $this->reader = $reader;
- }
-
-
-
- public function matches(Method $method): bool
- {
- foreach ($method->getClassAnnotations($this->reader) as $annotation) {
- if (!$annotation instanceof $this->annotationClass) {
- continue;
- }
-
- return true;
- }
-
- return false;
- }
-
-
-
- /**
- * @return string[]
- */
- public function listAcceptedTypes(): array
- {
- return [];
- }
-
-}
diff --git a/src/Pointcut/Matcher/ClassAttributedWithMatcher.php b/src/Pointcut/Matcher/ClassAttributedWithMatcher.php
new file mode 100644
index 0000000..0199ecd
--- /dev/null
+++ b/src/Pointcut/Matcher/ClassAttributedWithMatcher.php
@@ -0,0 +1,46 @@
+attributeClass = $attributeClass;
+ }
+
+
+
+ public function matches(Method $method): bool
+ {
+ foreach ($method->getClassAttributes() as $attribute) {
+ if (!$attribute->newInstance() instanceof $this->attributeClass) {
+ continue;
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+
+
+ /**
+ * @return string[]
+ */
+ public function listAcceptedTypes(): array
+ {
+ return [];
+ }
+
+}
diff --git a/src/Pointcut/Matcher/MethodAnnotateWithMatcher.php b/src/Pointcut/Matcher/MethodAnnotateWithMatcher.php
deleted file mode 100644
index a7e5a2e..0000000
--- a/src/Pointcut/Matcher/MethodAnnotateWithMatcher.php
+++ /dev/null
@@ -1,47 +0,0 @@
-annotationClass = $annotationClass;
- $this->reader = $reader;
- }
-
-
- public function matches(Method $method): bool
- {
- foreach ($method->getAnnotations($this->reader) as $annotation) {
- if (!$annotation instanceof $this->annotationClass) {
- continue;
- }
-
- return true;
- }
-
- return false;
- }
-
- /**
- * @return string[]
- */
- public function listAcceptedTypes(): array
- {
- return [];
- }
-
-}
diff --git a/src/Pointcut/Matcher/MethodAttributedWithMatcher.php b/src/Pointcut/Matcher/MethodAttributedWithMatcher.php
new file mode 100644
index 0000000..b346e1a
--- /dev/null
+++ b/src/Pointcut/Matcher/MethodAttributedWithMatcher.php
@@ -0,0 +1,43 @@
+attributeClass = $attributeClass;
+ }
+
+
+ public function matches(Method $method): bool
+ {
+ foreach ($method->getAttributes() as $attribute) {
+ if (!$attribute->newInstance() instanceof $this->attributeClass) {
+ continue;
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * @return string[]
+ */
+ public function listAcceptedTypes(): array
+ {
+ return [];
+ }
+
+}
diff --git a/src/Pointcut/MatcherFactory.php b/src/Pointcut/MatcherFactory.php
index e706878..e7182d0 100644
--- a/src/Pointcut/MatcherFactory.php
+++ b/src/Pointcut/MatcherFactory.php
@@ -2,16 +2,14 @@
namespace Contributte\Aop\Pointcut;
-use Contributte\Aop\Pointcut\Matcher\ClassAnnotateWithMatcher;
+use Contributte\Aop\Pointcut\Matcher\ClassAttributedWithMatcher;
use Contributte\Aop\Pointcut\Matcher\Criteria;
use Contributte\Aop\Pointcut\Matcher\EvaluateMatcher;
use Contributte\Aop\Pointcut\Matcher\FilterMatcher;
-use Contributte\Aop\Pointcut\Matcher\MethodAnnotateWithMatcher;
+use Contributte\Aop\Pointcut\Matcher\MethodAttributedWithMatcher;
use Contributte\Aop\Pointcut\Matcher\MethodMatcher;
use Contributte\Aop\Pointcut\Matcher\SettingMatcher;
use Contributte\Aop\Pointcut\Matcher\WithinMatcher;
-use Doctrine\Common\Annotations\AnnotationReader;
-use Doctrine\Common\Annotations\Reader;
use Nette;
use Nette\DI\ContainerBuilder;
@@ -22,15 +20,12 @@ class MatcherFactory
private ContainerBuilder $builder;
- private Reader $annotationReader;
-
/** @var mixed[] */
private array $cache = [];
- public function __construct(Nette\DI\ContainerBuilder $builder, ?Reader $annotationReader = null)
+ public function __construct(Nette\DI\ContainerBuilder $builder)
{
$this->builder = $builder;
- $this->annotationReader = $annotationReader ?: new AnnotationReader();
}
@@ -102,16 +97,16 @@ public function createEvaluate(Criteria $evaluate): EvaluateMatcher
- public function createClassAnnotatedWith(string $annotation): ClassAnnotateWithMatcher
+ public function createClassAttributedWith(string $attributte): ClassAttributedWithMatcher
{
- return new ClassAnnotateWithMatcher($annotation, $this->annotationReader);
+ return new ClassAttributedWithMatcher($attributte);
}
- public function createMethodAnnotatedWith(string $annotation): MethodAnnotateWithMatcher
+ public function createMethodAttributedWith(string $attribute): MethodAttributedWithMatcher
{
- return new MethodAnnotateWithMatcher($annotation, $this->annotationReader);
+ return new MethodAttributedWithMatcher($attribute);
}
}
diff --git a/src/Pointcut/Method.php b/src/Pointcut/Method.php
index 0028368..587a2fd 100644
--- a/src/Pointcut/Method.php
+++ b/src/Pointcut/Method.php
@@ -3,9 +3,8 @@
namespace Contributte\Aop\Pointcut;
use Contributte\Aop\PhpGenerator\PointcutMethod;
-use Doctrine\Common\Annotations\Annotation;
-use Doctrine\Common\Annotations\Reader;
use Nette;
+use ReflectionAttribute;
use ReflectionMethod;
/**
@@ -41,8 +40,15 @@ public function getName(): string
public function getVisibility(): string
{
- return $this->method->isPublic() ? self::VISIBILITY_PUBLIC
- : ($this->method->isProtected() ? self::VISIBILITY_PROTECTED : self::VISIBILITY_PRIVATE);
+ if ($this->method->isPublic()) {
+ return self::VISIBILITY_PUBLIC;
+ }
+
+ if ($this->method->isProtected()) {
+ return self::VISIBILITY_PROTECTED;
+ }
+
+ return self::VISIBILITY_PRIVATE;
}
@@ -64,27 +70,21 @@ public function getTypesWithin(): array
/**
- * @return Annotation[]
+ * @return ReflectionAttribute[]
*/
- public function getAnnotations(Reader $reader): array
+ public function getAttributes(): array
{
- /** @var Annotation[] $annotations */
- $annotations = $reader->getMethodAnnotations($this->method);
-
- return $annotations;
+ return $this->method->getAttributes();
}
/**
- * @return Annotation[]
+ * @return ReflectionAttribute[]
*/
- public function getClassAnnotations(Reader $reader): array
+ public function getClassAttributes(): array
{
- /** @var Annotation[] $annotations */
- $annotations = $reader->getClassAnnotations($this->serviceDefinition->getTypeReflection());
-
- return $annotations;
+ return $this->serviceDefinition->getTypeReflection()->getAttributes();
}
diff --git a/src/Pointcut/Parser.php b/src/Pointcut/Parser.php
index 1c69eea..18116be 100644
--- a/src/Pointcut/Parser.php
+++ b/src/Pointcut/Parser.php
@@ -36,7 +36,7 @@ public function __construct(MatcherFactory $matcherFactory)
$this->tokenizer = new Tokenizer([
self::TOK_BRACKET => '[\\(\\)]',
self::TOK_VISIBILITY => '(?:public|protected|private)(?=[\t ]+)',
- self::TOK_KEYWORD => '(?:classAnnotatedWith|class|methodAnnotatedWith|method|within|filter|setting|evaluate)(?=\\()',
+ self::TOK_KEYWORD => '(?:classAttributedWith|class|methodAttributedWith|method|within|filter|setting|evaluate)(?=\\()',
self::TOK_OPERATOR => '(?:===?|!==?|<=|>=|<|>|n?in|contains|matches)',
self::TOK_LOGIC => '(?:\\&\\&|\\|\\||,)',
self::TOK_NOT => '!',
@@ -229,24 +229,24 @@ protected function parseEvaluate(Stream $tokens): Filter
- protected function parseClassAnnotatedWith(Stream $tokens): Filter
+ protected function parseClassAttributedWith(Stream $tokens): Filter
{
$tokens->nextUntil(self::TOK_IDENTIFIER);
- $annotation = $tokens->nextValue();
+ $attributte = $tokens->nextValue();
$tokens->nextToken(); // )
- return $this->matcherFactory->getMatcher('classAnnotatedWith', $annotation);
+ return $this->matcherFactory->getMatcher('classAttributedWith', $attributte);
}
- protected function parseMethodAnnotatedWith(Stream $tokens): Filter
+ protected function parseMethodAttributedWith(Stream $tokens): Filter
{
$tokens->nextUntil(self::TOK_IDENTIFIER);
- $annotation = $tokens->nextValue();
+ $attribute = $tokens->nextValue();
$tokens->nextToken(); // )
- return $this->matcherFactory->getMatcher('methodAnnotatedWith', $annotation);
+ return $this->matcherFactory->getMatcher('methodAttributedWith', $attribute);
}
diff --git a/tests/Cases/AspectAnalyzerTest.php b/tests/Cases/AspectAnalyzerTest.php
index b8d0c10..6f0329a 100644
--- a/tests/Cases/AspectAnalyzerTest.php
+++ b/tests/Cases/AspectAnalyzerTest.php
@@ -2,14 +2,13 @@
namespace Tests\Cases;
-use Contributte\Aop\Annotations\After;
-use Contributte\Aop\Annotations\AfterReturning;
-use Contributte\Aop\Annotations\AfterThrowing;
-use Contributte\Aop\Annotations\Around;
-use Contributte\Aop\Annotations\Before;
+use Contributte\Aop\Attributes\After;
+use Contributte\Aop\Attributes\AfterReturning;
+use Contributte\Aop\Attributes\AfterThrowing;
+use Contributte\Aop\Attributes\Around;
+use Contributte\Aop\Attributes\Before;
use Contributte\Aop\Pointcut;
use Contributte\Aop\Pointcut\ServiceDefinition;
-use Doctrine\Common\Annotations\AnnotationReader;
use Nette;
use PHPUnit\Framework\TestCase;
use Tests\Files\Aspects\AfterAspect;
@@ -101,9 +100,8 @@ public function dataAnalyze(): array
public function testAnalyze(array $pointcuts, ServiceDefinition $service): void
{
$builder = new Nette\DI\ContainerBuilder();
- $annotationReader = new AnnotationReader();
- $matcherFactory = new Pointcut\MatcherFactory($builder, $annotationReader);
- $analyzer = new Pointcut\AspectAnalyzer(new Pointcut\Parser($matcherFactory), $annotationReader);
+ $matcherFactory = new Pointcut\MatcherFactory($builder);
+ $analyzer = new Pointcut\AspectAnalyzer(new Pointcut\Parser($matcherFactory));
$this->assertEquals($pointcuts, $analyzer->analyze($service));
}
diff --git a/tests/Cases/ExtensionTest.php b/tests/Cases/ExtensionTest.php
index 2167120..107d113 100644
--- a/tests/Cases/ExtensionTest.php
+++ b/tests/Cases/ExtensionTest.php
@@ -19,8 +19,6 @@
use Contributte\Aop\JoinPoint\MethodInvocation;
use Contributte\Aop\JoinPoint\ResultAware;
use Nette;
-use Nettrine\Annotations\DI\AnnotationsExtension;
-use Nettrine\Cache\DI\CacheExtension;
use PHPUnit\Framework\TestCase;
use ReflectionException;
use ReflectionProperty;
@@ -56,10 +54,6 @@ public function createContainer(string $configFile): Nette\DI\Container
$config->addConfig(__DIR__ . '/../nette-reset.neon');
$config->addConfig(__DIR__ . '/../config/' . $configFile . '.neon');
- $config->onCompile[] = function (Nette\Configurator $config, Nette\DI\Compiler $compiler): void {
- $compiler->addExtension('annotations', new AnnotationsExtension());
- $compiler->addExtension('nettrine.cache', new CacheExtension());
- };
AspectsExtension::register($config);
AopExtension::register($config);
diff --git a/tests/Cases/PointcutParserTest.php b/tests/Cases/PointcutParserTest.php
index 069121b..36556df 100644
--- a/tests/Cases/PointcutParserTest.php
+++ b/tests/Cases/PointcutParserTest.php
@@ -265,23 +265,23 @@ public function testParse(Filter $expected, string $input): void
$this->assertEquals($expected, $parser->parse($input));
}
- public function testParseClassAnnotatedWith(): void
+ public function testParseClassAttributedWith(): void
{
$mf = $this->getMatcherFactory();
$parser = new Parser($this->getMatcherFactory());
$this->assertEquals(
- $mf->getMatcher('classAnnotatedWith', 'Doctrine\ORM\Mapping\Entity'),
- $parser->parse('classAnnotatedWith(Doctrine\ORM\Mapping\Entity)')
+ $mf->getMatcher('classAttributedWith', 'Doctrine\ORM\Mapping\Entity'),
+ $parser->parse('classAttributedWith(Doctrine\ORM\Mapping\Entity)')
);
}
- public function testParseMethodAnnotatedWith(): void
+ public function testParseMethodAttributedWith(): void
{
$mf = $this->getMatcherFactory();
$parser = new Parser($this->getMatcherFactory());
$this->assertEquals(
- $mf->getMatcher('classAnnotatedWith', 'Acme\Demo\Annotations\Special'),
- $parser->parse('classAnnotatedWith(Acme\Demo\Annotations\Special)')
+ $mf->getMatcher('classAttributedWith', 'Acme\Demo\Annotations\Special'),
+ $parser->parse('classAttributedWith(Acme\Demo\Annotations\Special)')
);
}
diff --git a/tests/Cases/PointcutRulesTest.php b/tests/Cases/PointcutRulesTest.php
index 5e28bd2..39338f0 100644
--- a/tests/Cases/PointcutRulesTest.php
+++ b/tests/Cases/PointcutRulesTest.php
@@ -10,15 +10,14 @@
use Contributte\Aop\Pointcut;
use Contributte\Aop\Pointcut\Filter;
-use Contributte\Aop\Pointcut\Matcher\ClassAnnotateWithMatcher;
+use Contributte\Aop\Pointcut\Matcher\ClassAttributedWithMatcher;
use Contributte\Aop\Pointcut\Matcher\FilterMatcher;
-use Contributte\Aop\Pointcut\Matcher\MethodAnnotateWithMatcher;
+use Contributte\Aop\Pointcut\Matcher\MethodAttributedWithMatcher;
use Contributte\Aop\Pointcut\Matcher\MethodMatcher;
use Contributte\Aop\Pointcut\Matcher\SettingMatcher;
use Contributte\Aop\Pointcut\Matcher\WithinMatcher;
use Contributte\Aop\Pointcut\Method;
use Contributte\Aop\Pointcut\Rules;
-use Doctrine\Common\Annotations\AnnotationReader;
use Nette\Bridges\ApplicationLatte\Template;
use Nette\DI\ContainerBuilder;
use Nette\DI\Definitions\ServiceDefinition;
@@ -123,18 +122,17 @@ public function testMatchFilter(bool $expected, Filter $rules, Pointcut\ServiceD
/**
* @return array>
*/
- public function dataMatchClassAnnotateWith(): array
+ public function dataMatchClassAttributedWith(): array
{
$data = [];
- $reader = new AnnotationReader();
- $data[] = [true, new Rules([new ClassAnnotateWithMatcher(Test::class, $reader)]), $this->createDefinition(SmegHead::class)];
- $data[] = [false, new Rules([new ClassAnnotateWithMatcher(Test::class, $reader)]), $this->createDefinition(Legie::class)];
+ $data[] = [true, new Rules([new ClassAttributedWithMatcher(Test::class)]), $this->createDefinition(SmegHead::class)];
+ $data[] = [false, new Rules([new ClassAttributedWithMatcher(Test::class)]), $this->createDefinition(Legie::class)];
return $data;
}
/**
- * @dataProvider dataMatchClassAnnotateWith
+ * @dataProvider dataMatchClassAttributedWith
*/
- public function testMatchClassAnnotateWith(bool $expected, Filter $rules, Pointcut\ServiceDefinition $def): void
+ public function testMatchClassAttributedWith(bool $expected, Filter $rules, Pointcut\ServiceDefinition $def): void
{
$this->assertSame($expected, (bool) $def->match($rules));
}
@@ -142,18 +140,17 @@ public function testMatchClassAnnotateWith(bool $expected, Filter $rules, Pointc
/**
* @return array>
*/
- public function dataMatchMethodAnnotateWith(): array
+ public function dataMatchMethodAttributedWith(): array
{
$data = [];
- $reader = new AnnotationReader();
- $data[] = [true, new Rules([new MethodAnnotateWithMatcher(Test::class, $reader)]), $this->createDefinition(Legie::class)];
- $data[] = [false, new Rules([new MethodAnnotateWithMatcher(Test::class, $reader)]), $this->createDefinition(SmegHead::class)];
+ $data[] = [true, new Rules([new MethodAttributedWithMatcher(Test::class)]), $this->createDefinition(Legie::class)];
+ $data[] = [false, new Rules([new MethodAttributedWithMatcher(Test::class)]), $this->createDefinition(SmegHead::class)];
return $data;
}
/**
- * @dataProvider dataMatchMethodAnnotateWith
+ * @dataProvider dataMatchMethodAttributedWith
*/
- public function testMatchMethodAnnotateWith(bool $expected, Filter $rules, Pointcut\ServiceDefinition $def): void
+ public function testMatchMethodAttributedWith(bool $expected, Filter $rules, Pointcut\ServiceDefinition $def): void
{
$this->assertSame($expected, (bool) $def->match($rules));
}
diff --git a/tests/Files/Aspects/AfterAspect.php b/tests/Files/Aspects/AfterAspect.php
index 322bd6c..63f1d12 100644
--- a/tests/Files/Aspects/AfterAspect.php
+++ b/tests/Files/Aspects/AfterAspect.php
@@ -2,7 +2,8 @@
namespace Tests\Files\Aspects;
-use Contributte\Aop;
+use Contributte\Aop\Attributes\After;
+use Contributte\Aop\JoinPoint\AfterMethod;
use Nette;
class AfterAspect
@@ -10,13 +11,12 @@ class AfterAspect
use Nette\SmartObject;
- /** @var array|Aop\JoinPoint\AfterMethod[] */
+ /** @var array|AfterMethod[] */
public array $calls = [];
- /**
- * @Aop\Annotations\After("method(Tests\Files\Aspects\CommonService->magic)")
- */
- public function log(Aop\JoinPoint\AfterMethod $after): void
+ #[After('method(Tests\Files\Aspects\CommonService->magic)')]
+
+ public function log(AfterMethod $after): void
{
$this->calls[] = $after;
}
diff --git a/tests/Files/Aspects/AfterReturningAspect.php b/tests/Files/Aspects/AfterReturningAspect.php
index 08935e0..8168b4d 100644
--- a/tests/Files/Aspects/AfterReturningAspect.php
+++ b/tests/Files/Aspects/AfterReturningAspect.php
@@ -16,9 +16,8 @@ class AfterReturningAspect
/** @var mixed|false */
public $modifyReturn = false;
- /**
- * @Aop\Annotations\AfterReturning("method(Tests\Files\Aspects\CommonService->magic)")
- */
+ #[Aop\Attributes\AfterReturning('method(Tests\Files\Aspects\CommonService->magic)')]
+
public function log(Aop\JoinPoint\AfterReturning $after): void
{
$this->calls[] = $after;
diff --git a/tests/Files/Aspects/AfterThrowingAspect.php b/tests/Files/Aspects/AfterThrowingAspect.php
index 8530cd9..5efcedf 100644
--- a/tests/Files/Aspects/AfterThrowingAspect.php
+++ b/tests/Files/Aspects/AfterThrowingAspect.php
@@ -13,9 +13,9 @@ class AfterThrowingAspect
/** @var array|Aop\JoinPoint\AfterThrowing[] */
public array $calls = [];
- /**
- * @Aop\Annotations\AfterThrowing("method(Tests\Files\Aspects\CommonService->magic)")
- */
+
+ #[Aop\Attributes\AfterThrowing('method(Tests\Files\Aspects\CommonService->magic)')]
+
public function log(Aop\JoinPoint\AfterThrowing $after): void
{
$this->calls[] = $after;
diff --git a/tests/Files/Aspects/AroundAspect.php b/tests/Files/Aspects/AroundAspect.php
index 18c310a..5960495 100644
--- a/tests/Files/Aspects/AroundAspect.php
+++ b/tests/Files/Aspects/AroundAspect.php
@@ -20,9 +20,10 @@ class AroundAspect
public $modifyReturn = false;
/**
- * @Aop\Annotations\Around("method(Tests\Files\Aspects\CommonService->magic)")
* @return mixed
*/
+ #[Aop\Attributes\Around('method(Tests\Files\Aspects\CommonService->magic)')]
+
public function log(Aop\JoinPoint\AroundMethod $around)
{
$this->calls[] = $around;
diff --git a/tests/Files/Aspects/AroundBlockingAspect.php b/tests/Files/Aspects/AroundBlockingAspect.php
index 1c26961..970c4a6 100644
--- a/tests/Files/Aspects/AroundBlockingAspect.php
+++ b/tests/Files/Aspects/AroundBlockingAspect.php
@@ -25,9 +25,10 @@ class AroundBlockingAspect
public $modifyThrow = false;
/**
- * @Aop\Annotations\Around("method(Tests\Files\Aspects\CommonService->magic)")
* @return mixed
*/
+ #[Aop\Attributes\Around('method(Tests\Files\Aspects\CommonService->magic)')]
+
public function log(Aop\JoinPoint\AroundMethod $around)
{
$this->calls[] = $around;
diff --git a/tests/Files/Aspects/AspectWithArguments.php b/tests/Files/Aspects/AspectWithArguments.php
index ca17c09..8bdc688 100644
--- a/tests/Files/Aspects/AspectWithArguments.php
+++ b/tests/Files/Aspects/AspectWithArguments.php
@@ -19,9 +19,8 @@ public function __construct(Nette\Http\Request $httpRequest)
}
- /**
- * @Aop\Annotations\After("method(Tests\Files\Aspects\CommonService->magic)")
- */
+ #[Aop\Attributes\After('method(Tests\Files\Aspects\CommonService->magic)')]
+
public function log(Aop\JoinPoint\AfterMethod $after): void
{
// pass
diff --git a/tests/Files/Aspects/BeforeAspect.php b/tests/Files/Aspects/BeforeAspect.php
index 4a954d0..7a52053 100644
--- a/tests/Files/Aspects/BeforeAspect.php
+++ b/tests/Files/Aspects/BeforeAspect.php
@@ -16,9 +16,8 @@ class BeforeAspect
/** @var mixed[]|false */
public $modifyArgs = false;
- /**
- * @Aop\Annotations\Before("method(Tests\Files\Aspects\CommonService->magic)")
- */
+ #[Aop\Attributes\Before('method(Tests\Files\Aspects\CommonService->magic)')]
+
public function log(Aop\JoinPoint\BeforeMethod $before): void
{
$this->calls[] = $before;
diff --git a/tests/Files/Aspects/ConditionalAfterReturningAspect.php b/tests/Files/Aspects/ConditionalAfterReturningAspect.php
index eddc4f8..22b943d 100644
--- a/tests/Files/Aspects/ConditionalAfterReturningAspect.php
+++ b/tests/Files/Aspects/ConditionalAfterReturningAspect.php
@@ -16,9 +16,8 @@ class ConditionalAfterReturningAspect
/** @var mixed|false */
public $modifyReturn = false;
- /**
- * @Aop\Annotations\AfterReturning("method(Tests\Files\Aspects\CommonService->magic) && evaluate(this.return == 2)")
- */
+ #[Aop\Attributes\AfterReturning('method(Tests\Files\Aspects\CommonService->magic) && evaluate(this.return == 2)')]
+
public function log(Aop\JoinPoint\AfterReturning $after): void
{
$this->calls[] = $after;
diff --git a/tests/Files/Aspects/ConditionalAroundAspect.php b/tests/Files/Aspects/ConditionalAroundAspect.php
index 059bb32..a72e173 100644
--- a/tests/Files/Aspects/ConditionalAroundAspect.php
+++ b/tests/Files/Aspects/ConditionalAroundAspect.php
@@ -20,9 +20,10 @@ class ConditionalAroundAspect
public $modifyReturn = false;
/**
- * @Aop\Annotations\Around("method(Tests\Files\Aspects\CommonService->magic($argument == 1))")
* @return mixed
*/
+ #[Aop\Attributes\Around('method(Tests\Files\Aspects\CommonService->magic($argument == 1))')]
+
public function log(Aop\JoinPoint\AroundMethod $around)
{
$this->calls[] = $around;
diff --git a/tests/Files/Aspects/ConditionalBeforeAspect.php b/tests/Files/Aspects/ConditionalBeforeAspect.php
index 1368c82..2008c98 100644
--- a/tests/Files/Aspects/ConditionalBeforeAspect.php
+++ b/tests/Files/Aspects/ConditionalBeforeAspect.php
@@ -16,9 +16,8 @@ class ConditionalBeforeAspect
/** @var mixed[]|false */
public $modifyArgs = false;
- /**
- * @Aop\Annotations\Before("method(Tests\Files\Aspects\CommonService->magic($argument == 1))")
- */
+ #[Aop\Attributes\Before('method(Tests\Files\Aspects\CommonService->magic($argument == 1))')]
+
public function log(Aop\JoinPoint\BeforeMethod $before): void
{
$this->calls[] = $before;
diff --git a/tests/Files/Aspects/ConstructorBeforeAspect.php b/tests/Files/Aspects/ConstructorBeforeAspect.php
index e395ec1..3575d94 100644
--- a/tests/Files/Aspects/ConstructorBeforeAspect.php
+++ b/tests/Files/Aspects/ConstructorBeforeAspect.php
@@ -13,9 +13,8 @@ class ConstructorBeforeAspect
/** @var array|Aop\JoinPoint\BeforeMethod[] */
public array $calls = [];
- /**
- * @Aop\Annotations\Before("method(Tests\Files\Aspects\CommonService->__construct)")
- */
+ #[Aop\Attributes\Before('method(Tests\Files\Aspects\CommonService->__construct)')]
+
public function log(Aop\JoinPoint\BeforeMethod $before): void
{
$this->calls[] = $before;
diff --git a/tests/Files/Pointcut/Legie.php b/tests/Files/Pointcut/Legie.php
index 1661853..9abfb7b 100644
--- a/tests/Files/Pointcut/Legie.php
+++ b/tests/Files/Pointcut/Legie.php
@@ -5,9 +5,8 @@
class Legie implements Rimmer, Lister, Kryten, Cat
{
- /**
- * @Test()
- */
+ #[Test]
+
public function publicCalculation(): void
{
}
diff --git a/tests/Files/Pointcut/SmegHead.php b/tests/Files/Pointcut/SmegHead.php
index 947338c..6ec0cc4 100644
--- a/tests/Files/Pointcut/SmegHead.php
+++ b/tests/Files/Pointcut/SmegHead.php
@@ -2,9 +2,7 @@
namespace Tests\Files\Pointcut;
-/**
- * @Test()
- */
+#[Test]
class SmegHead
{
diff --git a/tests/Files/Pointcut/Test.php b/tests/Files/Pointcut/Test.php
index cc4ca31..66058fd 100644
--- a/tests/Files/Pointcut/Test.php
+++ b/tests/Files/Pointcut/Test.php
@@ -2,13 +2,14 @@
namespace Tests\Files\Pointcut;
-use Doctrine\Common\Annotations\Annotation;
+use Attribute;
+use Contributte\Aop\Attributes\BaseAttribute;
/**
- * @Annotation
* @Target({"CLASS", "METHOD"})
*/
-class Test extends Annotation
+#[Attribute]
+class Test extends BaseAttribute
{
}
diff --git a/tests/nette-reset.neon b/tests/nette-reset.neon
index 8815085..a1a42e4 100644
--- a/tests/nette-reset.neon
+++ b/tests/nette-reset.neon
@@ -4,8 +4,6 @@ php:
services:
cacheStorage:
class: Nette\Caching\Storages\MemoryStorage
-annotations:
- debug: false
http:
frames: null