Skip to content

Commit

Permalink
Release v3.1.31 (#6944)
Browse files Browse the repository at this point in the history
Co-authored-by: Deeka Wong <huangdijia@gmail.com>
  • Loading branch information
limingxinleo and huangdijia authored Jul 11, 2024
1 parent 4eac760 commit 66f2361
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
47 changes: 36 additions & 11 deletions src/Fluent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,34 @@
namespace Hyperf\Support;

use ArrayAccess;
use Closure;
use Hyperf\Contract\Arrayable;
use Hyperf\Contract\Jsonable;
use JsonSerializable;

/**
* Most of the methods in this file come from illuminate/support,
* thanks Laravel Team provide such a useful class.
*
* @template TKey of array-key
* @template TValue
*
* @implements \Hyperf\Contract\Arrayable<TKey, TValue>
* @implements \ArrayAccess<TKey, TValue>
*/
class Fluent implements ArrayAccess, Arrayable, Jsonable, JsonSerializable
{
/**
* All the attributes set on the fluent instance.
*
* @var array
* @var array<TKey, TValue>
*/
protected $attributes = [];

/**
* Create a new fluent instance.
*
* @param array|object $attributes
* @param iterable<TKey, TValue> $attributes
*/
public function __construct($attributes = [])
{
Expand All @@ -45,7 +52,7 @@ public function __construct($attributes = [])
/**
* Handle dynamic calls to the fluent instance to set attributes.
*
* @param string $method
* @param TKey $method
* @param array $parameters
* @return $this
*/
Expand All @@ -59,7 +66,8 @@ public function __call($method, $parameters)
/**
* Dynamically retrieve the value of an attribute.
*
* @param string $key
* @param TKey $key
* @return null|TValue
*/
public function __get($key)
{
Expand All @@ -69,8 +77,8 @@ public function __get($key)
/**
* Dynamically set the value of an attribute.
*
* @param string $key
* @param mixed $value
* @param TKey $key
* @param TValue $value
*/
public function __set($key, $value)
{
Expand All @@ -80,7 +88,7 @@ public function __set($key, $value)
/**
* Dynamically check if an attribute is set.
*
* @param string $key
* @param TKey $key
* @return bool
*/
public function __isset($key)
Expand All @@ -91,7 +99,7 @@ public function __isset($key)
/**
* Dynamically unset an attribute.
*
* @param string $key
* @param TKey $key
*/
public function __unset($key)
{
Expand All @@ -106,8 +114,11 @@ public function __toString(): string
/**
* Get an attribute from the fluent instance.
*
* @param string $key
* @param null|mixed $default
* @template TGetDefault
*
* @param TKey $key
* @param (Closure(): TGetDefault)|TGetDefault $default
* @return TGetDefault|TValue
*/
public function get($key, $default = null)
{
Expand All @@ -121,7 +132,7 @@ public function get($key, $default = null)
/**
* Get the attributes from the fluent instance.
*
* @return array
* @return array<TKey, TValue>
*/
public function getAttributes()
{
Expand All @@ -130,6 +141,8 @@ public function getAttributes()

/**
* Convert the fluent instance to an array.
*
* @return array<TKey, TValue>
*/
public function toArray(): array
{
Expand All @@ -138,6 +151,8 @@ public function toArray(): array

/**
* Convert the object into something JSON serializable.
*
* @return array<TKey, TValue>
*/
public function jsonSerialize(): mixed
{
Expand All @@ -157,6 +172,8 @@ public function toJson($options = 0)

/**
* Determine if the given offset exists.
*
* @param TKey $offset
*/
public function offsetExists(mixed $offset): bool
{
Expand All @@ -165,6 +182,9 @@ public function offsetExists(mixed $offset): bool

/**
* Get the value for a given offset.
*
* @param TKey $offset
* @return null|TValue
*/
public function offsetGet(mixed $offset): mixed
{
Expand All @@ -173,6 +193,9 @@ public function offsetGet(mixed $offset): mixed

/**
* Set the value at the given offset.
*
* @param TKey $offset
* @param TValue $value
*/
public function offsetSet(mixed $offset, mixed $value): void
{
Expand All @@ -181,6 +204,8 @@ public function offsetSet(mixed $offset, mixed $value): void

/**
* Unset the value at the given offset.
*
* @param TKey $offset
*/
public function offsetUnset(mixed $offset): void
{
Expand Down
5 changes: 5 additions & 0 deletions src/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ function getter(string $property): string
* Create an object instance, if the DI container exist in ApplicationContext,
* then the object will be created by DI container via `make()` method, if not,
* the object will create by `new` keyword.
*
* @template TClass
*
* @param class-string<TClass>|string $name
* @return ($name is class-string<TClass> ? TClass : mixed)
*/
function make(string $name, array $parameters = [])
{
Expand Down

0 comments on commit 66f2361

Please sign in to comment.