diff --git a/README.md b/README.md index cff94f5..fa88bad 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Next up you need to create a configuration class `MyConfiguration` and document ```php =7.1" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.22-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "support": { + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.22.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-01-07T16:49:33+00:00" + }, { "name": "webimpress/safe-writer", "version": "2.1.0", @@ -652,6 +581,64 @@ } ], "time": "2020-08-25T07:21:11+00:00" + }, + { + "name": "webmozart/assert", + "version": "1.10.0", + "source": { + "type": "git", + "url": "https://github.com/webmozarts/assert.git", + "reference": "6964c76c7804814a842473e0c8fd15bab0f18e25" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozarts/assert/zipball/6964c76c7804814a842473e0c8fd15bab0f18e25", + "reference": "6964c76c7804814a842473e0c8fd15bab0f18e25", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0", + "symfony/polyfill-ctype": "^1.8" + }, + "conflict": { + "phpstan/phpstan": "<0.12.20", + "vimeo/psalm": "<4.6.1 || 4.6.2" + }, + "require-dev": { + "phpunit/phpunit": "^8.5.13" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.10-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "support": { + "issues": "https://github.com/webmozarts/assert/issues", + "source": "https://github.com/webmozarts/assert/tree/1.10.0" + }, + "time": "2021-03-09T10:59:23+00:00" } ], "packages-dev": [ @@ -3347,85 +3334,6 @@ }, "time": "2020-10-23T02:01:07+00:00" }, - { - "name": "symfony/polyfill-ctype", - "version": "v1.22.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "c6c942b1ac76c82448322025e084cadc56048b4e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/c6c942b1ac76c82448322025e084cadc56048b4e", - "reference": "c6c942b1ac76c82448322025e084cadc56048b4e", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "suggest": { - "ext-ctype": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.22-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for ctype functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "ctype", - "polyfill", - "portable" - ], - "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.22.1" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-01-07T16:49:33+00:00" - }, { "name": "theseer/tokenizer", "version": "1.2.0", @@ -3475,64 +3383,6 @@ } ], "time": "2020-07-12T23:59:07+00:00" - }, - { - "name": "webmozart/assert", - "version": "1.10.0", - "source": { - "type": "git", - "url": "https://github.com/webmozarts/assert.git", - "reference": "6964c76c7804814a842473e0c8fd15bab0f18e25" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/webmozarts/assert/zipball/6964c76c7804814a842473e0c8fd15bab0f18e25", - "reference": "6964c76c7804814a842473e0c8fd15bab0f18e25", - "shasum": "" - }, - "require": { - "php": "^7.2 || ^8.0", - "symfony/polyfill-ctype": "^1.8" - }, - "conflict": { - "phpstan/phpstan": "<0.12.20", - "vimeo/psalm": "<4.6.1 || 4.6.2" - }, - "require-dev": { - "phpunit/phpunit": "^8.5.13" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.10-dev" - } - }, - "autoload": { - "psr-4": { - "Webmozart\\Assert\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Bernhard Schussek", - "email": "bschussek@gmail.com" - } - ], - "description": "Assertions to validate method input/output with nice error messages.", - "keywords": [ - "assert", - "check", - "validate" - ], - "support": { - "issues": "https://github.com/webmozarts/assert/issues", - "source": "https://github.com/webmozarts/assert/tree/1.10.0" - }, - "time": "2021-03-09T10:59:23+00:00" } ], "aliases": [], @@ -3546,5 +3396,5 @@ "php": "^8.0.0" }, "platform-dev": [], - "plugin-api-version": "2.0.0" + "plugin-api-version": "2.1.0" } diff --git a/docs/advanced/bean-post-processor.md b/docs/advanced/bean-post-processor.md index 369792c..b4169e6 100644 --- a/docs/advanced/bean-post-processor.md +++ b/docs/advanced/bean-post-processor.md @@ -30,8 +30,8 @@ To register the `SampleServiceBeanPostProcessor` with Disco create a method in y ```php > $attributes - * @throws AnnotationException - */ - public function __construct(array $attributes = []) - { - $this->type = false; - - if (isset($attributes['value']['type'])) { - $this->type = AnnotationAttributeParser::parseBooleanValue($attributes['value']['type']); - } - - if (isset($attributes['value']['name'])) { - if ($this->type) { - throw new AnnotationException('Type alias should not have a name!'); - } - - $this->name = $attributes['value']['name']; - } - - if (!$this->type && (!is_string($this->name) || $this->name === '')) { - throw new AnnotationException('Alias should either be a named alias or a type alias!'); - } - } - - public function getName(): ?string - { - return $this->name; - } - - public function isTypeAlias(): bool - { - return $this->type; - } -} diff --git a/src/bitExpert/Disco/Annotations/AnnotationAttributeParser.php b/src/bitExpert/Disco/Annotations/AnnotationAttributeParser.php deleted file mode 100644 index e9b77cc..0000000 --- a/src/bitExpert/Disco/Annotations/AnnotationAttributeParser.php +++ /dev/null @@ -1,41 +0,0 @@ -"), - * @Attribute("parameters", type = "array<\bitExpert\Disco\Annotations\Parameter>") - * }) - */ -final class Bean extends ParameterAwareAnnotation -{ - const SCOPE_REQUEST = 1; - const SCOPE_SESSION = 2; - /** - * @var int - */ - protected $scope; - /** - * @var bool - */ - protected $singleton; - /** - * @var bool - */ - protected $lazy; - /** - * @var Alias[] - */ - protected $aliases; - - /** - * Creates a new {@link \bitExpert\Disco\Annotations\Bean}. - * - * @param array> $attributes - */ - public function __construct(array $attributes = []) - { - parent::__construct(); - - // initialize default values - $this->scope = self::SCOPE_REQUEST; - $this->singleton = true; - $this->lazy = false; - $this->aliases = []; - - if (isset($attributes['value'])) { - if (isset($attributes['value']['scope']) && \strtolower($attributes['value']['scope']) === 'session') { - $this->scope = self::SCOPE_SESSION; - } - - if (isset($attributes['value']['singleton'])) { - $this->singleton = AnnotationAttributeParser::parseBooleanValue($attributes['value']['singleton']); - } - - if (isset($attributes['value']['lazy'])) { - $this->lazy = AnnotationAttributeParser::parseBooleanValue($attributes['value']['lazy']); - } - - if (isset($attributes['value']['aliases']) && \is_array($attributes['value']['aliases'])) { - $this->setAliases(...$attributes['value']['aliases']); - } - - if (isset($attributes['value']['parameters']) && \is_array($attributes['value']['parameters'])) { - $this->setParameters(...$attributes['value']['parameters']); - } - } - } - - /** - * Helper methd to ensure that the passed aliases are of {@link \bitExpert\Disco\Annotations\Alias} type. - * - * @param Alias ...$aliases - */ - private function setAliases(Alias ...$aliases): void - { - $this->aliases = $aliases; - } - - /** - * Returns true if the current scope if of type Scope::REQUEST. - * - * @return bool - */ - public function isRequest(): bool - { - return $this->scope === self::SCOPE_REQUEST; - } - - /** - * Returns true if the current scope if of type Scope::SESSION. - * - * @return bool - */ - public function isSession(): bool - { - return $this->scope === self::SCOPE_SESSION; - } - - /** - * Returns true if the Bean should be a singleton instance. - * - * @return bool - */ - public function isSingleton(): bool - { - return $this->singleton; - } - - /** - * Returns true if the Bean should be a lazily instantiated. - * - * @return bool - */ - public function isLazy(): bool - { - return $this->lazy; - } - - /** - * Returns the list of aliases for the bean instance. Returns an empty array when no alias was set. - * - * @return Alias[] - */ - public function getAliases(): array - { - return $this->aliases; - } -} diff --git a/src/bitExpert/Disco/Annotations/BeanPostProcessor.php b/src/bitExpert/Disco/Annotations/BeanPostProcessor.php deleted file mode 100644 index d22f3db..0000000 --- a/src/bitExpert/Disco/Annotations/BeanPostProcessor.php +++ /dev/null @@ -1,41 +0,0 @@ -") - * }) - */ -final class BeanPostProcessor extends ParameterAwareAnnotation -{ - /** - * Creates a new {@link \bitExpert\Disco\Annotations\BeanPostProcessor}. - * - * @param array> $attributes - */ - public function __construct(array $attributes = []) - { - parent::__construct(); - - if (isset($attributes['value']['parameters']) && \is_array($attributes['value']['parameters'])) { - $this->setParameters(...$attributes['value']['parameters']); - } - } -} diff --git a/src/bitExpert/Disco/Annotations/Parameter.php b/src/bitExpert/Disco/Annotations/Parameter.php deleted file mode 100644 index 60b8da7..0000000 --- a/src/bitExpert/Disco/Annotations/Parameter.php +++ /dev/null @@ -1,102 +0,0 @@ -> $attributes - * @throws AnnotationException - */ - public function __construct(array $attributes = []) - { - $this->required = true; - $this->name = ''; - - if (isset($attributes['value'])) { - if (isset($attributes['value']['name'])) { - $this->name = $attributes['value']['name']; - } - - if (isset($attributes['value']['default'])) { - $this->defaultValue = $attributes['value']['default']; - } - - if (isset($attributes['value']['required'])) { - $this->required = AnnotationAttributeParser::parseBooleanValue($attributes['value']['required']); - } - } - - if ($this->name === '') { - throw new AnnotationException('name attribute missing!'); - } - } - - /** - * Returns the name of the configuration value to use. - * - * @return string - */ - public function getName(): string - { - return $this->name; - } - - /** - * Returns the default value to use in case the configuration value is not defined. - * - * @return mixed - */ - public function getDefaultValue(): mixed - { - return $this->defaultValue; - } - - /** - * Returns true if the parameter is required, false for an optional parameter. - * - * @return bool - */ - public function isRequired(): bool - { - return $this->required; - } -} diff --git a/src/bitExpert/Disco/Annotations/ParameterAwareAnnotation.php b/src/bitExpert/Disco/Annotations/ParameterAwareAnnotation.php deleted file mode 100644 index b30007d..0000000 --- a/src/bitExpert/Disco/Annotations/ParameterAwareAnnotation.php +++ /dev/null @@ -1,53 +0,0 @@ -parameters = []; - } - - /** - * Returns the list of parameters for the bean post processor instance. Returns an empty array when no parameters - * were set. - * - * @return Parameter[] - */ - public function getParameters(): array - { - return $this->parameters; - } - - /** - * Helper methd to ensure that the passed parameters are of {@link \bitExpert\Disco\Annotations\Parameter} type. - * - * @param Parameter[] ...$parameters - */ - protected function setParameters(Parameter ...$parameters): void - { - $this->parameters = $parameters; - } -} diff --git a/src/bitExpert/Disco/Attributes/Alias.php b/src/bitExpert/Disco/Attributes/Alias.php new file mode 100644 index 0000000..3c43133 --- /dev/null +++ b/src/bitExpert/Disco/Attributes/Alias.php @@ -0,0 +1,47 @@ +name = $name; + } + + public function getName(): string + { + return $this->name; + } +} diff --git a/src/bitExpert/Disco/Attributes/Bean.php b/src/bitExpert/Disco/Attributes/Bean.php new file mode 100644 index 0000000..242ae4e --- /dev/null +++ b/src/bitExpert/Disco/Attributes/Bean.php @@ -0,0 +1,86 @@ +singleton = $singleton; + $this->lazy = $lazy; + $this->scope = $scope; + } + + /** + * Returns true if the current scope if of type Scope::REQUEST. + * + * @return bool + */ + public function isRequest(): bool + { + return $this->scope === self::SCOPE_REQUEST; + } + + /** + * Returns true if the current scope if of type Scope::SESSION. + * + * @return bool + */ + public function isSession(): bool + { + return $this->scope === self::SCOPE_SESSION; + } + + /** + * Returns true if the Bean should be a singleton instance. + * + * @return bool + */ + public function isSingleton(): bool + { + return $this->singleton; + } + + /** + * Returns true if the Bean should be a lazily instantiated. + * + * @return bool + */ + public function isLazy(): bool + { + return $this->lazy; + } +} diff --git a/src/bitExpert/Disco/Attributes/BeanPostProcessor.php b/src/bitExpert/Disco/Attributes/BeanPostProcessor.php new file mode 100644 index 0000000..5609cdf --- /dev/null +++ b/src/bitExpert/Disco/Attributes/BeanPostProcessor.php @@ -0,0 +1,23 @@ +name = $name; + $this->key = $key; + $this->defaultValue = $default; + $this->required = $required; + } + + /** + * Return the name of the parameter + * + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * Returns the key of the configuration value to use. + * + * @return string + */ + public function getKey(): string + { + return $this->key; + } + + /** + * Returns the default value to use in case the configuration value is not defined. + * + * @return mixed + */ + public function getDefaultValue(): mixed + { + return $this->defaultValue; + } + + /** + * Returns true if the parameter is required, false for an optional parameter. + * + * @return bool + */ + public function isRequired(): bool + { + return $this->required; + } +} diff --git a/src/bitExpert/Disco/Attributes/ReturnTypeAlias.php b/src/bitExpert/Disco/Attributes/ReturnTypeAlias.php new file mode 100644 index 0000000..bf642f0 --- /dev/null +++ b/src/bitExpert/Disco/Attributes/ReturnTypeAlias.php @@ -0,0 +1,25 @@ +getClassAnnotation($originalClass, Configuration::class); - } catch (Exception $e) { - throw new InvalidProxiedClassException($e->getMessage(), $e->getCode(), $e); - } + $configurationAttribute = $originalClass->getAttributes(Configuration::class)[0] ?? null; - if (null === $annotation) { + if (null === $configurationAttribute) { throw new InvalidProxiedClassException( sprintf( - '"%s" seems not to be a valid configuration class. @Configuration annotation missing!', + '"%s" seems not to be a valid configuration class. #[Configuration] attribute missing!', $originalClass->name ) ); @@ -112,22 +95,26 @@ public function generate(ReflectionClass $originalClass, ClassGenerator $classGe $localAliases = []; $methods = $originalClass->getMethods(ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED); foreach ($methods as $method) { - $methodReflection = new MethodReflection( + $reflectionMethod = new MethodReflection( $method->class, $method->name ); - /** @var \bitExpert\Disco\Annotations\Bean|null $beanAnnotation */ - $beanAnnotation = $reader->getMethodAnnotation($method, Bean::class); - if (null === $beanAnnotation) { - /** @var \bitExpert\Disco\Annotations\BeanPostProcessor|null $beanAnnotation */ - $beanAnnotation = $reader->getMethodAnnotation($method, BeanPostProcessor::class); - if ($beanAnnotation instanceof BeanPostProcessor) { + /** @var Bean|null $beanAttribute */ + $beanAttribute = ($reflectionMethod->getAttributes(Bean::class)[0] ?? null)?->newInstance(); + /** @var Parameter[] $parameterAttributes */ + $parameterAttributes = \array_map( + fn($attributeRefl) => $attributeRefl->newInstance(), + $reflectionMethod->getAttributes(Parameter::class) + ); + if (null === $beanAttribute) { + $postProcessorAttribute = $reflectionMethod->getAttributes(BeanPostProcessor::class)[0] ?? null; + if (null !== $postProcessorAttribute) { $postProcessorMethods[] = $method->name; $proxyMethod = BeanPostProcessorMethod::generateMethod( - $methodReflection, - $beanAnnotation, + $reflectionMethod, + $parameterAttributes, $getParameterMethod ); $classGenerator->addMethodFromGenerator($proxyMethod); @@ -138,32 +125,69 @@ public function generate(ReflectionClass $originalClass, ClassGenerator $classGe continue; } - // every method needs either @Bean or @PostPostprocessor annotation + // every method needs either #[Bean] or #[PostPostprocessor] attribute throw new InvalidProxiedClassException( sprintf( - 'Method "%s" on "%s" is missing the @Bean annotation!', + 'Method "%s" on "%s" is missing the #[Bean] (or #[BeanPostProcessor]) attribute ' + . 'or its scope must be protected!', $method->name, $originalClass->name ) ); } - foreach ($beanAnnotation->getAliases() as $beanAlias) { - $alias = $beanAlias->isTypeAlias() ? (string) $method->getReturnType() : $beanAlias->getName(); + $beanAliases = []; + + /** @var \bitExpert\Disco\Attributes\ReturnTypeAlias $returnTypeAlias */ + $returnTypeAlias = ($reflectionMethod->getAttributes(ReturnTypeAlias::class)[0] ?? null) + ?->newInstance(); + if (null !== $returnTypeAlias) { + $returnTypeRefl = $method->getReturnType(); + + if ($returnTypeRefl instanceof ReflectionUnionType) { + throw new InvalidProxiedClassException( + sprintf( + 'Method "%s" on "%s" uses the unsupported union type.', + $method->name, + $originalClass->name + ) + ); + } + + if (null === $returnTypeRefl || $returnTypeRefl->allowsNull() || $returnTypeRefl->isBuiltin()) { + throw new InvalidProxiedClassException( + sprintf( + 'Cannot use #[ReturnTypeAlias] on method "%s" on "%s" because it\'s returning a ' + . 'builtin type ("%s").', + $method->name, + $originalClass->name, + $returnTypeRefl === null || $returnTypeRefl->allowsNull() + ? 'null' + : $returnTypeRefl->getName() + ) + ); + } + + $beanAliases[] = $returnTypeRefl->getName(); + } + + $beanAliases = [...$beanAliases, ...\array_map( + fn($attr) => $attr->newInstance()->getName(), + $reflectionMethod->getAttributes(Alias::class) + )]; - $hasAlias = ''; + foreach ($beanAliases as $beanAlias) { if ($method->getDeclaringClass()->name === $originalClass->name) { - $hasAlias = $localAliases[$alias] ?? ''; + $hasAlias = $localAliases[$beanAlias] ?? ''; } else { - $hasAlias= $parentAliases[$alias] ?? ''; + $hasAlias = $parentAliases[$beanAlias] ?? ''; } if ($hasAlias !== '') { throw new InvalidProxiedClassException( sprintf( - 'Alias "%s" of method "%s" on "%s" is already used by method "%s" of another Bean!' - . ' Did you use a type alias twice?', - $alias, + 'Alias "%s" of method "%s" on "%s" is already used by method "%s" of another Bean!', + $beanAlias, $method->name, $originalClass->name, $hasAlias @@ -172,15 +196,16 @@ public function generate(ReflectionClass $originalClass, ClassGenerator $classGe } if ($method->getDeclaringClass()->name === $originalClass->name) { - $localAliases[$alias] = $method->name; + $localAliases[$beanAlias] = $method->name; } else { - $parentAliases[$alias] = $method->name; + $parentAliases[$beanAlias] = $method->name; } } $proxyMethod = BeanMethod::generateMethod( - $methodReflection, - $beanAnnotation, + $reflectionMethod, + $beanAttribute, + $parameterAttributes, $method->getReturnType(), $forceLazyInitProperty, $sessionBeansProperty, diff --git a/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/BeanMethod.php b/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/BeanMethod.php index 683d2c8..b924d69 100644 --- a/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/BeanMethod.php +++ b/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/BeanMethod.php @@ -12,7 +12,8 @@ namespace bitExpert\Disco\Proxy\Configuration\MethodGenerator; -use bitExpert\Disco\Annotations\Bean; +use bitExpert\Disco\Attributes\Bean; +use bitExpert\Disco\Attributes\Parameter; use bitExpert\Disco\BeanException; use bitExpert\Disco\InitializedBean; use bitExpert\Disco\Proxy\Configuration\PropertyGenerator\BeanFactoryConfigurationProperty; @@ -22,7 +23,7 @@ use bitExpert\Disco\Proxy\LazyBean\LazyBeanFactory; use ProxyManager\Exception\InvalidProxiedClassException; use ProxyManager\Proxy\LazyLoadingInterface; -use ReflectionType; +use ReflectionNamedType; use Laminas\Code\Generator\MethodGenerator; use Laminas\Code\Generator\ParameterGenerator; use Laminas\Code\Reflection\MethodReflection; @@ -39,8 +40,9 @@ class BeanMethod extends ParameterAwareMethodGenerator * Creates a new {@link \bitExpert\Disco\Proxy\Configuration\MethodGenerator\BeanMethod}. * * @param MethodReflection $originalMethod - * @param Bean $beanMetadata - * @param ReflectionType|null $beanType + * @param \bitExpert\Disco\Attributes\Bean $beanMetadata + * @param \bitExpert\Disco\Attributes\Parameter[] $parameters + * @param ReflectionNamedType|null $beanTypeName * @param ForceLazyInitProperty $forceLazyInitProperty * @param SessionBeansProperty $sessionBeansProperty * @param BeanPostProcessorsProperty $postProcessorsProperty @@ -52,15 +54,16 @@ class BeanMethod extends ParameterAwareMethodGenerator * @throws \ProxyManager\Exception\InvalidProxiedClassException */ public static function generateMethod( - MethodReflection $originalMethod, - Bean $beanMetadata, - ?ReflectionType $beanType, - ForceLazyInitProperty $forceLazyInitProperty, - SessionBeansProperty $sessionBeansProperty, - BeanPostProcessorsProperty $postProcessorsProperty, + MethodReflection $originalMethod, + Bean $beanMetadata, + array $parameters, + ?ReflectionNamedType $beanType, + ForceLazyInitProperty $forceLazyInitProperty, + SessionBeansProperty $sessionBeansProperty, + BeanPostProcessorsProperty $postProcessorsProperty, BeanFactoryConfigurationProperty $beanFactoryConfigurationProperty, - GetParameter $parameterValuesMethod, - WrapBeanAsLazy $wrapBeanAsLazy + GetParameter $parameterValuesMethod, + WrapBeanAsLazy $wrapBeanAsLazy ): MethodGenerator { if (null === $beanType) { throw new InvalidProxiedClassException( @@ -71,22 +74,22 @@ public static function generateMethod( ) ); } - $beanType = (string) $beanType; + $beanTypeName = $beanType->getName(); $method = static::fromReflection($originalMethod); - $methodParams = static::convertMethodParamsToString($beanMetadata->getParameters(), $parameterValuesMethod); + $methodParams = static::convertMethodParamsToString($parameters, $parameterValuesMethod); $beanId = $originalMethod->name; $body = ''; - if (in_array($beanType, ['array', 'callable', 'bool', 'float', 'int', 'string'], true)) { + if ($beanType->isBuiltin()) { // return type is a primitive, simply call parent method and return immediately $body .= 'return parent::' . $beanId . '(' . $methodParams . ');' . PHP_EOL; - } elseif (class_exists($beanType) || interface_exists($beanType)) { + } elseif (class_exists($beanTypeName) || interface_exists($beanTypeName)) { if ($beanMetadata->isLazy()) { $body = static::generateLazyBeanCode( '', $beanId, - $beanType, + $beanTypeName, $beanMetadata, $methodParams, $forceLazyInitProperty, @@ -98,7 +101,7 @@ public static function generateMethod( $body = static::generateNonLazyBeanCode( '', $beanId, - $beanType, + $beanTypeName, $beanMetadata, $methodParams, $forceLazyInitProperty, @@ -154,7 +157,7 @@ public static function fromReflection(MethodReflection $reflectionMethod): Metho * @param string $padding * @param string $beanId * @param string $beanType - * @param Bean $beanMetadata + * @param \bitExpert\Disco\Attributes\Bean $beanMetadata * @param string $methodParams * @param ForceLazyInitProperty $forceLazyInitProperty * @param SessionBeansProperty $sessionBeansProperty @@ -279,7 +282,7 @@ protected static function generateBeanCreationCode( * @param string $padding * @param string $beanId * @param string $beanType - * @param Bean $beanMetadata + * @param \bitExpert\Disco\Attributes\Bean $beanMetadata * @param string $methodParams * @param ForceLazyInitProperty $forceLazyInitProperty * @param SessionBeansProperty $sessionBeansProperty diff --git a/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/BeanPostProcessorMethod.php b/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/BeanPostProcessorMethod.php index ed49b09..8e58f9e 100644 --- a/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/BeanPostProcessorMethod.php +++ b/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/BeanPostProcessorMethod.php @@ -12,7 +12,8 @@ namespace bitExpert\Disco\Proxy\Configuration\MethodGenerator; -use bitExpert\Disco\Annotations\BeanPostProcessor; +use bitExpert\Disco\Attributes\BeanPostProcessor; +use bitExpert\Disco\Attributes\Parameter; use Laminas\Code\Generator\MethodGenerator; use Laminas\Code\Reflection\MethodReflection; @@ -22,20 +23,20 @@ class BeanPostProcessorMethod extends ParameterAwareMethodGenerator * Creates a new {@link \bitExpert\Disco\Proxy\Configuration\MethodGenerator\BeanPostProcessorMethod}. * * @param MethodReflection $originalMethod - * @param BeanPostProcessor $beanPostProcessorMetadata + * @param \bitExpert\Disco\Attributes\Parameter[] $beanPostProcessorParameters * @param GetParameter $parameterValuesMethod * @return MethodGenerator * @throws \Laminas\Code\Generator\Exception\InvalidArgumentException */ public static function generateMethod( MethodReflection $originalMethod, - BeanPostProcessor $beanPostProcessorMetadata, + array $beanPostProcessorParameters, GetParameter $parameterValuesMethod ): MethodGenerator { $method = static::fromReflection($originalMethod); $methodParams = static::convertMethodParamsToString( - $beanPostProcessorMetadata->getParameters(), + $beanPostProcessorParameters, $parameterValuesMethod ); $beanId = $originalMethod->name; diff --git a/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/Constructor.php b/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/Constructor.php index b47c820..2fd5ec8 100644 --- a/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/Constructor.php +++ b/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/Constructor.php @@ -18,7 +18,6 @@ use bitExpert\Disco\Proxy\Configuration\PropertyGenerator\ParameterValuesProperty; use bitExpert\Disco\Proxy\Configuration\PropertyGenerator\SessionBeansProperty; use ProxyManager\Generator\MethodGenerator; -use ReflectionClass; use Laminas\Code\Generator\ParameterGenerator; /** diff --git a/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/GetAlias.php b/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/GetAlias.php index ff8b992..bc025ab 100644 --- a/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/GetAlias.php +++ b/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/GetAlias.php @@ -15,7 +15,6 @@ use bitExpert\Disco\BeanNotFoundException; use bitExpert\Disco\Proxy\Configuration\PropertyGenerator\AliasesProperty; use ProxyManager\Generator\MethodGenerator; -use ReflectionClass; use Laminas\Code\Generator\Exception\InvalidArgumentException; use Laminas\Code\Generator\ParameterGenerator; diff --git a/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/GetParameter.php b/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/GetParameter.php index 271362a..c665d69 100644 --- a/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/GetParameter.php +++ b/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/GetParameter.php @@ -15,7 +15,6 @@ use bitExpert\Disco\Proxy\Configuration\PropertyGenerator\ParameterValuesProperty; use ProxyManager\Generator\MethodGenerator; use ProxyManager\Generator\Util\UniqueIdentifierGenerator; -use ReflectionClass; use Laminas\Code\Generator\Exception\InvalidArgumentException; use Laminas\Code\Generator\ParameterGenerator; diff --git a/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/HasAlias.php b/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/HasAlias.php index eb54b64..05ba987 100644 --- a/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/HasAlias.php +++ b/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/HasAlias.php @@ -14,7 +14,6 @@ use bitExpert\Disco\Proxy\Configuration\PropertyGenerator\AliasesProperty; use ProxyManager\Generator\MethodGenerator; -use ReflectionClass; use Laminas\Code\Generator\Exception\InvalidArgumentException; use Laminas\Code\Generator\ParameterGenerator; diff --git a/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/ParameterAwareMethodGenerator.php b/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/ParameterAwareMethodGenerator.php index b8c73c6..8f3b119 100644 --- a/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/ParameterAwareMethodGenerator.php +++ b/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/ParameterAwareMethodGenerator.php @@ -12,7 +12,7 @@ namespace bitExpert\Disco\Proxy\Configuration\MethodGenerator; -use bitExpert\Disco\Annotations\Parameter; +use bitExpert\Disco\Attributes\Parameter; use Laminas\Code\Generator\MethodGenerator; /** @@ -53,7 +53,7 @@ protected static function convertMethodParamsToString( $template = ($defaultValue === '') ? '$this->%s("%s", %s)' : '$this->%s("%s", %s, %s)'; $required = $methodParameter->isRequired() ? 'true' : 'false'; $methodName = $parameterValuesMethod->getName(); - $parameters[] = \sprintf($template, $methodName, $methodParameter->getName(), $required, $defaultValue); + $parameters[] = \sprintf($template, $methodName, $methodParameter->getKey(), $required, $defaultValue); } return \implode(', ', $parameters); diff --git a/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/WrapBeanAsLazy.php b/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/WrapBeanAsLazy.php index 878150b..c826071 100644 --- a/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/WrapBeanAsLazy.php +++ b/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/WrapBeanAsLazy.php @@ -15,7 +15,6 @@ use bitExpert\Disco\Proxy\Configuration\PropertyGenerator\BeanFactoryConfigurationProperty; use ProxyManager\Generator\MethodGenerator; use ProxyManager\Generator\Util\UniqueIdentifierGenerator; -use ReflectionClass; use Laminas\Code\Generator\ParameterGenerator; /** diff --git a/tests/bitExpert/Disco/Annotations/AliasUnitTest.php b/tests/bitExpert/Disco/Annotations/AliasUnitTest.php index 73ccb69..412659a 100644 --- a/tests/bitExpert/Disco/Annotations/AliasUnitTest.php +++ b/tests/bitExpert/Disco/Annotations/AliasUnitTest.php @@ -12,11 +12,12 @@ namespace bitExpert\Disco\Annotations; -use Doctrine\Common\Annotations\AnnotationException; +use bitExpert\Disco\Attributes\Alias; use PHPUnit\Framework\TestCase; +use Webmozart\Assert\InvalidArgumentException; /** - * Unit tests for {@link \bitExpert\Disco\Annotations\Alias}. + * Unit tests for {@link \bitExpert\Disco\Attributes\Alias}. */ class AliasUnitTest extends TestCase { @@ -25,70 +26,18 @@ class AliasUnitTest extends TestCase */ public function aliasCanBeNamedAlias(): void { - $namedAlias = new Alias(['value' => ['name' => 'someAliasName']]); + $namedAlias = new Alias(name: 'someAliasName'); self::assertSame('someAliasName', $namedAlias->getName()); - self::assertFalse($namedAlias->isTypeAlias()); } /** * @test */ - public function aliasCannotBeNamedAliasAndTypeAlias(): void + public function aliasNameCannotBeEmpty(): void { - $this->expectException(AnnotationException::class); - $this->expectExceptionMessage('Type alias should not have a name!'); + $this->expectException(InvalidArgumentException::class); - new Alias(['value' => ['name' => 'someAliasName', 'type' => true]]); - } - - /** - * @test - */ - public function aliasCanBeTypeAlias(): void - { - $typeAlias = new Alias(['value' => ['type' => true]]); - - self::assertTrue($typeAlias->isTypeAlias()); - self::assertNull($typeAlias->getName()); - } - - /** - * @test - */ - public function aliasShouldBeNamedOrTypeAlias(): void - { - $this->expectException(AnnotationException::class); - $this->expectExceptionMessage('Alias should either be a named alias or a type alias!'); - - new Alias(); - } - - /** - * @test - * @dataProvider invalidNameProvider - * @param mixed $name - */ - public function aliasNameCannotBeEmpty(mixed $name): void - { - $this->expectException(AnnotationException::class); - $this->expectExceptionMessage('Alias should either be a named alias or a type alias!'); - - new Alias(['value' => ['name' => $name, 'type' => false]]); - } - - /** - * @return array - */ - public function invalidNameProvider(): array - { - return [ - [''], - [0], - [0.0], - [false], - [null], - [[]], - ]; + new Alias(name: ''); } } diff --git a/tests/bitExpert/Disco/Annotations/AnnotationAttributeParserUnitTest.php b/tests/bitExpert/Disco/Annotations/AnnotationAttributeParserUnitTest.php deleted file mode 100644 index 4f9b14b..0000000 --- a/tests/bitExpert/Disco/Annotations/AnnotationAttributeParserUnitTest.php +++ /dev/null @@ -1,54 +0,0 @@ - - */ - public function requireDataProvider(): array - { - $callable = function (): void { - }; - - return [ - [true, true], - [false, false], - ['true', true], - ['false', false], - ['anything else', false], - [1, true], - [0, false], - [new \stdClass(), false], - [[], false], - [$callable, false] - ]; - } -} diff --git a/tests/bitExpert/Disco/Annotations/BeanPostProcessorUnitTest.php b/tests/bitExpert/Disco/Annotations/BeanPostProcessorUnitTest.php deleted file mode 100644 index c65ae3a..0000000 --- a/tests/bitExpert/Disco/Annotations/BeanPostProcessorUnitTest.php +++ /dev/null @@ -1,64 +0,0 @@ - [ - 'parameters' => [ - new Parameter(['value' => ['name' => 'parameterName']]), - new Parameter(['value' => ['name' => 'yetAnotherParameter']]) - ] - ] - ]); - - self::assertEquals( - array_map( - function (Parameter $parameter): string { - return $parameter->getName(); - }, - $bean->getParameters() - ), - ['parameterName', 'yetAnotherParameter'] - ); - } - - /** - * @test - */ - public function throwsExceptionIfParameterTypeDoesNotMatch(): void - { - $this->expectException(TypeError::class); - - $bean = new Bean([ - 'value' => [ - 'parameters' => [ - new SampleService() - ] - ] - ]); - } -} diff --git a/tests/bitExpert/Disco/Annotations/BeanUnitTest.php b/tests/bitExpert/Disco/Annotations/BeanUnitTest.php index ed69c8e..ddab97c 100644 --- a/tests/bitExpert/Disco/Annotations/BeanUnitTest.php +++ b/tests/bitExpert/Disco/Annotations/BeanUnitTest.php @@ -12,12 +12,12 @@ namespace bitExpert\Disco\Annotations; -use bitExpert\Disco\Helper\SampleService; +use bitExpert\Disco\Attributes\Bean; use PHPUnit\Framework\TestCase; -use TypeError; +use Webmozart\Assert\InvalidArgumentException; /** - * Unit tests for {@link \bitExpert\Disco\Annotations\Bean}. + * Unit tests for {@link \bitExpert\Disco\Attributes\Bean}. */ class BeanUnitTest extends TestCase { @@ -32,8 +32,6 @@ public function emptyAttributesArraySetsDefaultValues(): void self::assertFalse($bean->isSession()); self::assertTrue($bean->isSingleton()); self::assertFalse($bean->isLazy()); - self::assertEmpty($bean->getAliases()); - self::assertEmpty($bean->getParameters()); } /** @@ -41,7 +39,7 @@ public function emptyAttributesArraySetsDefaultValues(): void */ public function markingBeanWithSessionScope(): void { - $bean = new Bean(['value' => ['scope' => 'session']]); + $bean = new Bean(scope: Bean::SCOPE_SESSION); self::assertTrue($bean->isSession()); self::assertFalse($bean->isRequest()); @@ -52,7 +50,7 @@ public function markingBeanWithSessionScope(): void */ public function markingBeanWithRequestScope(): void { - $bean = new Bean(['value' => ['scope' => 'request']]); + $bean = new Bean(scope: Bean::SCOPE_REQUEST); self::assertTrue($bean->isRequest()); self::assertFalse($bean->isSession()); @@ -63,7 +61,7 @@ public function markingBeanWithRequestScope(): void */ public function markingBeanAsSingleton(): void { - $bean = new Bean(['value' => ['singleton' => true]]); + $bean = new Bean(singleton: true); self::assertTrue($bean->isSingleton()); } @@ -73,17 +71,7 @@ public function markingBeanAsSingleton(): void */ public function markingBeanAsSingletonWithString(): void { - $bean = new Bean(['value' => ['singleton' => 'true']]); - - self::assertTrue($bean->isSingleton()); - } - - /** - * @test - */ - public function markingBeanAsSingletonWithInt(): void - { - $bean = new Bean(['value' => ['singleton' => 1]]); + $bean = new Bean(singleton: true); self::assertTrue($bean->isSingleton()); } @@ -93,27 +81,7 @@ public function markingBeanAsSingletonWithInt(): void */ public function markingBeanAsNonSingleton(): void { - $bean = new Bean(['value' => ['singleton' => false]]); - - self::assertFalse($bean->isSingleton()); - } - - /** - * @test - */ - public function markingBeanAsNonSingletonWithString(): void - { - $bean = new Bean(['value' => ['singleton' => 'false']]); - - self::assertFalse($bean->isSingleton()); - } - - /** - * @test - */ - public function markingBeanAsNonSingletonWithInt(): void - { - $bean = new Bean(['value' => ['singleton' => 0]]); + $bean = new Bean(singleton: false); self::assertFalse($bean->isSingleton()); } @@ -123,27 +91,7 @@ public function markingBeanAsNonSingletonWithInt(): void */ public function markingBeanAsLazy(): void { - $bean = new Bean(['value' => ['lazy' => true]]); - - self::assertTrue($bean->isLazy()); - } - - /** - * @test - */ - public function markingBeanAsLazyWithString(): void - { - $bean = new Bean(['value' => ['lazy' => 'true']]); - - self::assertTrue($bean->isLazy()); - } - - /** - * @test - */ - public function markingBeanAsLazyWithInt(): void - { - $bean = new Bean(['value' => ['lazy' => 1]]); + $bean = new Bean(lazy: true); self::assertTrue($bean->isLazy()); } @@ -153,17 +101,7 @@ public function markingBeanAsLazyWithInt(): void */ public function markingBeanAsNonLazy(): void { - $bean = new Bean(['value' => ['lazy' => false]]); - - self::assertFalse($bean->isLazy()); - } - - /** - * @test - */ - public function markingBeanAsNonLazyWithString(): void - { - $bean = new Bean(['value' => ['lazy' => 'false']]); + $bean = new Bean(lazy: false); self::assertFalse($bean->isLazy()); } @@ -171,92 +109,10 @@ public function markingBeanAsNonLazyWithString(): void /** * @test */ - public function markingBeanAsNonLazyWithInt(): void - { - $bean = new Bean(['value' => ['lazy' => 0]]); - - self::assertFalse($bean->isLazy()); - } - - /** - * @test - */ - public function configuredAliasesGetReturned(): void - { - $bean = new Bean([ - 'value' => [ - 'aliases' => [ - new Alias(['value' => ['name' => 'someAlias']]), - new Alias(['value' => ['name' => 'yetAnotherAlias']]) - ] - ] - ]); - - self::assertEquals( - array_map( - function (Alias $alias): ?string { - return $alias->getName(); - }, - $bean->getAliases() - ), - ['someAlias', 'yetAnotherAlias'] - ); - } - - /** - * @test - */ - public function throwsExceptionIfAliasTypeDoesNotMatch(): void - { - $this->expectException(TypeError::class); - - $bean = new Bean([ - 'value' => [ - 'aliases' => [ - new SampleService() - ] - ] - ]); - } - - /** - * @test - */ - public function configuredParametersGetReturned(): void - { - $bean = new Bean([ - 'value' => [ - 'parameters' => [ - new Parameter(['value' => ['name' => 'parameterName']]), - new Parameter(['value' => ['name' => 'yetAnotherParameter']]) - ] - ] - ]); - - self::assertEquals( - array_map( - function (Parameter $parameter): string { - return $parameter->getName(); - }, - $bean->getParameters() - ), - ['parameterName', 'yetAnotherParameter'] - ); - } - - /** - * @test - */ - public function throwsExceptionIfParameterTypeDoesNotMatch(): void + public function throwsExceptionIfScopeIsInvalid(): void { - $this->expectException(TypeError::class); + $this->expectException(InvalidArgumentException::class); - $bean = new Bean([ - 'value' => [ - 'parameters' => [ - new SampleService() - ] - ] - ]); + new Bean(scope: 3); } } diff --git a/tests/bitExpert/Disco/Annotations/ParameterUnitTest.php b/tests/bitExpert/Disco/Annotations/ParameterUnitTest.php index d958735..f04c0ed 100644 --- a/tests/bitExpert/Disco/Annotations/ParameterUnitTest.php +++ b/tests/bitExpert/Disco/Annotations/ParameterUnitTest.php @@ -12,32 +12,53 @@ namespace bitExpert\Disco\Annotations; -use Doctrine\Common\Annotations\AnnotationException; +use bitExpert\Disco\Attributes\Parameter; use PHPUnit\Framework\TestCase; +use Webmozart\Assert\InvalidArgumentException; /** - * Unit tests for {@link \bitExpert\Disco\Annotations\Parameter}. + * Unit tests for {@link \bitExpert\Disco\Attributes\Parameter}. */ class ParameterUnitTest extends TestCase { /** * @test */ - public function missingNameWillThrowAnnotationException(): void + public function emptyNameWillThrowAnnotationException(): void { - $this->expectException(AnnotationException::class); + $this->expectException(InvalidArgumentException::class); - new Parameter(); + new Parameter('', 'myParam'); } /** * @test */ - public function parameterNameIsParsed(): void + public function emptyKeyWillThrowAnnotationException(): void { - $parameter = new Parameter(['value' => ['name' => 'myParam']]); + $this->expectException(InvalidArgumentException::class); - self::assertSame('myParam', $parameter->getName()); + new Parameter('name', ''); + } + + /** + * @test + */ + public function nameIsSet(): void + { + $parameter = new Parameter(name: 'paramName', key: 'key'); + + self::assertSame('paramName', $parameter->getName()); + } + + /** + * @test + */ + public function keyIsSet(): void + { + $parameter = new Parameter(name: 'paramName', key: 'key'); + + self::assertSame('key', $parameter->getKey()); } /** @@ -45,7 +66,7 @@ public function parameterNameIsParsed(): void */ public function defaultValueDefaultsToNull(): void { - $parameter = new Parameter(['value' => ['name' => 'myParam']]); + $parameter = new Parameter(name: 'paramName', key: 'myParam'); self::assertNull($parameter->getDefaultValue()); } @@ -57,7 +78,7 @@ public function defaultValueDefaultsToNull(): void */ public function defaultValueIsParsed(mixed $defaultValue): void { - $parameter = new Parameter(['value' => ['name' => 'myParam', 'default' => $defaultValue]]); + $parameter = new Parameter(name: 'paramName', key: 'myParam', default: $defaultValue); self::assertSame($defaultValue, $parameter->getDefaultValue()); } @@ -67,7 +88,7 @@ public function defaultValueIsParsed(mixed $defaultValue): void */ public function requireDefaultsToTrue(): void { - $parameter = new Parameter(['value' => ['name' => 'myParam']]); + $parameter = new Parameter(name: 'paramName', key: 'myParam'); self::assertTrue($parameter->isRequired()); } @@ -79,7 +100,7 @@ public function requireDefaultsToTrue(): void */ public function requireIsParsed(bool $requireValue): void { - $parameter = new Parameter(['value' => ['name' => 'myParam', 'required' => $requireValue]]); + $parameter = new Parameter(name: 'paramName', key: 'myParam', required: $requireValue); self::assertSame($requireValue, $parameter->isRequired()); } diff --git a/tests/bitExpert/Disco/Config/BeanConfiguration.php b/tests/bitExpert/Disco/Config/BeanConfiguration.php index b20b447..0bc175e 100644 --- a/tests/bitExpert/Disco/Config/BeanConfiguration.php +++ b/tests/bitExpert/Disco/Config/BeanConfiguration.php @@ -12,92 +12,70 @@ namespace bitExpert\Disco\Config; -use bitExpert\Disco\Annotations\Bean; -use bitExpert\Disco\Annotations\Configuration; +use bitExpert\Disco\Attributes\Bean; +use bitExpert\Disco\Attributes\Configuration; use bitExpert\Disco\Helper\InitializedService; use bitExpert\Disco\Helper\MasterService; use bitExpert\Disco\Helper\SampleService; -/** - * @Configuration - */ +#[Configuration] class BeanConfiguration { - /** - * @Bean({"singleton"=false, "lazy"=false, "scope"="session"}) - */ + #[Bean(singleton: false, lazy: false, scope: Bean::SCOPE_SESSION)] public function nonSingletonNonLazySessionBean(): MasterService { return new MasterService($this->nonSingletonNonLazyRequestBean()); } - /** - * @Bean({"singleton"=false, "lazy"=false, "scope"="request"}) - */ + #[Bean(singleton: false, lazy: false, scope: Bean::SCOPE_REQUEST)] public function nonSingletonNonLazyRequestBean(): SampleService { return new SampleService(); } - /** - * @Bean({"singleton"=false, "lazy"=true, "scope"="session"}) - */ + #[Bean(singleton: false, lazy: true, scope: Bean::SCOPE_SESSION)] public function nonSingletonLazySessionBean(): MasterService { return new MasterService($this->nonSingletonLazyRequestBean()); } - /** - * @Bean({"singleton"=false, "lazy"=true, "scope"="request"}) - */ + #[Bean(singleton: false, lazy: true, scope: Bean::SCOPE_REQUEST)] public function nonSingletonLazyRequestBean(): SampleService { return new SampleService(); } - /** - * @Bean({"singleton"=true, "lazy"=false, "scope"="session"}) - */ + #[Bean(singleton: true, lazy: false, scope: Bean::SCOPE_SESSION)] public function singletonNonLazySessionBean(): MasterService { return new MasterService($this->singletonNonLazyRequestBean()); } - /** - * @Bean({"singleton"=true, "lazy"=false, "scope"="request"}) - */ + #[Bean(singleton: true, lazy: false, scope: Bean::SCOPE_REQUEST)] public function singletonNonLazyRequestBean(): SampleService { return new SampleService(); } - /** - * @Bean({"singleton"=true, "lazy"=true, "scope"="session"}) - */ + #[Bean(singleton: true, lazy: true, scope: Bean::SCOPE_SESSION)] public function singletonLazySessionBean(): MasterService { return new MasterService($this->singletonLazyRequestBean()); } - /** - * @Bean({"singleton"=true, "lazy"=true, "scope"="request"}) - */ + #[Bean(singleton: true, lazy: true, scope: Bean::SCOPE_REQUEST)] public function singletonLazyRequestBean(): SampleService { return new SampleService(); } - /** - * @Bean({"singleton"=true, "lazy"=false, "scope"="request"}) - */ + #[Bean(singleton: true, lazy: false, scope: Bean::SCOPE_REQUEST)] public function singletonInitializedService(): InitializedService { return new InitializedService(); } - /** - * @Bean({"singleton"=true, "lazy"=true, "scope"="request"}) - */ + #[Bean(singleton: true, lazy: true, scope: Bean::SCOPE_REQUEST)] public function singletonLazyInitializedService(): InitializedService { return new InitializedService(); diff --git a/tests/bitExpert/Disco/Config/BeanConfigurationPersistence.php b/tests/bitExpert/Disco/Config/BeanConfigurationPersistence.php index d297c98..ebc088b 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationPersistence.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationPersistence.php @@ -12,18 +12,14 @@ namespace bitExpert\Disco\Config; -use bitExpert\Disco\Annotations\Bean; -use bitExpert\Disco\Annotations\Configuration; +use bitExpert\Disco\Attributes\Bean; +use bitExpert\Disco\Attributes\Configuration; use bitExpert\Disco\Helper\SampleService; -/** - * @Configuration - */ +#[Configuration] class BeanConfigurationPersistence { - /** - * @Bean - */ + #[Bean] public function sampleService(): SampleService { return new SampleService(); diff --git a/tests/bitExpert/Disco/Config/BeanConfigurationSubclass.php b/tests/bitExpert/Disco/Config/BeanConfigurationSubclass.php index 65fffec..dff83ed 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationSubclass.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationSubclass.php @@ -12,18 +12,14 @@ namespace bitExpert\Disco\Config; -use bitExpert\Disco\Annotations\Bean; -use bitExpert\Disco\Annotations\Configuration; +use bitExpert\Disco\Attributes\Bean; +use bitExpert\Disco\Attributes\Configuration; use bitExpert\Disco\Helper\MasterService; -/** - * @Configuration - */ +#[Configuration] class BeanConfigurationSubclass extends BeanConfiguration { - /** - * @Bean({"singleton"=true, "lazy"=false, "scope"="session"}) - */ + #[Bean(singleton: true, lazy: false, scope: Bean::SCOPE_SESSION)] public function singletonNonLazySessionBeanInSubclass(): MasterService { return new MasterService($this->singletonNonLazyRequestBean()); diff --git a/tests/bitExpert/Disco/Config/BeanConfigurationTrait.php b/tests/bitExpert/Disco/Config/BeanConfigurationTrait.php index a95347c..aa6fde3 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationTrait.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationTrait.php @@ -12,12 +12,10 @@ namespace bitExpert\Disco\Config; -use bitExpert\Disco\Annotations\Configuration; +use bitExpert\Disco\Attributes\Configuration; use bitExpert\Disco\Config\Traits\NonSingletonNonLazyRequestBean; -/** - * @Configuration - */ +#[Configuration] class BeanConfigurationTrait extends BeanConfiguration { use NonSingletonNonLazyRequestBean; diff --git a/tests/bitExpert/Disco/Config/BeanConfigurationWithAliases.php b/tests/bitExpert/Disco/Config/BeanConfigurationWithAliases.php index dae3437..1897635 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationWithAliases.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationWithAliases.php @@ -12,54 +12,36 @@ namespace bitExpert\Disco\Config; -use bitExpert\Disco\Annotations\Alias; -use bitExpert\Disco\Annotations\Bean; -use bitExpert\Disco\Annotations\Configuration; +use bitExpert\Disco\Attributes\Alias; +use bitExpert\Disco\Attributes\Bean; +use bitExpert\Disco\Attributes\Configuration; +use bitExpert\Disco\Attributes\ReturnTypeAlias; use bitExpert\Disco\Helper\SampleService; use bitExpert\Disco\Helper\SampleServiceInterface; -/** - * @Configuration - */ +#[Configuration] class BeanConfigurationWithAliases { - /** - * @Bean({ - * "singelton"=true, - * "aliases"={ - * @Alias({"name" = "\my\Custom\Namespace"}), - * @Alias({"name" = "my::Custom::Namespace"}), - * @Alias({"name" = "Alias_With_Underscore"}), - * @Alias({"name" = "123456"}), - * @Alias({"type" = true}) - * } - * }) - */ + #[Bean(singleton: true)] + #[Alias(name: '\my\Custom\Namespace')] + #[Alias(name: 'my::Custom::Namespace')] + #[Alias(name: 'Alias_With_Underscore')] + #[Alias(name: '123456')] + #[ReturnTypeAlias] public function sampleServiceWithAliases(): SampleService { return new SampleService(); } - /** - * @Bean({ - * "aliases"={ - * @Alias({"type"=true}) - * } - * }) - * @return SampleServiceInterface - */ + #[Bean] + #[ReturnTypeAlias] public function sampleServiceWithInterfaceReturnTypeAlias(): SampleServiceInterface { return new SampleService(); } - /** - * @Bean({ - * "aliases"={ - * @Alias({"name"="aliasIsPublicForInternalService"}) - * } - * }) - */ + #[Bean] + #[Alias(name: 'aliasIsPublicForInternalService')] protected function internalServiceWithAlias(): SampleService { return new SampleService(); diff --git a/tests/bitExpert/Disco/Config/BeanConfigurationWithConflictingAliases.php b/tests/bitExpert/Disco/Config/BeanConfigurationWithConflictingAliases.php index bcd36bd..e66ce31 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationWithConflictingAliases.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationWithConflictingAliases.php @@ -12,38 +12,24 @@ namespace bitExpert\Disco\Config; -use bitExpert\Disco\Annotations\Alias; -use bitExpert\Disco\Annotations\Bean; -use bitExpert\Disco\Annotations\Configuration; +use bitExpert\Disco\Attributes\Bean; +use bitExpert\Disco\Attributes\Configuration; +use bitExpert\Disco\Attributes\ReturnTypeAlias; use bitExpert\Disco\Helper\SampleService; use bitExpert\Disco\Helper\SampleServiceInterface; -/** - * @Configuration - */ +#[Configuration] class BeanConfigurationWithConflictingAliases { - /** - * @Bean({ - * "aliases"={ - * @Alias({"type"=true}) - * } - * }) - * @return SampleServiceInterface - */ + #[Bean] + #[ReturnTypeAlias] public function sampleService1(): SampleServiceInterface { return new SampleService(); } - /** - * @Bean({ - * "aliases"={ - * @Alias({"type"=true}) - * } - * }) - * @return SampleServiceInterface - */ + #[Bean] + #[ReturnTypeAlias] public function sampleService2(): SampleServiceInterface { return new SampleService(); diff --git a/tests/bitExpert/Disco/Config/BeanConfigurationWithConflictingAliasesInParentClass.php b/tests/bitExpert/Disco/Config/BeanConfigurationWithConflictingAliasesInParentClass.php index 346ae25..e65952c 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationWithConflictingAliasesInParentClass.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationWithConflictingAliasesInParentClass.php @@ -12,25 +12,17 @@ namespace bitExpert\Disco\Config; -use bitExpert\Disco\Annotations\Alias; -use bitExpert\Disco\Annotations\Bean; -use bitExpert\Disco\Annotations\Configuration; +use bitExpert\Disco\Attributes\Alias; +use bitExpert\Disco\Attributes\Bean; +use bitExpert\Disco\Attributes\Configuration; use bitExpert\Disco\Helper\SampleService; use bitExpert\Disco\Helper\SampleServiceInterface; -/** - * @Configuration - */ +#[Configuration] class BeanConfigurationWithConflictingAliasesInParentClass extends BeanConfigurationWithConflictingAliases { - /** - * @Bean({ - * "aliases"={ - * @Alias({"name"="SampleService3Alias"}) - * } - * }) - * @return SampleServiceInterface - */ + #[Bean] + #[Alias(name: 'SampleService3Alias')] public function sampleService3(): SampleServiceInterface { return new SampleService(); diff --git a/tests/bitExpert/Disco/Config/BeanConfigurationWithParameterizedPostProcessor.php b/tests/bitExpert/Disco/Config/BeanConfigurationWithParameterizedPostProcessor.php index f60ab6a..f42053b 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationWithParameterizedPostProcessor.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationWithParameterizedPostProcessor.php @@ -12,33 +12,24 @@ namespace bitExpert\Disco\Config; -use bitExpert\Disco\Annotations\Bean; -use bitExpert\Disco\Annotations\BeanPostProcessor; -use bitExpert\Disco\Annotations\Configuration; -use bitExpert\Disco\Annotations\Parameter; +use bitExpert\Disco\Attributes\Bean; +use bitExpert\Disco\Attributes\BeanPostProcessor; +use bitExpert\Disco\Attributes\Configuration; +use bitExpert\Disco\Attributes\Parameter; use bitExpert\Disco\Helper\ParameterizedSampleServiceBeanPostProcessor; use bitExpert\Disco\Helper\SampleService; -/** - * @Configuration - */ +#[Configuration] class BeanConfigurationWithParameterizedPostProcessor { - /** - * @BeanPostProcessor({ - * "parameters"={ - * @Parameter({"name" = "test"}) - * } - * }) - */ + #[BeanPostProcessor] + #[Parameter(name: 'test', key: 'test')] public function sampleServiceBeanPostProcessor($test = ''): ParameterizedSampleServiceBeanPostProcessor { return new ParameterizedSampleServiceBeanPostProcessor($test); } - /** - * @Bean - */ + #[Bean] public function nonSingletonNonLazyRequestBean(): SampleService { return new SampleService(); diff --git a/tests/bitExpert/Disco/Config/BeanConfigurationWithParameters.php b/tests/bitExpert/Disco/Config/BeanConfigurationWithParameters.php index 5b8a1d8..3b7c697 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationWithParameters.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationWithParameters.php @@ -12,24 +12,16 @@ namespace bitExpert\Disco\Config; -use bitExpert\Disco\Annotations\Bean; -use bitExpert\Disco\Annotations\Configuration; -use bitExpert\Disco\Annotations\Parameter; +use bitExpert\Disco\Attributes\Bean; +use bitExpert\Disco\Attributes\Configuration; +use bitExpert\Disco\Attributes\Parameter; use bitExpert\Disco\Helper\SampleService; -/** - * @Configuration - */ +#[Configuration] class BeanConfigurationWithParameters { - /** - * @Bean({ - * "singleton"=false, - * "parameters"={ - * @Parameter({"name" = "test"}) - * } - * }) - */ + #[Bean(singleton: false)] + #[Parameter(name: 'test', key: 'test')] public function sampleServiceWithParam($test = ''): SampleService { $service = new SampleService(); @@ -37,14 +29,8 @@ public function sampleServiceWithParam($test = ''): SampleService return $service; } - /** - * @Bean({ - * "singleton"=false, - * "parameters"={ - * @Parameter({"name" = "test", "default" = null}) - * } - * }) - */ + #[Bean(singleton: false)] + #[Parameter(name: 'test', key: 'test', default: null)] public function sampleServiceWithParamNull($test = ''): SampleService { $service = new SampleService(); @@ -52,14 +38,8 @@ public function sampleServiceWithParamNull($test = ''): SampleService return $service; } - /** - * @Bean({ - * "singleton"=false, - * "parameters"={ - * @Parameter({"name" = "test", "default" = true}) - * } - * }) - */ + #[Bean(singleton: false)] + #[Parameter(name: 'test', key: 'test', default: true)] public function sampleServiceWithParamBool($test = ''): SampleService { $service = new SampleService(); @@ -67,14 +47,8 @@ public function sampleServiceWithParamBool($test = ''): SampleService return $service; } - /** - * @Bean({ - * "singleton"=false, - * "parameters"={ - * @Parameter({"name" = "test", "default" = 0}) - * } - * }) - */ + #[Bean(singleton: false)] + #[Parameter(name: 'test', key: 'test', default: 0)] public function sampleServiceWithParamEmpty($test = ''): SampleService { $service = new SampleService(); @@ -82,14 +56,8 @@ public function sampleServiceWithParamEmpty($test = ''): SampleService return $service; } - /** - * @Bean({ - * "singleton"=false, - * "parameters"={ - * @Parameter({"name" = "test.nested.key"}) - * } - * }) - */ + #[Bean(singleton: false)] + #[Parameter(name: 'test', key: 'test.nested.key')] public function sampleServiceWithNestedParamKey($test = ''): SampleService { $service = new SampleService(); @@ -97,14 +65,8 @@ public function sampleServiceWithNestedParamKey($test = ''): SampleService return $service; } - /** - * @Bean({ - * "singleton"=false, - * "parameters"={ - * @Parameter({"name" = "test", "default" = "myDefaultValue"}) - * } - * }) - */ + #[Bean(singleton: false)] + #[Parameter(name: 'test', key: 'test', default: 'myDefaultValue')] public function sampleServiceWithParamDefaultValue($test = ''): SampleService { $service = new SampleService(); @@ -112,14 +74,8 @@ public function sampleServiceWithParamDefaultValue($test = ''): SampleService return $service; } - /** - * @Bean({ - * "singleton"=false, - * "parameters"={ - * @Parameter({"name" = "test", "required" = false}) - * } - * }) - */ + #[Bean(singleton: false)] + #[Parameter(name: 'test', key: 'test', required: false)] public function sampleServiceWithoutRequiredParam($test = ''): SampleService { $service = new SampleService(); diff --git a/tests/bitExpert/Disco/Config/BeanConfigurationWithPostProcessor.php b/tests/bitExpert/Disco/Config/BeanConfigurationWithPostProcessor.php index 1cb945b..58bcd92 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationWithPostProcessor.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationWithPostProcessor.php @@ -12,38 +12,28 @@ namespace bitExpert\Disco\Config; -use bitExpert\Disco\Annotations\Bean; -use bitExpert\Disco\Annotations\BeanPostProcessor; -use bitExpert\Disco\Annotations\Configuration; -use bitExpert\Disco\BeanFactoryPostProcessor; -use bitExpert\Disco\Helper\BeanFactoryAwareService; +use bitExpert\Disco\Attributes\Bean; +use bitExpert\Disco\Attributes\BeanPostProcessor; +use bitExpert\Disco\Attributes\Configuration; use bitExpert\Disco\Helper\SampleService; use bitExpert\Disco\Helper\SampleServiceBeanPostProcessor; -/** - * @Configuration - */ +#[Configuration] class BeanConfigurationWithPostProcessor { - /** - * @BeanPostProcessor - */ + #[BeanPostProcessor] public function sampleServiceBeanPostProcessor(): SampleServiceBeanPostProcessor { return new SampleServiceBeanPostProcessor(); } - /** - * @Bean - */ + #[Bean] public function nonSingletonNonLazyRequestBean(): SampleService { return new SampleService(); } - /** - * @Bean({"lazy"=true}) - */ + #[Bean(lazy: true)] public function nonSingletonLazyRequestBean(): SampleService { return new SampleService(); diff --git a/tests/bitExpert/Disco/Config/BeanConfigurationWithPostProcessorAndParameterizedDependency.php b/tests/bitExpert/Disco/Config/BeanConfigurationWithPostProcessorAndParameterizedDependency.php index 449a710..3f75596 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationWithPostProcessorAndParameterizedDependency.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationWithPostProcessorAndParameterizedDependency.php @@ -12,33 +12,24 @@ namespace bitExpert\Disco\Config; -use bitExpert\Disco\Annotations\Bean; -use bitExpert\Disco\Annotations\BeanPostProcessor; -use bitExpert\Disco\Annotations\Configuration; -use bitExpert\Disco\Annotations\Parameter; +use bitExpert\Disco\Attributes\Bean; +use bitExpert\Disco\Attributes\BeanPostProcessor; +use bitExpert\Disco\Attributes\Configuration; +use bitExpert\Disco\Attributes\Parameter; use bitExpert\Disco\Helper\ParameterizedSampleServiceBeanPostProcessor; use bitExpert\Disco\Helper\SampleService; -/** - * @Configuration - */ +#[Configuration] class BeanConfigurationWithPostProcessorAndParameterizedDependency { - /** - * @BeanPostProcessor - */ + #[BeanPostProcessor] public function sampleServiceBeanPostProcessor(): ParameterizedSampleServiceBeanPostProcessor { return new ParameterizedSampleServiceBeanPostProcessor($this->dependency()); } - /** - * @Bean({ - * "parameters"={ - * @Parameter({"name" = "test"}) - * } - * }) - */ + #[Bean] + #[Parameter(name: 'test', key: 'test')] public function dependency($test = ''): \stdClass { $object = new \stdClass(); @@ -46,9 +37,7 @@ public function dependency($test = ''): \stdClass return $object; } - /** - * @Bean - */ + #[Bean] public function nonSingletonNonLazyRequestBean(): SampleService { return new SampleService(); diff --git a/tests/bitExpert/Disco/Config/BeanConfigurationWithPrimitives.php b/tests/bitExpert/Disco/Config/BeanConfigurationWithPrimitives.php index 19c262d..59c3ee5 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationWithPrimitives.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationWithPrimitives.php @@ -12,60 +12,45 @@ namespace bitExpert\Disco\Config; -use bitExpert\Disco\Annotations\Bean; -use bitExpert\Disco\Annotations\Configuration; -use bitExpert\Disco\Annotations\Parameters; +use bitExpert\Disco\Attributes\Bean; +use bitExpert\Disco\Attributes\Configuration; use bitExpert\Disco\Helper\SampleService; -/** - * @Configuration - */ +#[Configuration] class BeanConfigurationWithPrimitives { - /** - * @Bean - */ + #[Bean] public function arrayPrimitive(): array { return []; } - /** - * @Bean - */ + #[Bean] public function callablePrimitive(): callable { return function () { }; } - /** - * @Bean - */ + #[Bean] public function boolPrimitive(): bool { return true; } - /** - * @Bean - */ + #[Bean] public function floatPrimitive(): float { return 1.23; } - /** - * @Bean - */ + #[Bean] public function intPrimitive(): int { return 5; } - /** - * @Bean - */ + #[Bean] public function serviceWithStringInjected(): SampleService { $service = new SampleService(); @@ -73,9 +58,7 @@ public function serviceWithStringInjected(): SampleService return $service; } - /** - * @Bean - */ + #[Bean] public function stringPrimitive(): string { return 'Disco'; diff --git a/tests/bitExpert/Disco/Config/BeanConfigurationWithProtectedMethod.php b/tests/bitExpert/Disco/Config/BeanConfigurationWithProtectedMethod.php index 4f7caa5..c157052 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationWithProtectedMethod.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationWithProtectedMethod.php @@ -12,43 +12,33 @@ namespace bitExpert\Disco\Config; -use bitExpert\Disco\Annotations\Bean; -use bitExpert\Disco\Annotations\Configuration; +use bitExpert\Disco\Attributes\Bean; +use bitExpert\Disco\Attributes\Configuration; use bitExpert\Disco\Helper\MasterService; use bitExpert\Disco\Helper\SampleService; -/** - * @Configuration - */ +#[Configuration] class BeanConfigurationWithProtectedMethod { - /** - * @Bean({"singleton"=false}) - */ + #[Bean(singleton: false)] public function masterServiceWithSingletonDependency(): MasterService { return new MasterService($this->singletonDependency()); } - /** - * @Bean({"singleton"=true}) - */ + #[Bean(singleton: true)] protected function singletonDependency(): SampleService { return new SampleService(); } - /** - * @Bean({"singleton"=false}) - */ + #[Bean(singleton: false)] public function masterServiceWithNonSingletonDependency(): MasterService { return new MasterService($this->nonSingletonDependency()); } - /** - * @Bean({"singleton"=false}) - */ + #[Bean(singleton: false)] protected function nonSingletonDependency(): SampleService { return new SampleService(); diff --git a/tests/bitExpert/Disco/Config/ExtendedBeanConfigurationOverwritingParentAlias.php b/tests/bitExpert/Disco/Config/ExtendedBeanConfigurationOverwritingParentAlias.php index 4a5467a..5d0bc1f 100644 --- a/tests/bitExpert/Disco/Config/ExtendedBeanConfigurationOverwritingParentAlias.php +++ b/tests/bitExpert/Disco/Config/ExtendedBeanConfigurationOverwritingParentAlias.php @@ -12,25 +12,17 @@ namespace bitExpert\Disco\Config; -use bitExpert\Disco\Annotations\Alias; -use bitExpert\Disco\Annotations\Bean; -use bitExpert\Disco\Annotations\Configuration; +use bitExpert\Disco\Attributes\Bean; +use bitExpert\Disco\Attributes\Configuration; +use bitExpert\Disco\Attributes\ReturnTypeAlias; use bitExpert\Disco\Helper\SampleService; use bitExpert\Disco\Helper\SampleServiceInterface; -/** - * @Configuration - */ +#[Configuration] class ExtendedBeanConfigurationOverwritingParentAlias extends BeanConfigurationWithAliases { - /** - * @Bean({ - * "aliases"={ - * @Alias({"type"=true}) - * } - * }) - * @return SampleServiceInterface - */ + #[Bean] + #[ReturnTypeAlias] public function extendedSampleServiceWithInterfaceReturnTypeAlias(): SampleServiceInterface { return new SampleService(); diff --git a/tests/bitExpert/Disco/Config/InterfaceConfiguration.php b/tests/bitExpert/Disco/Config/InterfaceConfiguration.php index 0c2a01b..46b6282 100644 --- a/tests/bitExpert/Disco/Config/InterfaceConfiguration.php +++ b/tests/bitExpert/Disco/Config/InterfaceConfiguration.php @@ -12,11 +12,9 @@ namespace bitExpert\Disco\Config; -use bitExpert\Disco\Annotations\Configuration; +use bitExpert\Disco\Attributes\Configuration; -/** - * @Configuration - */ +#[Configuration] interface InterfaceConfiguration { } diff --git a/tests/bitExpert/Disco/Config/InvalidConfiguration.php b/tests/bitExpert/Disco/Config/InvalidConfiguration.php index f87ca68..4c6db1d 100644 --- a/tests/bitExpert/Disco/Config/InvalidConfiguration.php +++ b/tests/bitExpert/Disco/Config/InvalidConfiguration.php @@ -13,7 +13,7 @@ namespace bitExpert\Disco\Config; /** - * Configuration class missing the needed annotation. + * Configuration class missing the needed attribute. */ class InvalidConfiguration { diff --git a/tests/bitExpert/Disco/Config/MissingBeanAnnotationConfiguration.php b/tests/bitExpert/Disco/Config/MissingBeanAnnotationConfiguration.php index 4e8a7e4..66fbc45 100644 --- a/tests/bitExpert/Disco/Config/MissingBeanAnnotationConfiguration.php +++ b/tests/bitExpert/Disco/Config/MissingBeanAnnotationConfiguration.php @@ -12,12 +12,10 @@ namespace bitExpert\Disco\Config; -use bitExpert\Disco\Annotations\Configuration; +use bitExpert\Disco\Attributes\Configuration; use bitExpert\Disco\Helper\SampleService; -/** - * @Configuration - */ +#[Configuration] class MissingBeanAnnotationConfiguration { public function nonSingletonNonLazyRequestBean() diff --git a/tests/bitExpert/Disco/Config/MissingReturnTypeConfiguration.php b/tests/bitExpert/Disco/Config/MissingReturnTypeConfiguration.php index 72c385f..6f9ab04 100644 --- a/tests/bitExpert/Disco/Config/MissingReturnTypeConfiguration.php +++ b/tests/bitExpert/Disco/Config/MissingReturnTypeConfiguration.php @@ -12,18 +12,14 @@ namespace bitExpert\Disco\Config; -use bitExpert\Disco\Annotations\Bean; -use bitExpert\Disco\Annotations\Configuration; +use bitExpert\Disco\Attributes\Bean; +use bitExpert\Disco\Attributes\Configuration; use bitExpert\Disco\Helper\SampleService; -/** - * @Configuration - */ +#[Configuration] class MissingReturnTypeConfiguration { - /** - * @Bean({"singleton"=false, "lazy"=false, "scope"="request"}) - */ + #[Bean(singleton: false, lazy: false, scope: Bean::SCOPE_REQUEST)] public function nonSingletonNonLazyRequestBean() { return new SampleService(); diff --git a/tests/bitExpert/Disco/Config/NonExistentReturnTypeConfiguration.php b/tests/bitExpert/Disco/Config/NonExistentReturnTypeConfiguration.php index 514c641..4ed0891 100644 --- a/tests/bitExpert/Disco/Config/NonExistentReturnTypeConfiguration.php +++ b/tests/bitExpert/Disco/Config/NonExistentReturnTypeConfiguration.php @@ -12,18 +12,14 @@ namespace bitExpert\Disco\Config; -use bitExpert\Disco\Annotations\Bean; -use bitExpert\Disco\Annotations\Configuration; +use bitExpert\Disco\Attributes\Bean; +use bitExpert\Disco\Attributes\Configuration; use bitExpert\Disco\Helper\SampleService; -/** - * @Configuration - */ +#[Configuration] class NonExistentReturnTypeConfiguration { - /** - * @Bean({"singleton"=false, "lazy"=false, "scope"="request"}) - */ + #[Bean(singleton: false, lazy: false, scope: Bean::SCOPE_REQUEST)] public function nonSingletonNonLazyRequestBean(): \MyOtherClass { return new SampleService(); diff --git a/tests/bitExpert/Disco/Config/Traits/NonSingletonNonLazyRequestBean.php b/tests/bitExpert/Disco/Config/Traits/NonSingletonNonLazyRequestBean.php index 8bd2df4..521036d 100644 --- a/tests/bitExpert/Disco/Config/Traits/NonSingletonNonLazyRequestBean.php +++ b/tests/bitExpert/Disco/Config/Traits/NonSingletonNonLazyRequestBean.php @@ -12,14 +12,12 @@ namespace bitExpert\Disco\Config\Traits; -use bitExpert\Disco\Annotations\Bean; +use bitExpert\Disco\Attributes\Bean; use bitExpert\Disco\Helper\SampleService; trait NonSingletonNonLazyRequestBean { - /** - * @Bean({"singleton"=false, "lazy"=false, "scope"="request"}) - */ + #[Bean(singleton: false, lazy: false, scope: Bean::SCOPE_REQUEST)] public function nonSingletonNonLazyRequestBeanInTrait(): SampleService { return new SampleService(); diff --git a/tests/bitExpert/Disco/Config/WrongReturnTypeConfiguration.php b/tests/bitExpert/Disco/Config/WrongReturnTypeConfiguration.php index 8bf7d79..5e90562 100644 --- a/tests/bitExpert/Disco/Config/WrongReturnTypeConfiguration.php +++ b/tests/bitExpert/Disco/Config/WrongReturnTypeConfiguration.php @@ -12,41 +12,31 @@ namespace bitExpert\Disco\Config; -use bitExpert\Disco\Annotations\Bean; -use bitExpert\Disco\Annotations\Configuration; +use bitExpert\Disco\Attributes\Bean; +use bitExpert\Disco\Attributes\Configuration; use bitExpert\Disco\Helper\MasterService; use bitExpert\Disco\Helper\SampleService; -/** - * @Configuration - */ +#[Configuration] class WrongReturnTypeConfiguration { - /** - * @Bean({"singleton"=false, "lazy"=false, "scope"="request"}) - */ + #[Bean(singleton: false, lazy: false, scope: Bean::SCOPE_REQUEST)] public function nonLazyBeanNotReturningAnything(): SampleService { } - /** - * @Bean({"singleton"=false, "lazy"=false, "scope"="request"}) - */ + #[Bean(singleton: false, lazy: false, scope: Bean::SCOPE_REQUEST)] public function nonLazyBeanReturningSomethingWrong(): SampleService { return new MasterService(new SampleService()); } - /** - * @Bean({"singleton"=false, "lazy"=true, "scope"="request"}) - */ + #[Bean(singleton: false, lazy: true, scope: Bean::SCOPE_REQUEST)] public function lazyBeanNotReturningAnything(): SampleService { } - /** - * @Bean({"singleton"=false, "lazy"=true, "scope"="request"}) - */ + #[Bean(singleton: false, lazy: true, scope: Bean::SCOPE_REQUEST)] public function lazyBeanReturningSomethingWrong(): SampleService { return new MasterService(new SampleService()); diff --git a/tests/bitExpert/Disco/Proxy/Configuration/ConfigurationGeneratorUnitTest.php b/tests/bitExpert/Disco/Proxy/Configuration/ConfigurationGeneratorUnitTest.php index 4c43e76..b701110 100644 --- a/tests/bitExpert/Disco/Proxy/Configuration/ConfigurationGeneratorUnitTest.php +++ b/tests/bitExpert/Disco/Proxy/Configuration/ConfigurationGeneratorUnitTest.php @@ -16,14 +16,12 @@ use bitExpert\Disco\Config\BeanConfigurationWithConflictingAliases; use bitExpert\Disco\Config\BeanConfigurationWithConflictingAliasesInParentClass; use bitExpert\Disco\Config\ExtendedBeanConfigurationOverwritingParentAlias; -use bitExpert\Disco\Config\BeanConfigurationWithNativeTypeAlias; use bitExpert\Disco\Config\InterfaceConfiguration; use bitExpert\Disco\Config\InvalidConfiguration; use bitExpert\Disco\Config\MissingBeanAnnotationConfiguration; use bitExpert\Disco\Config\MissingReturnTypeConfiguration; use bitExpert\Disco\Config\NonExistentReturnTypeConfiguration; use PHPUnit\Framework\TestCase; -use PHPUnit_Framework_MockObject_MockObject; use ProxyManager\Exception\InvalidProxiedClassException; use Laminas\Code\Generator\ClassGenerator; @@ -124,10 +122,10 @@ public function sameAliasUsedForMultipleBeansThrowsException(): void /** * @test */ - public function unknownAnnotationThrowsException(): void + public function missingConfigurationAttributeThrowsException(): void { $this->expectException(InvalidProxiedClassException::class); - $this->expectExceptionMessageMatches('/^\[Semantical Error\] The annotation "@foo"/'); + $this->expectExceptionMessageMatches('/#\[Configuration\] attribute missing!/'); /** * @foo @@ -158,7 +156,7 @@ public function parsingConfigurationWithoutAnyErrorsSucceeds(): void /** * @test */ - public function subclassedConfigurationIsAllowedToOverrwriteParentAlias(): void + public function subclassedConfigurationIsAllowedToOverwriteParentAlias(): void { $this->classGenerator->expects(self::atLeastOnce()) ->method('addMethodFromGenerator');