Added Macroable for Hyperf\Utils\Arr. (#4157)

Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
Deeka Wong 2021-11-02 10:30:11 +08:00 committed by GitHub
parent 8916691f53
commit bcbcc49130
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 0 deletions

View File

@ -1,5 +1,9 @@
# v2.2.15 - TBD
## Added
- [#4157](https://github.com/hyperf/hyperf/pull/4157) Added `Macroable` for `Hyperf\Utils\Arr`.
# v2.2.14 - 2021-11-01
## Added

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Hyperf\Utils;
use ArrayAccess;
use Hyperf\Macroable\Macroable;
use InvalidArgumentException;
/**
@ -20,6 +21,8 @@ use InvalidArgumentException;
*/
class Arr
{
use Macroable;
/**
* Determine whether the given value is array accessible.
* @param mixed $value

View File

@ -170,4 +170,14 @@ class ArrTest extends TestCase
Arr::forget($data, [2]);
$this->assertSame([1, 2], $data);
}
public function testArrMacroable()
{
Arr::macro('foo', function () {
return 'foo';
});
$this->assertTrue(Arr::hasMacro('foo'));
$this->assertFalse(Arr::hasMacro('bar'));
}
}