update 1.0.8.0
Commits for version update
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Illuminate\Support;
|
||||
|
||||
use Countable;
|
||||
use ArrayAccess;
|
||||
use Traversable;
|
||||
use ArrayIterator;
|
||||
use CachingIterator;
|
||||
use JsonSerializable;
|
||||
@@ -80,6 +81,65 @@ class Collection implements ArrayAccess, Arrayable, Countable, IteratorAggregate
|
||||
return $this->avg($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the median of a given key.
|
||||
*
|
||||
* @param null $key
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function median($key = null)
|
||||
{
|
||||
$count = $this->count();
|
||||
|
||||
if ($count == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$values = with(isset($key) ? $this->pluck($key) : $this)
|
||||
->sort()->values();
|
||||
|
||||
$middle = (int) floor($count / 2);
|
||||
|
||||
if ($count % 2) {
|
||||
return $values->get($middle);
|
||||
}
|
||||
|
||||
return (new static([
|
||||
$values->get($middle - 1), $values->get($middle),
|
||||
]))->average();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mode of a given key.
|
||||
*
|
||||
* @param null $key
|
||||
* @return array
|
||||
*/
|
||||
public function mode($key = null)
|
||||
{
|
||||
$count = $this->count();
|
||||
|
||||
if ($count == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$collection = isset($key) ? $this->pluck($key) : $this;
|
||||
|
||||
$counts = new self;
|
||||
|
||||
$collection->each(function ($value) use ($counts) {
|
||||
$counts[$value] = isset($counts[$value]) ? $counts[$value] + 1 : 1;
|
||||
});
|
||||
|
||||
$sorted = $counts->sort();
|
||||
|
||||
$highestValue = $sorted->last();
|
||||
|
||||
return $sorted->filter(function ($value) use ($highestValue) {
|
||||
return $value == $highestValue;
|
||||
})->sort()->keys()->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Collapse the collection of items into a single array.
|
||||
*
|
||||
@@ -604,6 +664,17 @@ class Collection implements ArrayAccess, Arrayable, Countable, IteratorAggregate
|
||||
return $this->slice(($page - 1) * $perPage, $perPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass the collection to the given callback and return the result.
|
||||
*
|
||||
* @param callable $callback
|
||||
* @return mixed
|
||||
*/
|
||||
public function pipe(callable $callback)
|
||||
{
|
||||
return $callback($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and remove the last item from the collection.
|
||||
*
|
||||
@@ -766,13 +837,22 @@ class Collection implements ArrayAccess, Arrayable, Countable, IteratorAggregate
|
||||
/**
|
||||
* Shuffle the items in the collection.
|
||||
*
|
||||
* @param int $seed
|
||||
* @return static
|
||||
*/
|
||||
public function shuffle()
|
||||
public function shuffle($seed = null)
|
||||
{
|
||||
$items = $this->items;
|
||||
|
||||
shuffle($items);
|
||||
if (is_null($seed)) {
|
||||
shuffle($items);
|
||||
} else {
|
||||
srand($seed);
|
||||
|
||||
usort($items, function () {
|
||||
return rand(-1, 1);
|
||||
});
|
||||
}
|
||||
|
||||
return new static($items);
|
||||
}
|
||||
@@ -1162,6 +1242,8 @@ class Collection implements ArrayAccess, Arrayable, Countable, IteratorAggregate
|
||||
return json_decode($items->toJson(), true);
|
||||
} elseif ($items instanceof JsonSerializable) {
|
||||
return $items->jsonSerialize();
|
||||
} elseif ($items instanceof Traversable) {
|
||||
return iterator_to_array($items);
|
||||
}
|
||||
|
||||
return (array) $items;
|
||||
|
||||
@@ -96,14 +96,43 @@ class MessageBag implements Arrayable, Countable, Jsonable, JsonSerializable, Me
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if messages exist for a given key.
|
||||
* Determine if messages exist for all of the given keys.
|
||||
*
|
||||
* @param string $key
|
||||
* @param array|string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function has($key = null)
|
||||
{
|
||||
return $this->first($key) !== '';
|
||||
if (is_null($key)) {
|
||||
return $this->any();
|
||||
}
|
||||
|
||||
$keys = is_array($key) ? $key : func_get_args();
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if ($this->first($key) === '') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if messages exist for any of the given keys.
|
||||
*
|
||||
* @param array $keys
|
||||
* @return bool
|
||||
*/
|
||||
public function hasAny($keys = [])
|
||||
{
|
||||
foreach ($keys as $key) {
|
||||
if ($this->has($key)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,6 +32,7 @@ class Pluralizer
|
||||
'nutrition',
|
||||
'offspring',
|
||||
'plankton',
|
||||
'pokemon',
|
||||
'police',
|
||||
'rice',
|
||||
'series',
|
||||
@@ -50,7 +51,7 @@ class Pluralizer
|
||||
*/
|
||||
public static function plural($value, $count = 2)
|
||||
{
|
||||
if ($count === 1 || static::uncountable($value)) {
|
||||
if ((int) $count === 1 || static::uncountable($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,15 +48,15 @@ trait Macroable
|
||||
*/
|
||||
public static function __callStatic($method, $parameters)
|
||||
{
|
||||
if (static::hasMacro($method)) {
|
||||
if (static::$macros[$method] instanceof Closure) {
|
||||
return call_user_func_array(Closure::bind(static::$macros[$method], null, static::class), $parameters);
|
||||
} else {
|
||||
return call_user_func_array(static::$macros[$method], $parameters);
|
||||
}
|
||||
if (! static::hasMacro($method)) {
|
||||
throw new BadMethodCallException("Method {$method} does not exist.");
|
||||
}
|
||||
|
||||
throw new BadMethodCallException("Method {$method} does not exist.");
|
||||
if (static::$macros[$method] instanceof Closure) {
|
||||
return call_user_func_array(Closure::bind(static::$macros[$method], null, static::class), $parameters);
|
||||
}
|
||||
|
||||
return call_user_func_array(static::$macros[$method], $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,14 +70,14 @@ trait Macroable
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
if (static::hasMacro($method)) {
|
||||
if (static::$macros[$method] instanceof Closure) {
|
||||
return call_user_func_array(static::$macros[$method]->bindTo($this, static::class), $parameters);
|
||||
} else {
|
||||
return call_user_func_array(static::$macros[$method], $parameters);
|
||||
}
|
||||
if (! static::hasMacro($method)) {
|
||||
throw new BadMethodCallException("Method {$method} does not exist.");
|
||||
}
|
||||
|
||||
throw new BadMethodCallException("Method {$method} does not exist.");
|
||||
if (static::$macros[$method] instanceof Closure) {
|
||||
return call_user_func_array(static::$macros[$method]->bindTo($this, static::class), $parameters);
|
||||
}
|
||||
|
||||
return call_user_func_array(static::$macros[$method], $parameters);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylorotwell@gmail.com"
|
||||
"email": "taylor@laravel.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
@@ -20,6 +20,9 @@
|
||||
"illuminate/contracts": "5.2.*",
|
||||
"paragonie/random_compat": "~1.4"
|
||||
},
|
||||
"replace": {
|
||||
"tightenco/collect": "self.version"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Illuminate\\Support\\": ""
|
||||
|
||||
Reference in New Issue
Block a user