dep: package update
This commit is contained in:
+67
-23
@@ -15,6 +15,7 @@ use Illuminate\Support\HigherOrderWhenProxy;
|
||||
use JsonSerializable;
|
||||
use Symfony\Component\VarDumper\VarDumper;
|
||||
use Traversable;
|
||||
use UnexpectedValueException;
|
||||
|
||||
/**
|
||||
* @property-read HigherOrderCollectionProxy $average
|
||||
@@ -45,6 +46,13 @@ use Traversable;
|
||||
*/
|
||||
trait EnumeratesValues
|
||||
{
|
||||
/**
|
||||
* Indicates that the object's string representation should be escaped when __toString is invoked.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $escapeWhenCastingToString = false;
|
||||
|
||||
/**
|
||||
* The methods that can be proxied.
|
||||
*
|
||||
@@ -744,6 +752,49 @@ trait EnumeratesValues
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduce the collection to multiple aggregate values.
|
||||
*
|
||||
* @param callable $callback
|
||||
* @param mixed ...$initial
|
||||
* @return array
|
||||
*
|
||||
* @deprecated Use "reduceSpread" instead
|
||||
*
|
||||
* @throws \UnexpectedValueException
|
||||
*/
|
||||
public function reduceMany(callable $callback, ...$initial)
|
||||
{
|
||||
return $this->reduceSpread($callback, ...$initial);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduce the collection to multiple aggregate values.
|
||||
*
|
||||
* @param callable $callback
|
||||
* @param mixed ...$initial
|
||||
* @return array
|
||||
*
|
||||
* @throws \UnexpectedValueException
|
||||
*/
|
||||
public function reduceSpread(callable $callback, ...$initial)
|
||||
{
|
||||
$result = $initial;
|
||||
|
||||
foreach ($this as $key => $value) {
|
||||
$result = call_user_func_array($callback, array_merge($result, [$value, $key]));
|
||||
|
||||
if (! is_array($result)) {
|
||||
throw new UnexpectedValueException(sprintf(
|
||||
"%s::reduceMany expects reducer to return an array, but got a '%s' instead.",
|
||||
class_basename(static::class), gettype($result)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduce an associative collection to a single value.
|
||||
*
|
||||
@@ -773,28 +824,6 @@ trait EnumeratesValues
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return only unique items from the collection array.
|
||||
*
|
||||
* @param string|callable|null $key
|
||||
* @param bool $strict
|
||||
* @return static
|
||||
*/
|
||||
public function unique($key = null, $strict = false)
|
||||
{
|
||||
$callback = $this->valueRetriever($key);
|
||||
|
||||
$exists = [];
|
||||
|
||||
return $this->reject(function ($item, $key) use ($callback, $strict, &$exists) {
|
||||
if (in_array($id = $callback($item, $key), $exists, $strict)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$exists[] = $id;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return only unique items from the collection array using strict comparison.
|
||||
*
|
||||
@@ -878,7 +907,22 @@ trait EnumeratesValues
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->toJson();
|
||||
return $this->escapeWhenCastingToString
|
||||
? e($this->toJson())
|
||||
: $this->toJson();
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's string representation should be escaped when __toString is invoked.
|
||||
*
|
||||
* @param bool $escape
|
||||
* @return $this
|
||||
*/
|
||||
public function escapeWhenCastingToString($escape = true)
|
||||
{
|
||||
$this->escapeWhenCastingToString = $escape;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user