Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down
2 changes: 1 addition & 1 deletion src/macros/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"autoload": {
"files": [
"src/autoload.php"
"src/Functions.php"
],
"psr-4": {
"FriendsOfHyperf\\Macros\\": "src/"
Expand Down
6 changes: 5 additions & 1 deletion src/macros/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class ConfigProvider
{
public function __invoke(): array
{
return [];
return [
'listeners' => [
Listener\RegisterMixinListener::class,
],
];
}
}
17 changes: 0 additions & 17 deletions src/macros/src/autoload.php → src/macros/src/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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());
46 changes: 46 additions & 0 deletions src/macros/src/Listener/RegisterMixinListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);
/**
* This file is part of friendsofhyperf/components.
*
* @link https://github.com/friendsofhyperf/components
* @document https://github.com/friendsofhyperf/components/blob/3.x/README.md
* @contact huangdijia@gmail.com
*/
namespace FriendsOfHyperf\Macros\Listener;

use FriendsOfHyperf\Macros\ArrMacros;
use FriendsOfHyperf\Macros\CollectionMacros;
use FriendsOfHyperf\Macros\RequestMacros;
use FriendsOfHyperf\Macros\StringableMacros;
use FriendsOfHyperf\Macros\StrMacros;
use Hyperf\Event\Contract\ListenerInterface;
use Hyperf\Framework\Event\BootApplication;
use Hyperf\HttpServer\Request;
use Hyperf\Utils\Arr;
use Hyperf\Utils\Collection;
use Hyperf\Utils\Str;
use Hyperf\Utils\Stringable;

class RegisterMixinListener implements ListenerInterface
{
public function listen(): array
{
return [
BootApplication::class,
];
}

/**
* @param BootApplication $event
*/
public function process(object $event): void
{
Arr::mixin(new ArrMacros());
Collection::mixin(new CollectionMacros());
Request::mixin(new RequestMacros());
Str::mixin(new StrMacros());
Stringable::mixin(new StringableMacros());
}
}
6 changes: 6 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
namespace FriendsOfHyperf\Tests;

use FriendsOfHyperf\Macros\Listener\RegisterMixinListener;
use Mockery;

/**
Expand All @@ -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();
Expand Down