diff --git a/README.md b/README.md index cff94f5..2306675 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,7 @@ Next up you need to create a configuration class `MyConfiguration` and document use bitExpert\Disco\Annotations\Configuration; -/** - * @Configuration - */ +#[Configuration] class MyConfiguration { } @@ -52,14 +50,10 @@ use bitExpert\Disco\Annotations\Bean; use bitExpert\Disco\Annotations\Configuration; use bitExpert\Disco\Helper\SampleService; -/** - * @Configuration - */ +#[Configuration] class MyConfiguration { - /** - * @Bean - */ + #[Bean] public function mySampleService() : SampleService { return new SampleService(); diff --git a/Upgrade.md b/Upgrade.md index e990276..0f92e0d 100644 --- a/Upgrade.md +++ b/Upgrade.md @@ -72,6 +72,7 @@ Disco 0.5.0 dropped support for the @return annotations and strictly relies on the return type definitions now. While this was valid configuration code before the 0.5.0 release: + ```php =7.2.0" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, "autoload": { "psr-4": { "Psr\\Container\\": "src/" @@ -540,22 +263,22 @@ ], "support": { "issues": "https://github.com/php-fig/container/issues", - "source": "https://github.com/php-fig/container/tree/1.1.1" + "source": "https://github.com/php-fig/container/tree/2.0.1" }, - "time": "2021-03-05T17:36:06+00:00" + "time": "2021-03-24T13:40:57+00:00" }, { "name": "psr/log", - "version": "1.1.3", + "version": "1.1.4", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc" + "reference": "d49695b909c3b7628b6289db5479a1c204601f11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/0f73288fd15629204f9d42b7055f72dacbe811fc", - "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc", + "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11", "shasum": "" }, "require": { @@ -579,7 +302,7 @@ "authors": [ { "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" + "homepage": "https://www.php-fig.org/" } ], "description": "Common interface for logging libraries", @@ -590,37 +313,116 @@ "psr-3" ], "support": { - "source": "https://github.com/php-fig/log/tree/1.1.3" + "source": "https://github.com/php-fig/log/tree/1.1.4" }, - "time": "2020-03-23T09:12:05+00:00" + "time": "2021-05-03T11:20:27+00:00" + }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.23.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/46cd95797e9df938fdd2b03693b5fca5e64b01ce", + "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-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.23.0" + }, + "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-02-19T12:13:01+00:00" }, { "name": "webimpress/safe-writer", - "version": "2.1.0", + "version": "2.2.0", "source": { "type": "git", "url": "https://github.com/webimpress/safe-writer.git", - "reference": "5cfafdec5873c389036f14bf832a5efc9390dcdd" + "reference": "9d37cc8bee20f7cb2f58f6e23e05097eab5072e6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webimpress/safe-writer/zipball/5cfafdec5873c389036f14bf832a5efc9390dcdd", - "reference": "5cfafdec5873c389036f14bf832a5efc9390dcdd", + "url": "https://api.github.com/repos/webimpress/safe-writer/zipball/9d37cc8bee20f7cb2f58f6e23e05097eab5072e6", + "reference": "9d37cc8bee20f7cb2f58f6e23e05097eab5072e6", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0" + "php": "^7.3 || ^8.0" }, "require-dev": { - "phpunit/phpunit": "^8.5.8 || ^9.3.7", - "vimeo/psalm": "^3.14.2", - "webimpress/coding-standard": "^1.1.5" + "phpunit/phpunit": "^9.5.4", + "vimeo/psalm": "^4.7", + "webimpress/coding-standard": "^1.2.2" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.1.x-dev", - "dev-develop": "2.2.x-dev", + "dev-master": "2.2.x-dev", + "dev-develop": "2.3.x-dev", "dev-release-1.0": "1.0.x-dev" } }, @@ -643,7 +445,7 @@ ], "support": { "issues": "https://github.com/webimpress/safe-writer/issues", - "source": "https://github.com/webimpress/safe-writer/tree/master" + "source": "https://github.com/webimpress/safe-writer/tree/2.2.0" }, "funding": [ { @@ -651,7 +453,65 @@ "type": "github" } ], - "time": "2020-08-25T07:21:11+00:00" + "time": "2021-04-19T16:34:45+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": [ @@ -847,23 +707,22 @@ }, { "name": "bookdown/bookdown", - "version": "1.x-dev", + "version": "2.x-dev", "source": { "type": "git", "url": "https://github.com/bookdown/Bookdown.Bookdown.git", - "reference": "12037a2460ef13d37e0681430af9a55c851d84e5" + "reference": "853534f823fe86802b4108dc0fb902a660261650" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/bookdown/Bookdown.Bookdown/zipball/12037a2460ef13d37e0681430af9a55c851d84e5", - "reference": "12037a2460ef13d37e0681430af9a55c851d84e5", + "url": "https://api.github.com/repos/bookdown/Bookdown.Bookdown/zipball/853534f823fe86802b4108dc0fb902a660261650", + "reference": "853534f823fe86802b4108dc0fb902a660261650", "shasum": "" }, "require": { "aura/cli": "~2.0", "aura/html": "~2.0", "aura/view": "~2.0", - "bookdown/themes": "~1.0", "league/commonmark": "~0.0", "php": ">=5.6.0", "psr/log": "~1.0" @@ -874,7 +733,6 @@ "webuni/commonmark-attributes-extension": "~0.5", "webuni/commonmark-table-extension": "~0.6" }, - "default-branch": true, "bin": [ "bin/bookdown" ], @@ -905,54 +763,9 @@ ], "support": { "issues": "https://github.com/bookdown/Bookdown.Bookdown/issues", - "source": "https://github.com/bookdown/Bookdown.Bookdown/tree/1.1.1" - }, - "time": "2019-04-23T15:53:49+00:00" - }, - { - "name": "bookdown/themes", - "version": "1.1.4", - "source": { - "type": "git", - "url": "https://github.com/bookdown/Bookdown.Themes.git", - "reference": "cf4986fcef40df4db1504bb62369d37a9e8bf6e7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/bookdown/Bookdown.Themes/zipball/cf4986fcef40df4db1504bb62369d37a9e8bf6e7", - "reference": "cf4986fcef40df4db1504bb62369d37a9e8bf6e7", - "shasum": "" - }, - "type": "library", - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Bookdown Bootswatch Templates Contributors", - "homepage": "https://github.com/bookdown/Bookdown.Themes/contributors" - } - ], - "description": "Bookdown.io With Bootswatch Styles And Prism Syntax Highlighting", - "homepage": "https://github.com/bookdown/Bookdown.Themes", - "keywords": [ - "bookdown", - "docbook", - "docs", - "documentation", - "highlighting", - "manual", - "markdown", - "static site", - "syntax", - "templates" - ], - "support": { - "issues": "https://github.com/bookdown/Bookdown.Themes/issues", - "source": "https://github.com/bookdown/Bookdown.Themes/tree/master" + "source": "https://github.com/bookdown/Bookdown.Bookdown/tree/1.x" }, - "time": "2018-08-10T15:21:32+00:00" + "time": "2017-07-29T18:05:10+00:00" }, { "name": "doctrine/instantiator", @@ -1100,16 +913,16 @@ }, { "name": "mikey179/vfsstream", - "version": "v1.6.8", + "version": "v1.6.9", "source": { "type": "git", "url": "https://github.com/bovigo/vfsStream.git", - "reference": "231c73783ebb7dd9ec77916c10037eff5a2b6efe" + "reference": "2257e326dc3d0f50e55d0a90f71e37899f029718" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/bovigo/vfsStream/zipball/231c73783ebb7dd9ec77916c10037eff5a2b6efe", - "reference": "231c73783ebb7dd9ec77916c10037eff5a2b6efe", + "url": "https://api.github.com/repos/bovigo/vfsStream/zipball/2257e326dc3d0f50e55d0a90f71e37899f029718", + "reference": "2257e326dc3d0f50e55d0a90f71e37899f029718", "shasum": "" }, "require": { @@ -1147,20 +960,20 @@ "source": "https://github.com/bovigo/vfsStream/tree/master", "wiki": "https://github.com/bovigo/vfsStream/wiki" }, - "time": "2019-10-30T15:31:00+00:00" + "time": "2021-07-16T08:08:02+00:00" }, { "name": "monolog/monolog", - "version": "2.2.0", + "version": "2.3.2", "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "1cb1cde8e8dd0f70cc0fe51354a59acad9302084" + "reference": "71312564759a7db5b789296369c1a264efc43aad" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/1cb1cde8e8dd0f70cc0fe51354a59acad9302084", - "reference": "1cb1cde8e8dd0f70cc0fe51354a59acad9302084", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/71312564759a7db5b789296369c1a264efc43aad", + "reference": "71312564759a7db5b789296369c1a264efc43aad", "shasum": "" }, "require": { @@ -1179,7 +992,7 @@ "php-amqplib/php-amqplib": "~2.4", "php-console/php-console": "^3.1.3", "phpspec/prophecy": "^1.6.1", - "phpstan/phpstan": "^0.12.59", + "phpstan/phpstan": "^0.12.91", "phpunit/phpunit": "^8.5", "predis/predis": "^1.1", "rollbar/rollbar": "^1.3", @@ -1231,7 +1044,7 @@ ], "support": { "issues": "https://github.com/Seldaek/monolog/issues", - "source": "https://github.com/Seldaek/monolog/tree/2.2.0" + "source": "https://github.com/Seldaek/monolog/tree/2.3.2" }, "funding": [ { @@ -1243,7 +1056,7 @@ "type": "tidelift" } ], - "time": "2020-12-14T13:15:25+00:00" + "time": "2021-07-23T07:42:52+00:00" }, { "name": "myclabs/deep-copy", @@ -1305,16 +1118,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.10.4", + "version": "v4.12.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "c6d052fc58cb876152f89f532b95a8d7907e7f0e" + "reference": "6608f01670c3cc5079e18c1dab1104e002579143" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/c6d052fc58cb876152f89f532b95a8d7907e7f0e", - "reference": "c6d052fc58cb876152f89f532b95a8d7907e7f0e", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/6608f01670c3cc5079e18c1dab1104e002579143", + "reference": "6608f01670c3cc5079e18c1dab1104e002579143", "shasum": "" }, "require": { @@ -1355,22 +1168,22 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.10.4" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.12.0" }, - "time": "2020-12-20T10:01:03+00:00" + "time": "2021-07-21T10:44:31+00:00" }, { "name": "phar-io/manifest", - "version": "2.0.1", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/phar-io/manifest.git", - "reference": "85265efd3af7ba3ca4b2a2c34dbfc5788dd29133" + "reference": "97803eca37d319dfa7826cc2437fc020857acb53" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/manifest/zipball/85265efd3af7ba3ca4b2a2c34dbfc5788dd29133", - "reference": "85265efd3af7ba3ca4b2a2c34dbfc5788dd29133", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/97803eca37d319dfa7826cc2437fc020857acb53", + "reference": "97803eca37d319dfa7826cc2437fc020857acb53", "shasum": "" }, "require": { @@ -1415,9 +1228,9 @@ "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", "support": { "issues": "https://github.com/phar-io/manifest/issues", - "source": "https://github.com/phar-io/manifest/tree/master" + "source": "https://github.com/phar-io/manifest/tree/2.0.3" }, - "time": "2020-06-27T14:33:11+00:00" + "time": "2021-07-20T11:28:43+00:00" }, { "name": "phar-io/version", @@ -1630,16 +1443,16 @@ }, { "name": "phpspec/prophecy", - "version": "1.12.2", + "version": "1.13.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "245710e971a030f42e08f4912863805570f23d39" + "reference": "be1996ed8adc35c3fd795488a653f4b518be70ea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/245710e971a030f42e08f4912863805570f23d39", - "reference": "245710e971a030f42e08f4912863805570f23d39", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/be1996ed8adc35c3fd795488a653f4b518be70ea", + "reference": "be1996ed8adc35c3fd795488a653f4b518be70ea", "shasum": "" }, "require": { @@ -1691,9 +1504,9 @@ ], "support": { "issues": "https://github.com/phpspec/prophecy/issues", - "source": "https://github.com/phpspec/prophecy/tree/1.12.2" + "source": "https://github.com/phpspec/prophecy/tree/1.13.0" }, - "time": "2020-12-19T10:15:11+00:00" + "time": "2021-03-17T13:42:18+00:00" }, { "name": "phpstan/extension-installer", @@ -1742,16 +1555,16 @@ }, { "name": "phpstan/phpstan", - "version": "0.12.81", + "version": "0.12.94", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "0dd5b0ebeff568f7000022ea5f04aa86ad3124b8" + "reference": "3d0ba4c198a24e3c3fc489f3ec6ac9612c4be5d6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/0dd5b0ebeff568f7000022ea5f04aa86ad3124b8", - "reference": "0dd5b0ebeff568f7000022ea5f04aa86ad3124b8", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/3d0ba4c198a24e3c3fc489f3ec6ac9612c4be5d6", + "reference": "3d0ba4c198a24e3c3fc489f3ec6ac9612c4be5d6", "shasum": "" }, "require": { @@ -1782,13 +1595,17 @@ "description": "PHPStan - PHP Static Analysis Tool", "support": { "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/0.12.81" + "source": "https://github.com/phpstan/phpstan/tree/0.12.94" }, "funding": [ { "url": "https://github.com/ondrejmirtes", "type": "github" }, + { + "url": "https://github.com/phpstan", + "type": "github" + }, { "url": "https://www.patreon.com/phpstan", "type": "patreon" @@ -1798,34 +1615,33 @@ "type": "tidelift" } ], - "time": "2021-03-08T22:03:02+00:00" + "time": "2021-07-30T09:05:27+00:00" }, { "name": "phpstan/phpstan-phpunit", - "version": "0.12.18", + "version": "0.12.22", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-phpunit.git", - "reference": "ab44aec7cfb5cb267b8bc30a8caea86dd50d1f72" + "reference": "7c01ef93bf128b4ac8bdad38c54b2a4fd6b0b3cc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/ab44aec7cfb5cb267b8bc30a8caea86dd50d1f72", - "reference": "ab44aec7cfb5cb267b8bc30a8caea86dd50d1f72", + "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/7c01ef93bf128b4ac8bdad38c54b2a4fd6b0b3cc", + "reference": "7c01ef93bf128b4ac8bdad38c54b2a4fd6b0b3cc", "shasum": "" }, "require": { "php": "^7.1 || ^8.0", - "phpstan/phpstan": "^0.12.60" + "phpstan/phpstan": "^0.12.92" }, "conflict": { "phpunit/phpunit": "<7.0" }, "require-dev": { - "phing/phing": "^2.16.3", "php-parallel-lint/php-parallel-lint": "^1.2", "phpstan/phpstan-strict-rules": "^0.12.6", - "phpunit/phpunit": "^7.5.20" + "phpunit/phpunit": "^9.5" }, "type": "phpstan-extension", "extra": { @@ -1851,22 +1667,22 @@ "description": "PHPUnit extensions and rules for PHPStan", "support": { "issues": "https://github.com/phpstan/phpstan-phpunit/issues", - "source": "https://github.com/phpstan/phpstan-phpunit/tree/0.12.18" + "source": "https://github.com/phpstan/phpstan-phpunit/tree/0.12.22" }, - "time": "2021-03-06T11:51:27+00:00" + "time": "2021-08-12T10:53:43+00:00" }, { "name": "phpstan/phpstan-strict-rules", - "version": "0.12.9", + "version": "0.12.10", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-strict-rules.git", - "reference": "0705fefc7c9168529fd130e341428f5f10f4f01d" + "reference": "ce82a050f9da4a32e438272907e38cdd04806223" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-strict-rules/zipball/0705fefc7c9168529fd130e341428f5f10f4f01d", - "reference": "0705fefc7c9168529fd130e341428f5f10f4f01d", + "url": "https://api.github.com/repos/phpstan/phpstan-strict-rules/zipball/ce82a050f9da4a32e438272907e38cdd04806223", + "reference": "ce82a050f9da4a32e438272907e38cdd04806223", "shasum": "" }, "require": { @@ -1874,10 +1690,9 @@ "phpstan/phpstan": "^0.12.66" }, "require-dev": { - "phing/phing": "^2.16.3", "php-parallel-lint/php-parallel-lint": "^1.2", "phpstan/phpstan-phpunit": "^0.12.16", - "phpunit/phpunit": "^7.5.20" + "phpunit/phpunit": "^9.5" }, "type": "phpstan-extension", "extra": { @@ -1902,22 +1717,22 @@ "description": "Extra strict and opinionated rules for PHPStan", "support": { "issues": "https://github.com/phpstan/phpstan-strict-rules/issues", - "source": "https://github.com/phpstan/phpstan-strict-rules/tree/0.12.9" + "source": "https://github.com/phpstan/phpstan-strict-rules/tree/0.12.10" }, - "time": "2021-01-13T08:50:28+00:00" + "time": "2021-07-04T14:57:39+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.5", + "version": "9.2.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "f3e026641cc91909d421802dd3ac7827ebfd97e1" + "reference": "f6293e1b30a2354e8428e004689671b83871edde" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f3e026641cc91909d421802dd3ac7827ebfd97e1", - "reference": "f3e026641cc91909d421802dd3ac7827ebfd97e1", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f6293e1b30a2354e8428e004689671b83871edde", + "reference": "f6293e1b30a2354e8428e004689671b83871edde", "shasum": "" }, "require": { @@ -1973,7 +1788,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.5" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.6" }, "funding": [ { @@ -1981,7 +1796,7 @@ "type": "github" } ], - "time": "2020-11-28T06:44:49+00:00" + "time": "2021-03-28T07:26:59+00:00" }, { "name": "phpunit/php-file-iterator", @@ -2226,16 +2041,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.2", + "version": "9.5.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "f661659747f2f87f9e72095bb207bceb0f151cb4" + "reference": "191768ccd5c85513b4068bdbe99bb6390c7d54fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/f661659747f2f87f9e72095bb207bceb0f151cb4", - "reference": "f661659747f2f87f9e72095bb207bceb0f151cb4", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/191768ccd5c85513b4068bdbe99bb6390c7d54fb", + "reference": "191768ccd5c85513b4068bdbe99bb6390c7d54fb", "shasum": "" }, "require": { @@ -2247,7 +2062,7 @@ "ext-xml": "*", "ext-xmlwriter": "*", "myclabs/deep-copy": "^1.10.1", - "phar-io/manifest": "^2.0.1", + "phar-io/manifest": "^2.0.3", "phar-io/version": "^3.0.2", "php": ">=7.3", "phpspec/prophecy": "^1.12.1", @@ -2265,7 +2080,7 @@ "sebastian/global-state": "^5.0.1", "sebastian/object-enumerator": "^4.0.3", "sebastian/resource-operations": "^3.0.3", - "sebastian/type": "^2.3", + "sebastian/type": "^2.3.4", "sebastian/version": "^3.0.2" }, "require-dev": { @@ -2313,7 +2128,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.2" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.8" }, "funding": [ { @@ -2325,7 +2140,7 @@ "type": "github" } ], - "time": "2021-02-02T14:45:58+00:00" + "time": "2021-07-31T15:17:34+00:00" }, { "name": "sebastian/cli-parser", @@ -2833,16 +2648,16 @@ }, { "name": "sebastian/global-state", - "version": "5.0.2", + "version": "5.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "a90ccbddffa067b51f574dea6eb25d5680839455" + "reference": "23bd5951f7ff26f12d4e3242864df3e08dec4e49" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/a90ccbddffa067b51f574dea6eb25d5680839455", - "reference": "a90ccbddffa067b51f574dea6eb25d5680839455", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/23bd5951f7ff26f12d4e3242864df3e08dec4e49", + "reference": "23bd5951f7ff26f12d4e3242864df3e08dec4e49", "shasum": "" }, "require": { @@ -2885,7 +2700,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.2" + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.3" }, "funding": [ { @@ -2893,7 +2708,7 @@ "type": "github" } ], - "time": "2020-10-26T15:55:19+00:00" + "time": "2021-06-11T13:31:12+00:00" }, { "name": "sebastian/lines-of-code", @@ -3184,16 +2999,16 @@ }, { "name": "sebastian/type", - "version": "2.3.1", + "version": "2.3.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", - "reference": "81cd61ab7bbf2de744aba0ea61fae32f721df3d2" + "reference": "b8cd8a1c753c90bc1a0f5372170e3e489136f914" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/81cd61ab7bbf2de744aba0ea61fae32f721df3d2", - "reference": "81cd61ab7bbf2de744aba0ea61fae32f721df3d2", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/b8cd8a1c753c90bc1a0f5372170e3e489136f914", + "reference": "b8cd8a1c753c90bc1a0f5372170e3e489136f914", "shasum": "" }, "require": { @@ -3228,7 +3043,7 @@ "homepage": "https://github.com/sebastianbergmann/type", "support": { "issues": "https://github.com/sebastianbergmann/type/issues", - "source": "https://github.com/sebastianbergmann/type/tree/2.3.1" + "source": "https://github.com/sebastianbergmann/type/tree/2.3.4" }, "funding": [ { @@ -3236,7 +3051,7 @@ "type": "github" } ], - "time": "2020-10-26T13:18:59+00:00" + "time": "2021-06-15T12:49:02+00:00" }, { "name": "sebastian/version", @@ -3293,16 +3108,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.5.8", + "version": "3.6.0", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "9d583721a7157ee997f235f327de038e7ea6dac4" + "reference": "ffced0d2c8fa8e6cdc4d695a743271fab6c38625" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/9d583721a7157ee997f235f327de038e7ea6dac4", - "reference": "9d583721a7157ee997f235f327de038e7ea6dac4", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ffced0d2c8fa8e6cdc4d695a743271fab6c38625", + "reference": "ffced0d2c8fa8e6cdc4d695a743271fab6c38625", "shasum": "" }, "require": { @@ -3345,99 +3160,20 @@ "source": "https://github.com/squizlabs/PHP_CodeSniffer", "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" }, - "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" + "time": "2021-04-09T00:54:41+00:00" }, { "name": "theseer/tokenizer", - "version": "1.2.0", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "75a63c33a8577608444246075ea0af0d052e452a" + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/75a63c33a8577608444246075ea0af0d052e452a", - "reference": "75a63c33a8577608444246075ea0af0d052e452a", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/34a41e998c2183e22995f158c581e7b5e755ab9e", + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e", "shasum": "" }, "require": { @@ -3466,7 +3202,7 @@ "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", "support": { "issues": "https://github.com/theseer/tokenizer/issues", - "source": "https://github.com/theseer/tokenizer/tree/master" + "source": "https://github.com/theseer/tokenizer/tree/1.2.1" }, "funding": [ { @@ -3474,65 +3210,7 @@ "type": "github" } ], - "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" + "time": "2021-07-28T10:34:58+00:00" } ], "aliases": [], @@ -3546,5 +3224,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..825f63e 100644 --- a/docs/advanced/bean-post-processor.md +++ b/docs/advanced/bean-post-processor.md @@ -10,7 +10,9 @@ First of all you need to create a class that implements the ```php A valid function name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. -This led to introducing aliases for beans. Each bean can have multiple aliases and two types of aliases are possible. In case of collisions (the same alias is used for different beans) Disco will throw an exception. +This led to introducing aliases for beans. Each bean can have multiple aliases and two types of aliases are possible: +a name alias `#[Alias]` or a type alias `#[TypeAlias]`. + +In case of collisions (the same alias is used for different beans) Disco will throw an exception. You're asked to avoid/resolve such conflicts. Since version 0.10.0 of Disco collision detection will only take the configuration class into account the alias is defined in, this allows you to overwrite aliases in child configuration. -Simply add the `aliases` attribute to the `@Bean` annotation to define a list of `@Alias`: +Simply attribute the Bean with `#[Alias(name: 'some_alias')]` to define a named alias or `#[TypeAlias]` to define the return type as an aliases. +Multiple name aliases are allowed. ```php get(SampleService::class)`. diff --git a/docs/basic/bean-parameters.md b/docs/basic/bean-parameters.md index 3f8ac1f..cca45fe 100644 --- a/docs/basic/bean-parameters.md +++ b/docs/basic/bean-parameters.md @@ -1,10 +1,17 @@ # Bean Parameters -Bean instances can be parameterized by a given configuration. To access the configuration add a `parameters` attribute to your bean configuration method, which holds a collection of `@Parameter` annotations. +Bean instances can be parameterized by a given configuration. To access the configuration add a `#[Parameter]` attribute to your Bean method. -The `@Parameter` annotation requires at least a name which will be used as key to look for in the configuration array. +Configuration parameters can be passed to the Bean configuration method as [named](https://www.php.net/manual/en/functions.arguments.php#functions.named-arguments) +or as positional arguments. A `Parameter` will be used as a named argument when the `name` argument is set. -In the following example the value of configuration key `test` gets passed to the bean configuration method as method parameter. The configuration parameters are passed in the same order as noted to the bean configuration method: +So `#[Parameter(name: 'argName', key: 'config.key)]` is a named parameter whereas `#[Parameter(key: 'config.key')]` is a positional parameter. +As one might expect, the order of the positional parameters matter. Therefore, the recommended way of configuring parameters is using named parameters. +Named and positional parameters can be mixed. + +The `#[Parameter]` attribute requires at least `key` which will be used to look for in the configuration array. + +In the following example the value of configuration key `configKey` gets passed to the Bean configuration for the argument named `$test`. ```php setTest($test); + return $service; + } + + #[Bean] + #[Parameter(name: 'anotherTest', key: 'configKey2')] + #[Parameter(key: 'configKey1')] + public function mySampleService(string $test = '', string $anotherTest = '') : SampleService { $service = new SampleService(); $service->setTest($test); + $service->setAnotherTest($anotherTest); return $service; } } @@ -40,13 +51,18 @@ The configuration array gets passed to the `\bitExpert\Disco\AnnotationBeanFacto ```php 'This is a test.']; +$parameters = ['configKey1' => 'This is a test.' 'configKey2' => 'This is another test.']; $beanFactory = new \bitExpert\Disco\AnnotationBeanFactory( MyConfiguration::class, $parameters ); \bitExpert\Disco\BeanFactoryRegistry::register($beanFactory); + +$sampleService = $beanFactory->get('mySampleService'); + +echo $sampleService->test; // Output: This is a test. +echo $sampleService->anotherTest; // Output: This is another test. ``` ## Default Parameter Values @@ -61,25 +77,30 @@ use bitExpert\Disco\Annotations\Parameter; use bitExpert\Disco\Annotations\Configuration; use bitExpert\Disco\Helper\SampleService; -/** - * @Configuration - */ +#[Configuration] class MyConfiguration { - /** - * @Bean({ - * "parameters"={ - * @Parameter({"name" = "test", "default" = "Some default value"}) - * } - * }) - */ - public function mySampleService($test = '') : SampleService + #[Bean] + #[Parameter(name: 'test', key: 'configKey', default: 'Some default value')] + public function mySampleService(string $test = '') : SampleService { $service = new SampleService(); $service->setTest($test); return $service; } } + +$parameters = []; // empty + +$beanFactory = new \bitExpert\Disco\AnnotationBeanFactory( + MyConfiguration::class, + $parameters +); +\bitExpert\Disco\BeanFactoryRegistry::register($beanFactory); + +$sampleService = $beanFactory->get('mySampleService'); + +echo $sampleService->test; // Output: Some default value. ``` ## Default Bean Configuration Method Parameter Values @@ -113,19 +134,12 @@ use bitExpert\Disco\Annotations\Parameter; use bitExpert\Disco\Annotations\Configuration; use bitExpert\Disco\Helper\SampleService; -/** - * @Configuration - */ +#[Configuration] class MyConfiguration { - /** - * @Bean({ - * "parameters"={ - * @Parameter({"name" = "nested.key"}) - * } - * }) - */ - public function mySampleService($test = '') : SampleService + #[Bean] + #[Parameter(name: 'test', key: 'nested.key')] + public function mySampleService(string $test = '') : SampleService { $service = new SampleService(); $service->setTest($test); diff --git a/docs/intro/getting-started.md b/docs/intro/getting-started.md index a7eb7ff..701e755 100644 --- a/docs/intro/getting-started.md +++ b/docs/intro/getting-started.md @@ -2,7 +2,10 @@ ## Prerequisites -Disco needs at least [PHP](http://php.net) 7.1 to run. Disco relies on the [return type declarations](http://php.net/manual/en/functions.returning-values.php#functions.returning-values.type-declaration) feature introduced with PHP 7.0 as well as the `ocramius/proxy-manager` package which in the latest version is only compatible with PHP 7.1. +Version 1 of Disco needs at least [PHP](http://php.net) 8.0 to run. Disco relies on the [return type declarations](http://php.net/manual/en/functions.returning-values.php#functions.returning-values.type-declaration) +and [attributes](https://www.php.net/manual/en/language.attributes.overview.php) feature introduced with PHP 8.0 as well as the `ocramius/proxy-manager` package. + +:warning: Look at version 0.x if you are still on [PHP](http://php.net) 7.4. ## Installation @@ -26,16 +29,14 @@ $beanFactory = new \bitExpert\Disco\AnnotationBeanFactory(MyConfiguration::class \bitExpert\Disco\BeanFactoryRegistry::register($beanFactory); ``` -Next up you need to create a configuration class ```MyConfiguration```. The class needs to be marked with a `@Configuration` annotation. +Next up you need to create a configuration class ```MyConfiguration```. The class needs to be attributed with `#[Configuration]`. ```php $configClassName * @param array $parameters - * @param BeanFactoryConfiguration $config + * @param BeanFactoryConfiguration|null $config */ - public function __construct($configClassName, array $parameters = [], BeanFactoryConfiguration $config = null) - { + public function __construct( + string $configClassName, + array $parameters = [], + BeanFactoryConfiguration $config = null + ) { if ($config === null) { $config = new BeanFactoryConfiguration(sys_get_temp_dir()); } @@ -79,7 +82,7 @@ public function get(string $id) /** * {@inheritDoc} */ - public function has(string $id) + public function has(string $id): bool { return is_callable([$this->beanConfig, $id]) || $this->beanConfig->hasAlias($id); } diff --git a/src/bitExpert/Disco/Annotations/Alias.php b/src/bitExpert/Disco/Annotations/Alias.php index 52fdae8..ae14ba0 100644 --- a/src/bitExpert/Disco/Annotations/Alias.php +++ b/src/bitExpert/Disco/Annotations/Alias.php @@ -12,64 +12,35 @@ namespace bitExpert\Disco\Annotations; -use Doctrine\Common\Annotations\Annotation\Attribute; -use Doctrine\Common\Annotations\Annotation\Attributes; -use Doctrine\Common\Annotations\AnnotationException; +use Attribute; +use Webmozart\Assert\Assert; /** - * @Annotation - * @Target({"ANNOTATION"}) - * @Attributes({ - * @Attribute("name", type = "string"), - * @Attribute("type", type = "bool"), - * }) + * Repeatable Attribute class to configure named aliases for a Bean. + * + * Used in conjunction with the #[Bean] attribute. */ +#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class Alias { /** - * @var ?string + * @var string */ - private $name; + private string $name; /** - * @var bool - */ - private $type; - - /** - * Creates a new {@link \bitExpert\Disco\Annotations\Bean\Alias}. * - * @param array> $attributes - * @throws AnnotationException + * @param string $name */ - public function __construct(array $attributes = []) + public function __construct(string $name) { - $this->type = false; - - if (isset($attributes['value']['type'])) { - $this->type = AnnotationAttributeParser::parseBooleanValue($attributes['value']['type']); - } + Assert::minLength($name, 1); - 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!'); - } + $this->name = $name; } - public function getName(): ?string + 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>") - * }) + * Non-repeatable Attribute to declare a method as a Bean factory. */ -final class Bean extends ParameterAwareAnnotation +#[Attribute(Attribute::TARGET_METHOD)] +final class Bean { - 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(); + public const SCOPE_REQUEST = 1; + public const SCOPE_SESSION = 2; - // initialize default values - $this->scope = self::SCOPE_REQUEST; - $this->singleton = true; - $this->lazy = false; - $this->aliases = []; + private int $scope; - if (isset($attributes['value'])) { - if (isset($attributes['value']['scope']) && \strtolower($attributes['value']['scope']) === 'session') { - $this->scope = self::SCOPE_SESSION; - } + private bool $singleton; - 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']); - } - } - } + private bool $lazy; /** - * Helper methd to ensure that the passed aliases are of {@link \bitExpert\Disco\Annotations\Alias} type. - * - * @param Alias ...$aliases + * @param bool $singleton + * @param bool $lazy + * @param int $scope */ - private function setAliases(Alias ...$aliases): void + public function __construct(bool $singleton = true, bool $lazy = false, int $scope = self::SCOPE_REQUEST) { - $this->aliases = $aliases; + Assert::inArray($scope, [self::SCOPE_REQUEST, self::SCOPE_SESSION]); + + $this->singleton = $singleton; + $this->lazy = $lazy; + $this->scope = $scope; } /** @@ -135,14 +83,4 @@ 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 index d22f3db..6812dde 100644 --- a/src/bitExpert/Disco/Annotations/BeanPostProcessor.php +++ b/src/bitExpert/Disco/Annotations/BeanPostProcessor.php @@ -12,30 +12,12 @@ namespace bitExpert\Disco\Annotations; -use Doctrine\Common\Annotations\Annotation\Attribute; -use Doctrine\Common\Annotations\Annotation\Attributes; -use Doctrine\Common\Annotations\AnnotationException; +use Attribute; /** - * @Annotation - * @Target({"METHOD"}) - * @Attributes({ - * @Attribute("parameters", type = "array<\bitExpert\Disco\Annotations\Parameter>") - * }) + * Non-repeatable Attribute to declare a method as a BeanPostProcessor factory. */ -final class BeanPostProcessor extends ParameterAwareAnnotation +#[Attribute(Attribute::TARGET_METHOD)] +final class BeanPostProcessor { - /** - * 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/Configuration.php b/src/bitExpert/Disco/Annotations/Configuration.php index 7b4d94a..8f58351 100644 --- a/src/bitExpert/Disco/Annotations/Configuration.php +++ b/src/bitExpert/Disco/Annotations/Configuration.php @@ -12,10 +12,12 @@ namespace bitExpert\Disco\Annotations; +use Attribute; + /** - * @Annotation - * @Target({"CLASS"}) + * Non-repeatable Attribute to mark a class a Beans or BeanPostProcessors provider. */ +#[Attribute(Attribute::TARGET_CLASS)] final class Configuration { } diff --git a/src/bitExpert/Disco/Annotations/Parameter.php b/src/bitExpert/Disco/Annotations/Parameter.php index 60b8da7..d7affac 100644 --- a/src/bitExpert/Disco/Annotations/Parameter.php +++ b/src/bitExpert/Disco/Annotations/Parameter.php @@ -12,72 +12,61 @@ namespace bitExpert\Disco\Annotations; -use Doctrine\Common\Annotations\Annotation\Attribute; -use Doctrine\Common\Annotations\Annotation\Attributes; -use Doctrine\Common\Annotations\AnnotationException; +use Attribute; +use Webmozart\Assert\Assert; /** - * @Annotation - * @Target({"ANNOTATION"}) - * @Attributes({ - * @Attribute("name", type = "string"), - * @Attribute("default", type = "string"), - * @Attribute("required", type = "bool") - * }) + * Repeatable Attribute to declare a "configuration key to parameter mapping" of a Bean or BeanPostProcessor factory + * method. + * + * Used in conjunction with the #[Bean] or #[BeanPostProcessor] attribute. */ +#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] final class Parameter { + private string $key; + + private ?string $name; + + private mixed $defaultValue; + + private bool $required; + /** - * @var string - */ - private $name; - /** - * @var mixed - */ - private $defaultValue; - /** - * @var bool + * @param string $key + * @param bool $required + * @param mixed $default + * @param string|null $name */ - private $required; + public function __construct(string $key, bool $required = true, mixed $default = null, ?string $name = null) + { + Assert::minLength($key, 1); + Assert::nullOrMinLength($name, 1); + + $this->key = $key; + $this->name = $name; + $this->defaultValue = $default; + $this->required = $required; + } /** - * Creates a new {@link \bitExpert\Disco\Annotations\Parameter}. + * Return the name of the argument or null in case of a positioned argument * - * @param array> $attributes - * @throws AnnotationException + * @return string|null */ - public function __construct(array $attributes = []) + public function getName(): ?string { - $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!'); - } + return $this->name; } /** - * Returns the name of the configuration value to use. + * Returns the key of the configuration value to use. * * @return string */ - public function getName(): string + public function getKey(): string { - return $this->name; + return $this->key; } /** 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/Annotations/TypeAlias.php b/src/bitExpert/Disco/Annotations/TypeAlias.php new file mode 100644 index 0000000..3d1e255 --- /dev/null +++ b/src/bitExpert/Disco/Annotations/TypeAlias.php @@ -0,0 +1,25 @@ +setProxiesTargetDir($this->proxyTargetDir); - - if ($this->proxyWriterGenerator instanceof GeneratorStrategyInterface) { - $proxyManagerConfiguration->setGeneratorStrategy($this->proxyWriterGenerator); - } + $proxyManagerConfiguration->setGeneratorStrategy($this->proxyWriterGenerator); if ($this->proxyAutoloader instanceof AutoloaderInterface) { $proxyManagerConfiguration->setProxyAutoloader($this->proxyAutoloader); diff --git a/src/bitExpert/Disco/Proxy/Configuration/ConfigurationGenerator.php b/src/bitExpert/Disco/Proxy/Configuration/ConfigurationGenerator.php index 2931854..fb3c726 100644 --- a/src/bitExpert/Disco/Proxy/Configuration/ConfigurationGenerator.php +++ b/src/bitExpert/Disco/Proxy/Configuration/ConfigurationGenerator.php @@ -12,10 +12,13 @@ namespace bitExpert\Disco\Proxy\Configuration; +use Attribute; +use bitExpert\Disco\Annotations\Alias; use bitExpert\Disco\Annotations\Bean; use bitExpert\Disco\Annotations\BeanPostProcessor; use bitExpert\Disco\Annotations\Configuration; -use bitExpert\Disco\Annotations\Parameters; +use bitExpert\Disco\Annotations\Parameter; +use bitExpert\Disco\Annotations\TypeAlias; use bitExpert\Disco\Proxy\Configuration\MethodGenerator\BeanMethod; use bitExpert\Disco\Proxy\Configuration\MethodGenerator\BeanPostProcessorMethod; use bitExpert\Disco\Proxy\Configuration\MethodGenerator\Constructor; @@ -30,9 +33,8 @@ use bitExpert\Disco\Proxy\Configuration\PropertyGenerator\ForceLazyInitProperty; use bitExpert\Disco\Proxy\Configuration\PropertyGenerator\ParameterValuesProperty; use bitExpert\Disco\Proxy\Configuration\PropertyGenerator\SessionBeansProperty; -use Doctrine\Common\Annotations\AnnotationReader; -use Doctrine\Common\Annotations\AnnotationRegistry; use Exception; +use Laminas\Code\Reflection\ClassReflection; use ProxyManager\Exception\InvalidProxiedClassException; use ProxyManager\ProxyGenerator\Assertion\CanProxyAssertion; use ProxyManager\ProxyGenerator\ProxyGeneratorInterface; @@ -41,25 +43,14 @@ use Laminas\Code\Generator\ClassGenerator; use Laminas\Code\Generator\Exception\InvalidArgumentException; use Laminas\Code\Reflection\MethodReflection; +use ReflectionNamedType; +use ReflectionUnionType; /** * Generator for configuration classes. */ class ConfigurationGenerator implements ProxyGeneratorInterface { - /** - * Creates a new {@link \bitExpert\Disco\Proxy\Configuration\ConfigurationGenerator}. - */ - public function __construct() - { - // registers all required annotations - AnnotationRegistry::registerFile(__DIR__ . '/../../Annotations/Bean.php'); - AnnotationRegistry::registerFile(__DIR__ . '/../../Annotations/Alias.php'); - AnnotationRegistry::registerFile(__DIR__ . '/../../Annotations/BeanPostProcessor.php'); - AnnotationRegistry::registerFile(__DIR__ . '/../../Annotations/Configuration.php'); - AnnotationRegistry::registerFile(__DIR__ . '/../../Annotations/Parameter.php'); - } - /** * {@inheritDoc} * @param ReflectionClass $originalClass @@ -72,7 +63,6 @@ public function generate(ReflectionClass $originalClass, ClassGenerator $classGe { CanProxyAssertion::assertClassCanBeProxied($originalClass, false); - $annotation = null; $forceLazyInitProperty = new ForceLazyInitProperty(); $sessionBeansProperty = new SessionBeansProperty(); $postProcessorsProperty = new BeanPostProcessorsProperty(); @@ -82,17 +72,12 @@ public function generate(ReflectionClass $originalClass, ClassGenerator $classGe $getParameterMethod = new GetParameter($parameterValuesProperty); $wrapBeanAsLazyMethod = new WrapBeanAsLazy($beanFactoryConfigurationProperty); - try { - $reader = new AnnotationReader(); - $annotation = $reader->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 +97,38 @@ public function generate(ReflectionClass $originalClass, ClassGenerator $classGe $localAliases = []; $methods = $originalClass->getMethods(ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED); foreach ($methods as $method) { - $methodReflection = new MethodReflection( + /** @var null|ReflectionUnionType|ReflectionNamedType $returnTypeRefl */ + $returnTypeRefl = $method->getReturnType(); + if ($returnTypeRefl instanceof ReflectionUnionType) { + throw new InvalidProxiedClassException( + sprintf( + 'Method "%s" on "%s" uses the unsupported union type.', + $method->name, + $originalClass->name + ) + ); + } + + $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 +139,58 @@ 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 TypeAlias|null $returnTypeAlias */ + $returnTypeAlias = ($reflectionMethod->getAttributes(TypeAlias::class)[0] ?? null) + ?->newInstance(); + if (null !== $returnTypeAlias) { + 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( + /** @phpstan-ignore-next-line */ + 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,16 +199,17 @@ 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, - $method->getReturnType(), + $reflectionMethod, + $beanAttribute, + $parameterAttributes, + $returnTypeRefl, $forceLazyInitProperty, $sessionBeansProperty, $postProcessorsProperty, diff --git a/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/BeanMethod.php b/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/BeanMethod.php index 683d2c8..80689be 100644 --- a/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/BeanMethod.php +++ b/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/BeanMethod.php @@ -13,6 +13,7 @@ namespace bitExpert\Disco\Proxy\Configuration\MethodGenerator; use bitExpert\Disco\Annotations\Bean; +use bitExpert\Disco\Annotations\Parameter; use bitExpert\Disco\BeanException; use bitExpert\Disco\InitializedBean; use bitExpert\Disco\Proxy\Configuration\PropertyGenerator\BeanFactoryConfigurationProperty; @@ -20,9 +21,10 @@ use bitExpert\Disco\Proxy\Configuration\PropertyGenerator\ForceLazyInitProperty; use bitExpert\Disco\Proxy\Configuration\PropertyGenerator\SessionBeansProperty; use bitExpert\Disco\Proxy\LazyBean\LazyBeanFactory; +use Laminas\Code\Generator\Exception\InvalidArgumentException; 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; @@ -40,7 +42,8 @@ class BeanMethod extends ParameterAwareMethodGenerator * * @param MethodReflection $originalMethod * @param Bean $beanMetadata - * @param ReflectionType|null $beanType + * @param Parameter[] $parameters + * @param ReflectionNamedType|null $beanType * @param ForceLazyInitProperty $forceLazyInitProperty * @param SessionBeansProperty $sessionBeansProperty * @param BeanPostProcessorsProperty $postProcessorsProperty @@ -48,19 +51,20 @@ class BeanMethod extends ParameterAwareMethodGenerator * @param GetParameter $parameterValuesMethod * @param WrapBeanAsLazy $wrapBeanAsLazy * @return MethodGenerator - * @throws \Laminas\Code\Generator\Exception\InvalidArgumentException - * @throws \ProxyManager\Exception\InvalidProxiedClassException + * @throws InvalidArgumentException + * @throws 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 +75,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 +102,7 @@ public static function generateMethod( $body = static::generateNonLazyBeanCode( '', $beanId, - $beanType, + $beanTypeName, $beanMetadata, $methodParams, $forceLazyInitProperty, @@ -127,7 +131,7 @@ public static function generateMethod( * @override Enforces generation of \ProxyManager\Generator\MethodGenerator. * * {@inheritDoc} - * @throws \Laminas\Code\Generator\Exception\InvalidArgumentException + * @throws InvalidArgumentException */ public static function fromReflection(MethodReflection $reflectionMethod): MethodGenerator { diff --git a/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/BeanPostProcessorMethod.php b/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/BeanPostProcessorMethod.php index ed49b09..1f5c059 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\Annotations\Parameter; +use Laminas\Code\Generator\Exception\InvalidArgumentException; 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 Parameter[] $beanPostProcessorParameters * @param GetParameter $parameterValuesMethod * @return MethodGenerator - * @throws \Laminas\Code\Generator\Exception\InvalidArgumentException + * @throws 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..c197a11 100644 --- a/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/ParameterAwareMethodGenerator.php +++ b/src/bitExpert/Disco/Proxy/Configuration/MethodGenerator/ParameterAwareMethodGenerator.php @@ -32,9 +32,10 @@ protected static function convertMethodParamsToString( array $methodParameters, GetParameter $parameterValuesMethod ): string { - $parameters = []; + $positionalArgs = []; + $namedArgs = []; + foreach ($methodParameters as $methodParameter) { - /** @var Parameter $methodParameter */ $defaultValue = $methodParameter->getDefaultValue(); switch (\gettype($defaultValue)) { case 'string': @@ -50,12 +51,32 @@ protected static function convertMethodParamsToString( break; } - $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); + $argName = $methodParameter->getName(); + + if (null === $argName) { + $template = ($defaultValue === '') ? '$this->%s("%s", %s)' : '$this->%s("%s", %s, %s)'; + $positionalArgs[] = \sprintf( + $template, + $methodName, + $methodParameter->getKey(), + $required, + $defaultValue + ); + } else { + $template = ($defaultValue === '') ? '%s: $this->%s("%s", %s)' : '%s: $this->%s("%s", %s, %s)'; + $namedArgs[] = \sprintf( + $template, + $argName, + $methodName, + $methodParameter->getKey(), + $required, + $defaultValue + ); + } } - return \implode(', ', $parameters); + return \implode(', ', [...$positionalArgs, ...$namedArgs]); } } 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/AnnotationBeanFactoryUnitTest.php b/tests/bitExpert/Disco/AnnotationBeanFactoryUnitTest.php index 04f02cb..7853378 100644 --- a/tests/bitExpert/Disco/AnnotationBeanFactoryUnitTest.php +++ b/tests/bitExpert/Disco/AnnotationBeanFactoryUnitTest.php @@ -260,14 +260,15 @@ public function beanFactoryPostProcessorCanBeConfiguredWithParameterizedDependen { $this->beanFactory = new AnnotationBeanFactory( BeanConfigurationWithPostProcessorAndParameterizedDependency::class, - ['test' => 'injectedValue'] + ['configKey1' => 'injectedValue1', 'configKey2' => 'injectedValue2'] ); BeanFactoryRegistry::register($this->beanFactory); /** @var SampleService $bean */ $bean = $this->beanFactory->get('nonSingletonNonLazyRequestBean'); self::assertInstanceOf(stdClass::class, $bean->test); - self::assertEquals('injectedValue', $bean->test->property); + self::assertEquals('injectedValue1', $bean->test->property1); + self::assertEquals('injectedValue2', $bean->test->property2); } /** @@ -277,7 +278,7 @@ public function parameterPassedToBeanFactoryGetsInjectedInBean(): void { $this->beanFactory = new AnnotationBeanFactory( BeanConfigurationWithParameters::class, - ['test' => 'injectedValue'] + ['configKey' => 'injectedValue'] ); BeanFactoryRegistry::register($this->beanFactory); @@ -285,6 +286,54 @@ public function parameterPassedToBeanFactoryGetsInjectedInBean(): void self::assertEquals('injectedValue', $bean->test); } + /** + * @test + */ + public function parametersPassedToBeanFactoryGetsInjectedInBeanWithPositionalParams(): void + { + $this->beanFactory = new AnnotationBeanFactory( + BeanConfigurationWithParameters::class, + ['configKey1' => 'injectedValue1', 'configKey2' => 'injectedValue2'] + ); + BeanFactoryRegistry::register($this->beanFactory); + + $bean = $this->beanFactory->get('sampleServiceWithPositionalParams'); + self::assertEquals('injectedValue1', $bean->test); + self::assertEquals('injectedValue2', $bean->anotherTest); + } + + /** + * @test + */ + public function parametersPassedToBeanFactoryGetsInjectedInBeanWithNamedParams(): void + { + $this->beanFactory = new AnnotationBeanFactory( + BeanConfigurationWithParameters::class, + ['configKey1' => 'injectedValue1', 'configKey2' => 'injectedValue2'] + ); + BeanFactoryRegistry::register($this->beanFactory); + + $bean = $this->beanFactory->get('sampleServiceWithNamedParams'); + self::assertEquals('injectedValue1', $bean->test); + self::assertEquals('injectedValue2', $bean->anotherTest); + } + + /** + * @test + */ + public function parametersPassedToBeanFactoryGetsInjectedInBeanWithMixedPositionalAndNamedParams(): void + { + $this->beanFactory = new AnnotationBeanFactory( + BeanConfigurationWithParameters::class, + ['configKey1' => 'injectedValue1', 'configKey2' => 'injectedValue2'] + ); + BeanFactoryRegistry::register($this->beanFactory); + + $bean = $this->beanFactory->get('sampleServiceWithMixedPositionalAndNamedParams'); + self::assertEquals('injectedValue1', $bean->test); + self::assertEquals('injectedValue2', $bean->anotherTest); + } + /** * @test */ @@ -293,7 +342,7 @@ public function nestedParameterKeyPassedToBeanFactoryGetsInjectedInBean(): void $this->beanFactory = new AnnotationBeanFactory( BeanConfigurationWithParameters::class, [ - 'test' => [ + 'config' => [ 'nested' => [ 'key' => 'injectedValue' ] diff --git a/tests/bitExpert/Disco/Annotations/AliasUnitTest.php b/tests/bitExpert/Disco/Annotations/AliasUnitTest.php index 73ccb69..f0ef434 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\Annotations\Alias; use PHPUnit\Framework\TestCase; +use Webmozart\Assert\InvalidArgumentException; /** - * Unit tests for {@link \bitExpert\Disco\Annotations\Alias}. + * Unit tests for {@link \bitExpert\Disco\Annotations\NameAlias}. */ 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..bfb22a7 100644 --- a/tests/bitExpert/Disco/Annotations/BeanUnitTest.php +++ b/tests/bitExpert/Disco/Annotations/BeanUnitTest.php @@ -12,9 +12,9 @@ namespace bitExpert\Disco\Annotations; -use bitExpert\Disco\Helper\SampleService; +use bitExpert\Disco\Annotations\Bean; use PHPUnit\Framework\TestCase; -use TypeError; +use Webmozart\Assert\InvalidArgumentException; /** * Unit tests for {@link \bitExpert\Disco\Annotations\Bean}. @@ -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..b1e1975 100644 --- a/tests/bitExpert/Disco/Annotations/ParameterUnitTest.php +++ b/tests/bitExpert/Disco/Annotations/ParameterUnitTest.php @@ -12,8 +12,9 @@ namespace bitExpert\Disco\Annotations; -use Doctrine\Common\Annotations\AnnotationException; +use bitExpert\Disco\Annotations\Parameter; use PHPUnit\Framework\TestCase; +use Webmozart\Assert\InvalidArgumentException; /** * Unit tests for {@link \bitExpert\Disco\Annotations\Parameter}. @@ -23,21 +24,41 @@ 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(key: 'myParam', name: ''); } /** * @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(key: ''); + } + + /** + * @test + */ + public function nameIsSet(): void + { + $parameter = new Parameter(name: 'argName', key: 'key'); + + self::assertSame('argName', $parameter->getName()); + } + + /** + * @test + */ + public function keyIsSet(): void + { + $parameter = new Parameter(name: 'argName', 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: 'argName', 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: 'argName', 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: 'argName', 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..a4cd298 100644 --- a/tests/bitExpert/Disco/Config/BeanConfiguration.php +++ b/tests/bitExpert/Disco/Config/BeanConfiguration.php @@ -18,86 +18,64 @@ 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..5f24492 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationPersistence.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationPersistence.php @@ -16,14 +16,10 @@ use bitExpert\Disco\Annotations\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..d488a3b 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationSubclass.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationSubclass.php @@ -16,14 +16,10 @@ use bitExpert\Disco\Annotations\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..d3ae2c2 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationTrait.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationTrait.php @@ -15,9 +15,7 @@ use bitExpert\Disco\Annotations\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..79cb4e5 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationWithAliases.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationWithAliases.php @@ -15,51 +15,33 @@ use bitExpert\Disco\Annotations\Alias; use bitExpert\Disco\Annotations\Bean; use bitExpert\Disco\Annotations\Configuration; +use bitExpert\Disco\Annotations\TypeAlias; 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')] + #[TypeAlias] public function sampleServiceWithAliases(): SampleService { return new SampleService(); } - /** - * @Bean({ - * "aliases"={ - * @Alias({"type"=true}) - * } - * }) - * @return SampleServiceInterface - */ + #[Bean] + #[TypeAlias] 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..a344a9e 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\Annotations\TypeAlias; use bitExpert\Disco\Helper\SampleService; use bitExpert\Disco\Helper\SampleServiceInterface; -/** - * @Configuration - */ +#[Configuration] class BeanConfigurationWithConflictingAliases { - /** - * @Bean({ - * "aliases"={ - * @Alias({"type"=true}) - * } - * }) - * @return SampleServiceInterface - */ + #[Bean] + #[TypeAlias] public function sampleService1(): SampleServiceInterface { return new SampleService(); } - /** - * @Bean({ - * "aliases"={ - * @Alias({"type"=true}) - * } - * }) - * @return SampleServiceInterface - */ + #[Bean] + #[TypeAlias] 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..194e971 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationWithConflictingAliasesInParentClass.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationWithConflictingAliasesInParentClass.php @@ -18,19 +18,11 @@ use bitExpert\Disco\Helper\SampleService; use bitExpert\Disco\Helper\SampleServiceInterface; -/** - * @Configuration - */ +#[Configuration] class BeanConfigurationWithConflictingAliasesInParentClass extends BeanConfigurationWithConflictingAliases { - /** - * @Bean({ - * "aliases"={ - * @Alias({"name"="SampleService3Alias"}) - * } - * }) - * @return SampleServiceInterface - */ + #[Bean] + #[NameAlias(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..ea660b0 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationWithParameterizedPostProcessor.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationWithParameterizedPostProcessor.php @@ -19,26 +19,17 @@ 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..f0c5d08 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationWithParameters.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationWithParameters.php @@ -17,19 +17,11 @@ use bitExpert\Disco\Annotations\Parameter; use bitExpert\Disco\Helper\SampleService; -/** - * @Configuration - */ +#[Configuration] class BeanConfigurationWithParameters { - /** - * @Bean({ - * "singleton"=false, - * "parameters"={ - * @Parameter({"name" = "test"}) - * } - * }) - */ + #[Bean(singleton: false)] + #[Parameter(name: 'test', key: 'configKey')] public function sampleServiceWithParam($test = ''): SampleService { $service = new SampleService(); @@ -37,14 +29,41 @@ public function sampleServiceWithParam($test = ''): SampleService return $service; } - /** - * @Bean({ - * "singleton"=false, - * "parameters"={ - * @Parameter({"name" = "test", "default" = null}) - * } - * }) - */ + #[Bean(singleton: false)] + #[Parameter('configKey1')] + #[Parameter('configKey2')] + public function sampleServiceWithPositionalParams($test = '', $anotherTest = ''): SampleService + { + $service = new SampleService(); + $service->setTest($test); + $service->setAnotherTest($anotherTest); + return $service; + } + + #[Bean(singleton: false)] + #[Parameter(key: 'configKey2', name: 'anotherTest')] + #[Parameter(key: 'configKey1', name: 'test')] + public function sampleServiceWithNamedParams($test = '', $anotherTest = ''): SampleService + { + $service = new SampleService(); + $service->setTest($test); + $service->setAnotherTest($anotherTest); + return $service; + } + + #[Bean(singleton: false)] + #[Parameter(key: 'configKey2', name: 'anotherTest')] + #[Parameter(key: 'configKey1')] + public function sampleServiceWithMixedPositionalAndNamedParams($test = '', $anotherTest = ''): SampleService + { + $service = new SampleService(); + $service->setTest($test); + $service->setAnotherTest($anotherTest); + return $service; + } + + #[Bean(singleton: false)] + #[Parameter(name: 'test', key: 'configKey', default: null)] public function sampleServiceWithParamNull($test = ''): SampleService { $service = new SampleService(); @@ -52,14 +71,8 @@ public function sampleServiceWithParamNull($test = ''): SampleService return $service; } - /** - * @Bean({ - * "singleton"=false, - * "parameters"={ - * @Parameter({"name" = "test", "default" = true}) - * } - * }) - */ + #[Bean(singleton: false)] + #[Parameter(name: 'test', key: 'configKey', default: true)] public function sampleServiceWithParamBool($test = ''): SampleService { $service = new SampleService(); @@ -67,14 +80,8 @@ public function sampleServiceWithParamBool($test = ''): SampleService return $service; } - /** - * @Bean({ - * "singleton"=false, - * "parameters"={ - * @Parameter({"name" = "test", "default" = 0}) - * } - * }) - */ + #[Bean(singleton: false)] + #[Parameter(name: 'test', key: 'configKey', default: 0)] public function sampleServiceWithParamEmpty($test = ''): SampleService { $service = new SampleService(); @@ -82,14 +89,8 @@ public function sampleServiceWithParamEmpty($test = ''): SampleService return $service; } - /** - * @Bean({ - * "singleton"=false, - * "parameters"={ - * @Parameter({"name" = "test.nested.key"}) - * } - * }) - */ + #[Bean(singleton: false)] + #[Parameter(name: 'test', key: 'config.nested.key')] public function sampleServiceWithNestedParamKey($test = ''): SampleService { $service = new SampleService(); @@ -97,14 +98,8 @@ public function sampleServiceWithNestedParamKey($test = ''): SampleService return $service; } - /** - * @Bean({ - * "singleton"=false, - * "parameters"={ - * @Parameter({"name" = "test", "default" = "myDefaultValue"}) - * } - * }) - */ + #[Bean(singleton: false)] + #[Parameter(name: 'test', key: 'configKey', default: 'myDefaultValue')] public function sampleServiceWithParamDefaultValue($test = ''): SampleService { $service = new SampleService(); @@ -112,14 +107,8 @@ public function sampleServiceWithParamDefaultValue($test = ''): SampleService return $service; } - /** - * @Bean({ - * "singleton"=false, - * "parameters"={ - * @Parameter({"name" = "test", "required" = false}) - * } - * }) - */ + #[Bean(singleton: false)] + #[Parameter(name: 'test', key: 'configKey', 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..3bb8a9b 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationWithPostProcessor.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationWithPostProcessor.php @@ -15,35 +15,25 @@ 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\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..27a5b4f 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationWithPostProcessorAndParameterizedDependency.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationWithPostProcessorAndParameterizedDependency.php @@ -19,36 +19,27 @@ 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"}) - * } - * }) - */ - public function dependency($test = ''): \stdClass + #[Bean] + #[Parameter(name: 'property1', key: 'configKey1')] + #[Parameter(name: 'property2', key: 'configKey2')] + public function dependency(string $property1 = '', string $property2 = ''): \stdClass { $object = new \stdClass(); - $object->property = $test; + $object->property1 = $property1; + $object->property2 = $property2; 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..63cc0e3 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationWithPrimitives.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationWithPrimitives.php @@ -14,58 +14,43 @@ use bitExpert\Disco\Annotations\Bean; use bitExpert\Disco\Annotations\Configuration; -use bitExpert\Disco\Annotations\Parameters; 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..c21194d 100644 --- a/tests/bitExpert/Disco/Config/BeanConfigurationWithProtectedMethod.php +++ b/tests/bitExpert/Disco/Config/BeanConfigurationWithProtectedMethod.php @@ -17,38 +17,28 @@ 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..6cc6dae 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\Annotations\TypeAlias; use bitExpert\Disco\Helper\SampleService; use bitExpert\Disco\Helper\SampleServiceInterface; -/** - * @Configuration - */ +#[Configuration] class ExtendedBeanConfigurationOverwritingParentAlias extends BeanConfigurationWithAliases { - /** - * @Bean({ - * "aliases"={ - * @Alias({"type"=true}) - * } - * }) - * @return SampleServiceInterface - */ + #[Bean] + #[TypeAlias] 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..a9daff4 100644 --- a/tests/bitExpert/Disco/Config/InterfaceConfiguration.php +++ b/tests/bitExpert/Disco/Config/InterfaceConfiguration.php @@ -14,9 +14,7 @@ use bitExpert\Disco\Annotations\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..354236b 100644 --- a/tests/bitExpert/Disco/Config/MissingBeanAnnotationConfiguration.php +++ b/tests/bitExpert/Disco/Config/MissingBeanAnnotationConfiguration.php @@ -15,9 +15,7 @@ use bitExpert\Disco\Annotations\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..4638966 100644 --- a/tests/bitExpert/Disco/Config/MissingReturnTypeConfiguration.php +++ b/tests/bitExpert/Disco/Config/MissingReturnTypeConfiguration.php @@ -16,14 +16,10 @@ use bitExpert\Disco\Annotations\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..367207e 100644 --- a/tests/bitExpert/Disco/Config/NonExistentReturnTypeConfiguration.php +++ b/tests/bitExpert/Disco/Config/NonExistentReturnTypeConfiguration.php @@ -16,14 +16,10 @@ use bitExpert\Disco\Annotations\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..c4c613b 100644 --- a/tests/bitExpert/Disco/Config/Traits/NonSingletonNonLazyRequestBean.php +++ b/tests/bitExpert/Disco/Config/Traits/NonSingletonNonLazyRequestBean.php @@ -17,9 +17,7 @@ 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..8476d07 100644 --- a/tests/bitExpert/Disco/Config/WrongReturnTypeConfiguration.php +++ b/tests/bitExpert/Disco/Config/WrongReturnTypeConfiguration.php @@ -17,36 +17,26 @@ 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/Helper/SampleService.php b/tests/bitExpert/Disco/Helper/SampleService.php index 23ef031..87a9239 100644 --- a/tests/bitExpert/Disco/Helper/SampleService.php +++ b/tests/bitExpert/Disco/Helper/SampleService.php @@ -15,6 +15,7 @@ class SampleService implements SampleServiceInterface { public $test; + public $anotherTest; /** * Setter method for the $test property. @@ -25,4 +26,14 @@ public function setTest($test) { $this->test = $test; } + + /** + * Setter method for the $anotherTest property. + * + * @param mixed $test + */ + public function setAnotherTest($test) + { + $this->anotherTest = $test; + } } diff --git a/tests/bitExpert/Disco/Proxy/Configuration/ConfigurationGeneratorUnitTest.php b/tests/bitExpert/Disco/Proxy/Configuration/ConfigurationGeneratorUnitTest.php index 4c43e76..5d6d64e 100644 --- a/tests/bitExpert/Disco/Proxy/Configuration/ConfigurationGeneratorUnitTest.php +++ b/tests/bitExpert/Disco/Proxy/Configuration/ConfigurationGeneratorUnitTest.php @@ -16,14 +16,13 @@ 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\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use PHPUnit_Framework_MockObject_MockObject; use ProxyManager\Exception\InvalidProxiedClassException; use Laminas\Code\Generator\ClassGenerator; @@ -38,7 +37,7 @@ class ConfigurationGeneratorUnitTest extends TestCase private $configGenerator; /** - * @var ClassGenerator&\PHPUnit\Framework\MockObject\MockObject + * @var ClassGenerator&MockObject */ private $classGenerator; @@ -50,9 +49,7 @@ public function setUp(): void parent::setUp(); $this->configGenerator = new ConfigurationGenerator(); - /** @var ClassGenerator&\PHPUnit\Framework\MockObject\MockObject $mock */ - $mock = $this->createMock(ClassGenerator::class); - $this->classGenerator = $mock; + $this->classGenerator = $this->createMock(ClassGenerator::class); } /** @@ -124,14 +121,11 @@ 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 - */ $configObject = new class { public function foo(): string @@ -158,7 +152,7 @@ public function parsingConfigurationWithoutAnyErrorsSucceeds(): void /** * @test */ - public function subclassedConfigurationIsAllowedToOverrwriteParentAlias(): void + public function subclassedConfigurationIsAllowedToOverwriteParentAlias(): void { $this->classGenerator->expects(self::atLeastOnce()) ->method('addMethodFromGenerator');