From d9e9dfb7368155ed5ee6775e6d741635c404ac84 Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Wed, 15 Feb 2023 08:53:35 +0800 Subject: [PATCH 1/2] Adds `RegisterMixinListener` --- composer.json | 2 +- src/macros/composer.json | 2 +- src/macros/src/ConfigProvider.php | 6 ++- .../src/{autoload.php => Functions.php} | 17 ------- .../src/Listener/RegisterMixinListener.php | 46 +++++++++++++++++++ 5 files changed, 53 insertions(+), 20 deletions(-) rename src/macros/src/{autoload.php => Functions.php} (62%) create mode 100644 src/macros/src/Listener/RegisterMixinListener.php diff --git a/composer.json b/composer.json index a3da103a1..5950ced83 100644 --- a/composer.json +++ b/composer.json @@ -106,7 +106,7 @@ "src/exception-event/src/functions.php", "src/helpers/src/functions.php", "src/lock/src/functions.php", - "src/macros/src/autoload.php", + "src/macros/src/Functions.php", "src/model-uid-addon/macros/blueprint.php", "src/model-uid-addon/macros/str.php" ], diff --git a/src/macros/composer.json b/src/macros/composer.json index a46cc3ce7..88c265d41 100644 --- a/src/macros/composer.json +++ b/src/macros/composer.json @@ -20,7 +20,7 @@ }, "autoload": { "files": [ - "src/autoload.php" + "src/Functions.php" ], "psr-4": { "FriendsOfHyperf\\Macros\\": "src/" diff --git a/src/macros/src/ConfigProvider.php b/src/macros/src/ConfigProvider.php index b8b5d5e15..a30c4ec32 100644 --- a/src/macros/src/ConfigProvider.php +++ b/src/macros/src/ConfigProvider.php @@ -14,6 +14,10 @@ class ConfigProvider { public function __invoke(): array { - return []; + return [ + 'listeners' => [ + Listener\RegisterMixinListener::class, + ], + ]; } } diff --git a/src/macros/src/autoload.php b/src/macros/src/Functions.php similarity index 62% rename from src/macros/src/autoload.php rename to src/macros/src/Functions.php index fffff453e..77516061f 100644 --- a/src/macros/src/autoload.php +++ b/src/macros/src/Functions.php @@ -8,17 +8,6 @@ * @document https://github.com/friendsofhyperf/components/blob/3.x/README.md * @contact huangdijia@gmail.com */ -use FriendsOfHyperf\Macros\ArrMacros; -use FriendsOfHyperf\Macros\CollectionMacros; -use FriendsOfHyperf\Macros\RequestMacros; -use FriendsOfHyperf\Macros\StringableMacros; -use FriendsOfHyperf\Macros\StrMacros; -use Hyperf\HttpServer\Request; -use Hyperf\Utils\Arr; -use Hyperf\Utils\Collection; -use Hyperf\Utils\Str; -use Hyperf\Utils\Stringable; - if (! function_exists('array_is_list')) { /** * Determine if the given value is a list of items. @@ -41,9 +30,3 @@ function array_is_list(array $array): bool return true; } } - -Arr::mixin(new ArrMacros()); -Collection::mixin(new CollectionMacros()); -Request::mixin(new RequestMacros()); -Str::mixin(new StrMacros()); -Stringable::mixin(new StringableMacros()); diff --git a/src/macros/src/Listener/RegisterMixinListener.php b/src/macros/src/Listener/RegisterMixinListener.php new file mode 100644 index 000000000..a531c5d5b --- /dev/null +++ b/src/macros/src/Listener/RegisterMixinListener.php @@ -0,0 +1,46 @@ + Date: Wed, 15 Feb 2023 09:00:29 +0800 Subject: [PATCH 2/2] Fix tests --- tests/TestCase.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/TestCase.php b/tests/TestCase.php index 94c4179a2..c333fbe51 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -10,6 +10,7 @@ */ namespace FriendsOfHyperf\Tests; +use FriendsOfHyperf\Macros\Listener\RegisterMixinListener; use Mockery; /** @@ -23,6 +24,11 @@ public function __construct($name = null, array $data = [], $dataName = '') parent::__construct($name, $data, $dataName); } + protected function setUp(): void + { + (new RegisterMixinListener())->process((object) []); + } + protected function tearDown(): void { Mockery::close();