laravel-6 support

This commit is contained in:
RafficMohammed
2023-01-08 01:17:22 +05:30
parent 1a5c16ae4b
commit 774eed8b0e
4962 changed files with 279380 additions and 297961 deletions

View File

@@ -3,8 +3,8 @@
namespace Illuminate\Support;
use ArrayAccess;
use InvalidArgumentException;
use Illuminate\Support\Traits\Macroable;
use InvalidArgumentException;
class Arr
{
@@ -24,9 +24,9 @@ class Arr
/**
* Add an element to an array using "dot" notation if it doesn't exist.
*
* @param array $array
* @param array $array
* @param string $key
* @param mixed $value
* @param mixed $value
* @return array
*/
public static function add($array, $key, $value)
@@ -41,7 +41,7 @@ class Arr
/**
* Collapse an array of arrays into a single array.
*
* @param array $array
* @param iterable $array
* @return array
*/
public static function collapse($array)
@@ -64,7 +64,7 @@ class Arr
/**
* Cross join the given arrays, returning all possible permutations.
*
* @param array ...$arrays
* @param iterable ...$arrays
* @return array
*/
public static function crossJoin(...$arrays)
@@ -102,7 +102,7 @@ class Arr
/**
* Flatten a multi-dimensional associative array with dots.
*
* @param array $array
* @param iterable $array
* @param string $prepend
* @return array
*/
@@ -154,7 +154,7 @@ class Arr
/**
* Return the first element in an array passing a given truth test.
*
* @param array $array
* @param iterable $array
* @param callable|null $callback
* @param mixed $default
* @return mixed
@@ -172,7 +172,7 @@ class Arr
}
foreach ($array as $key => $value) {
if (call_user_func($callback, $value, $key)) {
if ($callback($value, $key)) {
return $value;
}
}
@@ -200,7 +200,7 @@ class Arr
/**
* Flatten a multi-dimensional array into a single level.
*
* @param array $array
* @param iterable $array
* @param int $depth
* @return array
*/
@@ -275,8 +275,8 @@ class Arr
* Get an item from an array using "dot" notation.
*
* @param \ArrayAccess|array $array
* @param string|int $key
* @param mixed $default
* @param string|int|null $key
* @param mixed $default
* @return mixed
*/
public static function get($array, $key, $default = null)
@@ -342,6 +342,38 @@ class Arr
return true;
}
/**
* Determine if any of the keys exist in an array using "dot" notation.
*
* @param \ArrayAccess|array $array
* @param string|array $keys
* @return bool
*/
public static function hasAny($array, $keys)
{
if (is_null($keys)) {
return false;
}
$keys = (array) $keys;
if (! $array) {
return false;
}
if ($keys === []) {
return false;
}
foreach ($keys as $key) {
if (static::has($array, $key)) {
return true;
}
}
return false;
}
/**
* Determines if an array is associative.
*
@@ -372,7 +404,7 @@ class Arr
/**
* Pluck an array of values from an array.
*
* @param array $array
* @param iterable $array
* @param string|array $value
* @param string|array|null $key
* @return array
@@ -443,9 +475,9 @@ class Arr
/**
* Get a value from the array, and remove it.
*
* @param array $array
* @param array $array
* @param string $key
* @param mixed $default
* @param mixed $default
* @return mixed
*/
public static function pull(&$array, $key, $default = null)
@@ -502,9 +534,9 @@ class Arr
*
* If no key is given to the method, the entire array will be replaced.
*
* @param array $array
* @param array $array
* @param string $key
* @param mixed $value
* @param mixed $value
* @return array
*/
public static function set(&$array, $key, $value)
@@ -596,7 +628,7 @@ class Arr
*/
public static function query($array)
{
return http_build_query($array, null, '&', PHP_QUERY_RFC3986);
return http_build_query($array, '', '&', PHP_QUERY_RFC3986);
}
/**

File diff suppressed because it is too large Load Diff

View File

@@ -3,8 +3,8 @@
namespace Illuminate\Support;
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;
class Composer
{

View File

@@ -17,6 +17,8 @@ class ConfigurationUrlParser
'postgres' => 'pgsql',
'postgresql' => 'pgsql',
'sqlite3' => 'sqlite',
'redis' => 'tcp',
'rediss' => 'tls',
];
/**
@@ -39,12 +41,16 @@ class ConfigurationUrlParser
return $config;
}
$parsedUrl = $this->parseUrl($url);
$rawComponents = $this->parseUrl($url);
$decodedComponents = $this->parseStringsToNativeTypes(
array_map('rawurldecode', $rawComponents)
);
return array_merge(
$config,
$this->getPrimaryOptions($parsedUrl),
$this->getQueryOptions($parsedUrl)
$this->getPrimaryOptions($decodedComponents),
$this->getQueryOptions($rawComponents)
);
}
@@ -95,7 +101,7 @@ class ConfigurationUrlParser
{
$path = $url['path'] ?? null;
return $path ? substr($path, 1) : null;
return $path && $path !== '/' ? substr($path, 1) : null;
}
/**
@@ -124,6 +130,8 @@ class ConfigurationUrlParser
*
* @param string $url
* @return array
*
* @throws \InvalidArgumentException
*/
protected function parseUrl($url)
{
@@ -135,9 +143,7 @@ class ConfigurationUrlParser
throw new InvalidArgumentException('The database configuration URL is malformed.');
}
return $this->parseStringsToNativeTypes(
array_map('rawurldecode', $parsedUrl)
);
return $parsedUrl;
}
/**

View File

@@ -115,6 +115,7 @@ class DateFactory
* Use the given handler when generating dates (class name, callable, or factory).
*
* @param mixed $handler
* @return mixed
*
* @throws \InvalidArgumentException
*/

View File

@@ -0,0 +1,920 @@
<?php
namespace Illuminate\Support;
use Countable;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Jsonable;
use IteratorAggregate;
use JsonSerializable;
interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, JsonSerializable
{
/**
* Create a new collection instance if the value isn't one already.
*
* @param mixed $items
* @return static
*/
public static function make($items = []);
/**
* Create a new instance by invoking the callback a given amount of times.
*
* @param int $number
* @param callable $callback
* @return static
*/
public static function times($number, callable $callback = null);
/**
* Wrap the given value in a collection if applicable.
*
* @param mixed $value
* @return static
*/
public static function wrap($value);
/**
* Get the underlying items from the given collection if applicable.
*
* @param array|static $value
* @return array
*/
public static function unwrap($value);
/**
* Get all items in the enumerable.
*
* @return array
*/
public function all();
/**
* Alias for the "avg" method.
*
* @param callable|string|null $callback
* @return mixed
*/
public function average($callback = null);
/**
* Get the median of a given key.
*
* @param string|array|null $key
* @return mixed
*/
public function median($key = null);
/**
* Get the mode of a given key.
*
* @param string|array|null $key
* @return array|null
*/
public function mode($key = null);
/**
* Collapse the items into a single enumerable.
*
* @return static
*/
public function collapse();
/**
* Alias for the "contains" method.
*
* @param mixed $key
* @param mixed $operator
* @param mixed $value
* @return bool
*/
public function some($key, $operator = null, $value = null);
/**
* Determine if an item exists, using strict comparison.
*
* @param mixed $key
* @param mixed $value
* @return bool
*/
public function containsStrict($key, $value = null);
/**
* Get the average value of a given key.
*
* @param callable|string|null $callback
* @return mixed
*/
public function avg($callback = null);
/**
* Determine if an item exists in the enumerable.
*
* @param mixed $key
* @param mixed $operator
* @param mixed $value
* @return bool
*/
public function contains($key, $operator = null, $value = null);
/**
* Dump the collection and end the script.
*
* @param mixed ...$args
* @return void
*/
public function dd(...$args);
/**
* Dump the collection.
*
* @return $this
*/
public function dump();
/**
* Get the items that are not present in the given items.
*
* @param mixed $items
* @return static
*/
public function diff($items);
/**
* Get the items that are not present in the given items, using the callback.
*
* @param mixed $items
* @param callable $callback
* @return static
*/
public function diffUsing($items, callable $callback);
/**
* Get the items whose keys and values are not present in the given items.
*
* @param mixed $items
* @return static
*/
public function diffAssoc($items);
/**
* Get the items whose keys and values are not present in the given items, using the callback.
*
* @param mixed $items
* @param callable $callback
* @return static
*/
public function diffAssocUsing($items, callable $callback);
/**
* Get the items whose keys are not present in the given items.
*
* @param mixed $items
* @return static
*/
public function diffKeys($items);
/**
* Get the items whose keys are not present in the given items, using the callback.
*
* @param mixed $items
* @param callable $callback
* @return static
*/
public function diffKeysUsing($items, callable $callback);
/**
* Retrieve duplicate items.
*
* @param callable|null $callback
* @param bool $strict
* @return static
*/
public function duplicates($callback = null, $strict = false);
/**
* Retrieve duplicate items using strict comparison.
*
* @param callable|null $callback
* @return static
*/
public function duplicatesStrict($callback = null);
/**
* Execute a callback over each item.
*
* @param callable $callback
* @return $this
*/
public function each(callable $callback);
/**
* Execute a callback over each nested chunk of items.
*
* @param callable $callback
* @return static
*/
public function eachSpread(callable $callback);
/**
* Determine if all items pass the given truth test.
*
* @param string|callable $key
* @param mixed $operator
* @param mixed $value
* @return bool
*/
public function every($key, $operator = null, $value = null);
/**
* Get all items except for those with the specified keys.
*
* @param mixed $keys
* @return static
*/
public function except($keys);
/**
* Run a filter over each of the items.
*
* @param callable|null $callback
* @return static
*/
public function filter(callable $callback = null);
/**
* Apply the callback if the value is truthy.
*
* @param bool $value
* @param callable $callback
* @param callable $default
* @return static|mixed
*/
public function when($value, callable $callback, callable $default = null);
/**
* Apply the callback if the collection is empty.
*
* @param callable $callback
* @param callable $default
* @return static|mixed
*/
public function whenEmpty(callable $callback, callable $default = null);
/**
* Apply the callback if the collection is not empty.
*
* @param callable $callback
* @param callable $default
* @return static|mixed
*/
public function whenNotEmpty(callable $callback, callable $default = null);
/**
* Apply the callback if the value is falsy.
*
* @param bool $value
* @param callable $callback
* @param callable $default
* @return static|mixed
*/
public function unless($value, callable $callback, callable $default = null);
/**
* Apply the callback unless the collection is empty.
*
* @param callable $callback
* @param callable $default
* @return static|mixed
*/
public function unlessEmpty(callable $callback, callable $default = null);
/**
* Apply the callback unless the collection is not empty.
*
* @param callable $callback
* @param callable $default
* @return static|mixed
*/
public function unlessNotEmpty(callable $callback, callable $default = null);
/**
* Filter items by the given key value pair.
*
* @param string $key
* @param mixed $operator
* @param mixed $value
* @return static
*/
public function where($key, $operator = null, $value = null);
/**
* Filter items by the given key value pair using strict comparison.
*
* @param string $key
* @param mixed $value
* @return static
*/
public function whereStrict($key, $value);
/**
* Filter items by the given key value pair.
*
* @param string $key
* @param mixed $values
* @param bool $strict
* @return static
*/
public function whereIn($key, $values, $strict = false);
/**
* Filter items by the given key value pair using strict comparison.
*
* @param string $key
* @param mixed $values
* @return static
*/
public function whereInStrict($key, $values);
/**
* Filter items such that the value of the given key is between the given values.
*
* @param string $key
* @param array $values
* @return static
*/
public function whereBetween($key, $values);
/**
* Filter items such that the value of the given key is not between the given values.
*
* @param string $key
* @param array $values
* @return static
*/
public function whereNotBetween($key, $values);
/**
* Filter items by the given key value pair.
*
* @param string $key
* @param mixed $values
* @param bool $strict
* @return static
*/
public function whereNotIn($key, $values, $strict = false);
/**
* Filter items by the given key value pair using strict comparison.
*
* @param string $key
* @param mixed $values
* @return static
*/
public function whereNotInStrict($key, $values);
/**
* Filter the items, removing any items that don't match the given type.
*
* @param string $type
* @return static
*/
public function whereInstanceOf($type);
/**
* Get the first item from the enumerable passing the given truth test.
*
* @param callable|null $callback
* @param mixed $default
* @return mixed
*/
public function first(callable $callback = null, $default = null);
/**
* Get the first item by the given key value pair.
*
* @param string $key
* @param mixed $operator
* @param mixed $value
* @return mixed
*/
public function firstWhere($key, $operator = null, $value = null);
/**
* Flip the values with their keys.
*
* @return static
*/
public function flip();
/**
* Get an item from the collection by key.
*
* @param mixed $key
* @param mixed $default
* @return mixed
*/
public function get($key, $default = null);
/**
* Group an associative array by a field or using a callback.
*
* @param array|callable|string $groupBy
* @param bool $preserveKeys
* @return static
*/
public function groupBy($groupBy, $preserveKeys = false);
/**
* Key an associative array by a field or using a callback.
*
* @param callable|string $keyBy
* @return static
*/
public function keyBy($keyBy);
/**
* Determine if an item exists in the collection by key.
*
* @param mixed $key
* @return bool
*/
public function has($key);
/**
* Concatenate values of a given key as a string.
*
* @param string $value
* @param string $glue
* @return string
*/
public function implode($value, $glue = null);
/**
* Intersect the collection with the given items.
*
* @param mixed $items
* @return static
*/
public function intersect($items);
/**
* Intersect the collection with the given items by key.
*
* @param mixed $items
* @return static
*/
public function intersectByKeys($items);
/**
* Determine if the collection is empty or not.
*
* @return bool
*/
public function isEmpty();
/**
* Determine if the collection is not empty.
*
* @return bool
*/
public function isNotEmpty();
/**
* Join all items from the collection using a string. The final items can use a separate glue string.
*
* @param string $glue
* @param string $finalGlue
* @return string
*/
public function join($glue, $finalGlue = '');
/**
* Get the keys of the collection items.
*
* @return static
*/
public function keys();
/**
* Get the last item from the collection.
*
* @param callable|null $callback
* @param mixed $default
* @return mixed
*/
public function last(callable $callback = null, $default = null);
/**
* Run a map over each of the items.
*
* @param callable $callback
* @return static
*/
public function map(callable $callback);
/**
* Run a map over each nested chunk of items.
*
* @param callable $callback
* @return static
*/
public function mapSpread(callable $callback);
/**
* Run a dictionary map over the items.
*
* The callback should return an associative array with a single key/value pair.
*
* @param callable $callback
* @return static
*/
public function mapToDictionary(callable $callback);
/**
* Run a grouping map over the items.
*
* The callback should return an associative array with a single key/value pair.
*
* @param callable $callback
* @return static
*/
public function mapToGroups(callable $callback);
/**
* Run an associative map over each of the items.
*
* The callback should return an associative array with a single key/value pair.
*
* @param callable $callback
* @return static
*/
public function mapWithKeys(callable $callback);
/**
* Map a collection and flatten the result by a single level.
*
* @param callable $callback
* @return static
*/
public function flatMap(callable $callback);
/**
* Map the values into a new class.
*
* @param string $class
* @return static
*/
public function mapInto($class);
/**
* Merge the collection with the given items.
*
* @param mixed $items
* @return static
*/
public function merge($items);
/**
* Recursively merge the collection with the given items.
*
* @param mixed $items
* @return static
*/
public function mergeRecursive($items);
/**
* Create a collection by using this collection for keys and another for its values.
*
* @param mixed $values
* @return static
*/
public function combine($values);
/**
* Union the collection with the given items.
*
* @param mixed $items
* @return static
*/
public function union($items);
/**
* Get the min value of a given key.
*
* @param callable|string|null $callback
* @return mixed
*/
public function min($callback = null);
/**
* Get the max value of a given key.
*
* @param callable|string|null $callback
* @return mixed
*/
public function max($callback = null);
/**
* Create a new collection consisting of every n-th element.
*
* @param int $step
* @param int $offset
* @return static
*/
public function nth($step, $offset = 0);
/**
* Get the items with the specified keys.
*
* @param mixed $keys
* @return static
*/
public function only($keys);
/**
* "Paginate" the collection by slicing it into a smaller collection.
*
* @param int $page
* @param int $perPage
* @return static
*/
public function forPage($page, $perPage);
/**
* Partition the collection into two arrays using the given callback or key.
*
* @param callable|string $key
* @param mixed $operator
* @param mixed $value
* @return static
*/
public function partition($key, $operator = null, $value = null);
/**
* Push all of the given items onto the collection.
*
* @param iterable $source
* @return static
*/
public function concat($source);
/**
* Get one or a specified number of items randomly from the collection.
*
* @param int|null $number
* @return static|mixed
*
* @throws \InvalidArgumentException
*/
public function random($number = null);
/**
* Reduce the collection to a single value.
*
* @param callable $callback
* @param mixed $initial
* @return mixed
*/
public function reduce(callable $callback, $initial = null);
/**
* Replace the collection items with the given items.
*
* @param mixed $items
* @return static
*/
public function replace($items);
/**
* Recursively replace the collection items with the given items.
*
* @param mixed $items
* @return static
*/
public function replaceRecursive($items);
/**
* Reverse items order.
*
* @return static
*/
public function reverse();
/**
* Search the collection for a given value and return the corresponding key if successful.
*
* @param mixed $value
* @param bool $strict
* @return mixed
*/
public function search($value, $strict = false);
/**
* Shuffle the items in the collection.
*
* @param int $seed
* @return static
*/
public function shuffle($seed = null);
/**
* Skip the first {$count} items.
*
* @param int $count
* @return static
*/
public function skip($count);
/**
* Get a slice of items from the enumerable.
*
* @param int $offset
* @param int $length
* @return static
*/
public function slice($offset, $length = null);
/**
* Split a collection into a certain number of groups.
*
* @param int $numberOfGroups
* @return static
*/
public function split($numberOfGroups);
/**
* Chunk the collection into chunks of the given size.
*
* @param int $size
* @return static
*/
public function chunk($size);
/**
* Sort through each item with a callback.
*
* @param callable|null $callback
* @return static
*/
public function sort(callable $callback = null);
/**
* Sort the collection using the given callback.
*
* @param callable|string $callback
* @param int $options
* @param bool $descending
* @return static
*/
public function sortBy($callback, $options = SORT_REGULAR, $descending = false);
/**
* Sort the collection in descending order using the given callback.
*
* @param callable|string $callback
* @param int $options
* @return static
*/
public function sortByDesc($callback, $options = SORT_REGULAR);
/**
* Sort the collection keys.
*
* @param int $options
* @param bool $descending
* @return static
*/
public function sortKeys($options = SORT_REGULAR, $descending = false);
/**
* Sort the collection keys in descending order.
*
* @param int $options
* @return static
*/
public function sortKeysDesc($options = SORT_REGULAR);
/**
* Get the sum of the given values.
*
* @param callable|string|null $callback
* @return mixed
*/
public function sum($callback = null);
/**
* Take the first or last {$limit} items.
*
* @param int $limit
* @return static
*/
public function take($limit);
/**
* Pass the collection to the given callback and then return it.
*
* @param callable $callback
* @return $this
*/
public function tap(callable $callback);
/**
* Pass the enumerable to the given callback and return the result.
*
* @param callable $callback
* @return mixed
*/
public function pipe(callable $callback);
/**
* Get the values of a given key.
*
* @param string|array $value
* @param string|null $key
* @return static
*/
public function pluck($value, $key = null);
/**
* Create a collection of all elements that do not pass a given truth test.
*
* @param callable|mixed $callback
* @return static
*/
public function reject($callback = true);
/**
* 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);
/**
* Return only unique items from the collection array using strict comparison.
*
* @param string|callable|null $key
* @return static
*/
public function uniqueStrict($key = null);
/**
* Reset the keys on the underlying array.
*
* @return static
*/
public function values();
/**
* Pad collection to the specified length with a value.
*
* @param int $size
* @param mixed $value
* @return static
*/
public function pad($size, $value);
/**
* Count the number of items in the collection using a given truth test.
*
* @param callable|null $callback
* @return static
*/
public function countBy($callback = null);
/**
* Collect the values into a collection.
*
* @return \Illuminate\Support\Collection
*/
public function collect();
/**
* Convert the collection to its string representation.
*
* @return string
*/
public function __toString();
/**
* Add a method to the list of proxied methods.
*
* @param string $method
* @return void
*/
public static function proxy($method);
/**
* Dynamically access collection proxies.
*
* @param string $key
* @return mixed
*
* @throws \Exception
*/
public function __get($key);
}

View File

@@ -0,0 +1,127 @@
<?php
namespace Illuminate\Support;
use Dotenv\Environment\Adapter\EnvConstAdapter;
use Dotenv\Environment\Adapter\PutenvAdapter;
use Dotenv\Environment\Adapter\ServerConstAdapter;
use Dotenv\Environment\DotenvFactory;
use PhpOption\Option;
class Env
{
/**
* Indicates if the putenv adapter is enabled.
*
* @var bool
*/
protected static $putenv = true;
/**
* The environment factory instance.
*
* @var \Dotenv\Environment\FactoryInterface|null
*/
protected static $factory;
/**
* The environment variables instance.
*
* @var \Dotenv\Environment\VariablesInterface|null
*/
protected static $variables;
/**
* Enable the putenv adapter.
*
* @return void
*/
public static function enablePutenv()
{
static::$putenv = true;
static::$factory = null;
static::$variables = null;
}
/**
* Disable the putenv adapter.
*
* @return void
*/
public static function disablePutenv()
{
static::$putenv = false;
static::$factory = null;
static::$variables = null;
}
/**
* Get the environment factory instance.
*
* @return \Dotenv\Environment\FactoryInterface
*/
public static function getFactory()
{
if (static::$factory === null) {
$adapters = array_merge(
[new EnvConstAdapter, new ServerConstAdapter],
static::$putenv ? [new PutenvAdapter] : []
);
static::$factory = new DotenvFactory($adapters);
}
return static::$factory;
}
/**
* Get the environment variables instance.
*
* @return \Dotenv\Environment\VariablesInterface
*/
public static function getVariables()
{
if (static::$variables === null) {
static::$variables = static::getFactory()->createImmutable();
}
return static::$variables;
}
/**
* Gets the value of an environment variable.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
public static function get($key, $default = null)
{
return Option::fromValue(static::getVariables()->get($key))
->map(function ($value) {
switch (strtolower($value)) {
case 'true':
case '(true)':
return true;
case 'false':
case '(false)':
return false;
case 'empty':
case '(empty)':
return '';
case 'null':
case '(null)':
return;
}
if (preg_match('/\A([\'"])(.*)\1\z/', $value, $matches)) {
return $matches[2];
}
return $value;
})
->getOrCall(function () use ($default) {
return value($default);
});
}
}

View File

@@ -19,6 +19,7 @@ namespace Illuminate\Support\Facades;
* @method static \Illuminate\Support\ServiceProvider register(\Illuminate\Support\ServiceProvider|string $provider, bool $force = false)
* @method static void registerDeferredProvider(string $provider, string $service = null)
* @method static \Illuminate\Support\ServiceProvider resolveProvider(string $provider)
* @method static mixed make($abstract, array $parameters = [])
* @method static void boot()
* @method static void booting(callable $callback)
* @method static void booted(callable $callback)

View File

@@ -11,6 +11,7 @@ use Illuminate\Contracts\Console\Kernel as ConsoleKernelContract;
* @method static array all()
* @method static string output()
* @method static void terminate(\Symfony\Component\Console\Input\InputInterface $input, int $status)
* @method static \Illuminate\Foundation\Console\ClosureCommand command(string $command, callable $callback)
*
* @see \Illuminate\Contracts\Console\Kernel
*/

View File

@@ -3,7 +3,7 @@
namespace Illuminate\Support\Facades;
/**
* @method static mixed guard(string|null $name = null)
* @method static \Illuminate\Contracts\Auth\Guard|\Illuminate\Contracts\Auth\StatefulGuard guard(string|null $name = null)
* @method static void shouldUse(string $name);
* @method static bool check()
* @method static bool guest()
@@ -19,7 +19,7 @@ namespace Illuminate\Support\Facades;
* @method static bool viaRemember()
* @method static void logout()
* @method static \Symfony\Component\HttpFoundation\Response|null onceBasic(string $field = 'email',array $extraConditions = [])
* @method static null|bool logoutOtherDevices(string $password, string $attribute = 'password')
* @method static bool|null logoutOtherDevices(string $password, string $attribute = 'password')
* @method static \Illuminate\Contracts\Auth\UserProvider|null createUserProvider(string $provider = null)
* @method static \Illuminate\Auth\AuthManager extend(string $driver, \Closure $callback)
* @method static \Illuminate\Auth\AuthManager provider(string $name, \Closure $callback)

View File

@@ -6,8 +6,9 @@ use Illuminate\Contracts\Broadcasting\Factory as BroadcastingFactoryContract;
/**
* @method static void connection($name = null);
* @method static \Illuminate\Broadcasting\Broadcasters\Broadcaster channel(string $channel, callable|string $callback)
* @method static \Illuminate\Broadcasting\Broadcasters\Broadcaster channel(string $channel, callable|string $callback, array $options = [])
* @method static mixed auth(\Illuminate\Http\Request $request)
* @method static void routes()
*
* @see \Illuminate\Contracts\Broadcasting\Factory
*/

View File

@@ -2,8 +2,8 @@
namespace Illuminate\Support\Facades;
use Illuminate\Support\Testing\Fakes\BusFake;
use Illuminate\Contracts\Bus\Dispatcher as BusDispatcherContract;
use Illuminate\Support\Testing\Fakes\BusFake;
/**
* @method static mixed dispatch($command)
@@ -12,6 +12,9 @@ use Illuminate\Contracts\Bus\Dispatcher as BusDispatcherContract;
* @method static bool|mixed getCommandHandler($command)
* @method static \Illuminate\Contracts\Bus\Dispatcher pipeThrough(array $pipes)
* @method static \Illuminate\Contracts\Bus\Dispatcher map(array $map)
* @method static void assertDispatched(string $command, callable|int $callback = null)
* @method static void assertDispatchedTimes(string $command, int $times = 1)
* @method static void assertNotDispatched(string $command, callable|int $callback = null)
*
* @see \Illuminate\Contracts\Bus\Dispatcher
*/
@@ -20,11 +23,12 @@ class Bus extends Facade
/**
* Replace the bound instance with a fake.
*
* @param array|string $jobsToFake
* @return \Illuminate\Support\Testing\Fakes\BusFake
*/
public static function fake()
public static function fake($jobsToFake = [])
{
static::swap($fake = new BusFake);
static::swap($fake = new BusFake(static::getFacadeRoot(), $jobsToFake));
return $fake;
}

View File

@@ -25,8 +25,8 @@ class Cookie extends Facade
/**
* Retrieve a cookie from the request.
*
* @param string $key
* @param mixed $default
* @param string|null $key
* @param mixed $default
* @return string|array|null
*/
public static function get($key = null, $default = null)

View File

@@ -23,6 +23,12 @@ namespace Illuminate\Support\Facades;
* @method static void rollBack()
* @method static int transactionLevel()
* @method static array pretend(\Closure $callback)
* @method static void listen(\Closure $callback)
* @method static void enableQueryLog()
* @method static void disableQueryLog()
* @method static bool logging()
* @method static array getQueryLog()
* @method static void flushQueryLog()
*
* @see \Illuminate\Database\DatabaseManager
* @see \Illuminate\Database\Connection

View File

@@ -75,6 +75,11 @@ use Illuminate\Support\DateFactory;
* @method static string singularUnit(string $unit)
* @method static \Illuminate\Support\Carbon today($tz = null)
* @method static \Illuminate\Support\Carbon tomorrow($tz = null)
* @method static mixed use(mixed $handler)
* @method static void useCallable(callable $callable)
* @method static void useClass(string $class)
* @method static void useFactory(object $factory)
* @method static void useDefault()
* @method static void useMonthsOverflow($monthsOverflow = true)
* @method static \Illuminate\Support\Carbon useStrictMode($strictModeEnabled = true)
* @method static void useYearsOverflow($yearsOverflow = true)

View File

@@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Testing\Fakes\EventFake;
/**
* @method static void listen(string|array $events, mixed $listener)
* @method static void listen(string|array $events, \Closure|string $listener)
* @method static bool hasListeners(string $eventName)
* @method static void push(string $event, array $payload = [])
* @method static void flush(string $event)
@@ -19,6 +19,9 @@ use Illuminate\Support\Testing\Fakes\EventFake;
* @method static void forget(string $event)
* @method static void forgetPushed()
* @method static \Illuminate\Events\Dispatcher setQueueResolver(callable $resolver)
* @method static void assertDispatched(string $event, callable|int $callback = null)
* @method static void assertDispatchedTimes(string $event, int $times = 1)
* @method static void assertNotDispatched(string $event, callable|int $callback = null)
*
* @see \Illuminate\Events\Dispatcher
*/
@@ -35,6 +38,7 @@ class Event extends Facade
static::swap($fake = new EventFake(static::getFacadeRoot(), $eventsToFake));
Model::setEventDispatcher($fake);
Cache::refreshEventDispatcher();
return $fake;
}
@@ -56,6 +60,7 @@ class Event extends Facade
static::swap($originalDispatcher);
Model::setEventDispatcher($originalDispatcher);
Cache::refreshEventDispatcher();
});
}

View File

@@ -4,8 +4,8 @@ namespace Illuminate\Support\Facades;
use Closure;
use Mockery;
use RuntimeException;
use Mockery\MockInterface;
use RuntimeException;
abstract class Facade
{
@@ -31,7 +31,13 @@ abstract class Facade
*/
public static function resolved(Closure $callback)
{
static::$app->afterResolving(static::getFacadeAccessor(), function ($service) use ($callback) {
$accessor = static::getFacadeAccessor();
if (static::$app->resolved($accessor) === true) {
$callback(static::getFacadeRoot());
}
static::$app->afterResolving($accessor, function ($service) use ($callback) {
$callback($service);
});
}
@@ -52,6 +58,22 @@ abstract class Facade
}
}
/**
* Initiate a partial mock on the facade.
*
* @return \Mockery\MockInterface
*/
public static function partialMock()
{
$name = static::getFacadeAccessor();
$mock = static::isMock()
? static::$resolvedInstance[$name]
: static::createFreshMockInstance();
return $mock->makePartial();
}
/**
* Initiate a mock expectation on the facade.
*
@@ -71,7 +93,7 @@ abstract class Facade
/**
* Create a fresh mock instance for the given class.
*
* @return \Mockery\Expectation
* @return \Mockery\MockInterface
*/
protected static function createFreshMockInstance()
{
@@ -223,7 +245,7 @@ abstract class Facade
* Handle dynamic, static calls to the object.
*
* @param string $method
* @param array $args
* @param array $args
* @return mixed
*
* @throws \RuntimeException

View File

@@ -34,6 +34,7 @@ namespace Illuminate\Support\Facades;
* @method static \Symfony\Component\Finder\SplFileInfo[] files(string $directory, bool $hidden = false)
* @method static \Symfony\Component\Finder\SplFileInfo[] allFiles(string $directory, bool $hidden = false)
* @method static array directories(string $directory)
* @method static void ensureDirectoryExists(string $path, int $mode = 0755, bool $recursive = true)
* @method static bool makeDirectory(string $path, int $mode = 0755, bool $recursive = false, bool $force = false)
* @method static bool moveDirectory(string $from, string $to, bool $overwrite = false)
* @method static bool copyDirectory(string $directory, string $destination, int|null $options = null)

View File

@@ -19,6 +19,8 @@ use Illuminate\Contracts\Auth\Access\Gate as GateContract;
* @method static mixed getPolicyFor(object|string $class)
* @method static \Illuminate\Contracts\Auth\Access\Gate forUser(\Illuminate\Contracts\Auth\Authenticatable|mixed $user)
* @method static array abilities()
* @method static \Illuminate\Auth\Access\Response inspect(string $ability, array|mixed $arguments = [])
* @method static \Illuminate\Auth\Access\Gate guessPolicyNamesUsing(callable $callback)
*
* @see \Illuminate\Contracts\Auth\Access\Gate
*/

View File

@@ -1,114 +0,0 @@
<?php
namespace Illuminate\Support\Facades;
/**
* @method static bool matchesType(string $actual, string $type)
* @method static bool isJson()
* @method static bool expectsJson()
* @method static bool wantsJson()
* @method static bool accepts(string|array $contentTypes)
* @method static bool prefers(string|array $contentTypes)
* @method static bool acceptsAnyContentType()
* @method static bool acceptsJson()
* @method static bool acceptsHtml()
* @method static string format($default = 'html')
* @method static string|array old(string|null $key = null, string|array|null $default = null)
* @method static void flash()
* @method static void flashOnly(array|mixed $keys)
* @method static void flashExcept(array|mixed $keys)
* @method static void flush()
* @method static string|array|null server(string|null $key = null, string|array|null $default = null)
* @method static bool hasHeader(string $key)
* @method static string|array|null header(string|null $key = null, string|array|null $default = null)
* @method static string|null bearerToken()
* @method static bool exists(string|array $key)
* @method static bool has(string|array $key)
* @method static bool hasAny(string|array $key)
* @method static bool filled(string|array $key)
* @method static bool anyFilled(string|array $key)
* @method static array keys()
* @method static array all(array|mixed|null $keys = null)
* @method static string|array|null input(string|null $key = null, string|array|null $default = null)
* @method static array only(array|mixed $keys)
* @method static array except(array|mixed $keys)
* @method static string|array|null query(string|null $key = null, string|array|null $default = null)
* @method static string|array|null post(string|null $key = null, string|array|null $default = null)
* @method static bool hasCookie(string $key)
* @method static string|array|null cookie(string|null $key = null, string|array|null $default = null)
* @method static array allFiles()
* @method static bool hasFile(string $key)
* @method static \Illuminate\Http\UploadedFile|\Illuminate\Http\UploadedFile[]|array|null file(string|null $key = null, mixed $default = null)
* @method static \Illuminate\Http\Request capture()
* @method static \Illuminate\Http\Request instance()
* @method static string method()
* @method static string root()
* @method static string url()
* @method static string fullUrl()
* @method static string fullUrlWithQuery(array $query)
* @method static string path()
* @method static string decodedPath()
* @method static string|null segment(int $index, string|null $default = null)
* @method static array segments()
* @method static bool is(mixed ...$patterns)
* @method static bool routeIs(mixed ...$patterns)
* @method static bool fullUrlIs(mixed ...$patterns)
* @method static bool ajax()
* @method static bool pjax()
* @method static bool prefetch()
* @method static bool secure()
* @method static string|null ip()
* @method static array ips()
* @method static string userAgent()
* @method static \Illuminate\Http\Request merge(array $input)
* @method static \Illuminate\Http\Request replace(array $input)
* @method static \Symfony\Component\HttpFoundation\ParameterBag|mixed json(string|null $key = null, mixed $default = null)
* @method static \Illuminate\Http\Request createFrom(\Illuminate\Http\Request $from, \Illuminate\Http\Request|null $to = null)
* @method static \Illuminate\Http\Request createFromBase(\Symfony\Component\HttpFoundation\Request $request)
* @method static \Illuminate\Http\Request duplicate(array|null $query = null, array|null $request = null, array|null $attributes = null, array|null $cookies = null, array|null $files = null, array|null $server = null)
* @method static mixed filterFiles(mixed $files)
* @method static \Illuminate\Session\Store session()
* @method static \Illuminate\Session\Store|null getSession()
* @method static void setLaravelSession(\Illuminate\Contracts\Session\Session $session)
* @method static mixed user(string|null $guard = null)
* @method static \Illuminate\Routing\Route|object|string route(string|null $param = null, string|null $default = null)
* @method static string fingerprint()
* @method static \Illuminate\Http\Request setJson(\Symfony\Component\HttpFoundation\ParameterBag $json)
* @method static \Closure getUserResolver()
* @method static \Illuminate\Http\Request setUserResolver(\Closure $callback)
* @method static \Closure getRouteResolver()
* @method static \Illuminate\Http\Request setRouteResolver(\Closure $callback)
* @method static array toArray()
* @method static bool offsetExists(string $offset)
* @method static mixed offsetGet(string $offset)
* @method static void offsetSet(string $offset, mixed $value)
* @method static void offsetUnset(string $offset)
*
* @see \Illuminate\Http\Request
*/
class Input extends Facade
{
/**
* Get an item from the input data.
*
* This method is used for all request verbs (GET, POST, PUT, and DELETE)
*
* @param string|null $key
* @param mixed $default
* @return mixed
*/
public static function get($key = null, $default = null)
{
return static::$app['request']->input($key, $default);
}
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'request';
}
}

View File

@@ -3,11 +3,10 @@
namespace Illuminate\Support\Facades;
/**
* @method static mixed trans(string $key, array $replace = [], string $locale = null)
* @method static string transChoice(string $key, int|array|\Countable $number, array $replace = [], string $locale = null)
* @method static mixed get(string $key, array $replace = [], string $locale = null, bool $fallback = true)
* @method static string choice(string $key, \Countable|int|array $number, array $replace = [], string $locale = null)
* @method static string getLocale()
* @method static void setLocale(string $locale)
* @method static string|array|null get(string $key, array $replace = [], string $locale = null, bool $fallback = true)
*
* @see \Illuminate\Translation\Translator
*/

View File

@@ -12,7 +12,7 @@ namespace Illuminate\Support\Facades;
* @method static void info(string $message, array $context = [])
* @method static void debug(string $message, array $context = [])
* @method static void log($level, string $message, array $context = [])
* @method static mixed channel(string $channel = null)
* @method static \Psr\Log\LoggerInterface channel(string $channel = null)
* @method static \Psr\Log\LoggerInterface stack(array $channels, string $channel = null)
*
* @see \Illuminate\Log\Logger

View File

@@ -8,15 +8,15 @@ use Illuminate\Support\Testing\Fakes\MailFake;
* @method static \Illuminate\Mail\PendingMail to($users)
* @method static \Illuminate\Mail\PendingMail bcc($users)
* @method static void raw(string $text, $callback)
* @method static void send(string|array|\Illuminate\Contracts\Mail\Mailable $view, array $data = [], \Closure|string $callback = null)
* @method static void send(\Illuminate\Contracts\Mail\Mailable|string|array $view, array $data = [], \Closure|string $callback = null)
* @method static array failures()
* @method static mixed queue(string|array|\Illuminate\Contracts\Mail\Mailable $view, string $queue = null)
* @method static mixed later(\DateTimeInterface|\DateInterval|int $delay, string|array|\Illuminate\Contracts\Mail\Mailable $view, string $queue = null)
* @method static void assertSent(string $mailable, \Closure|string $callback = null)
* @method static void assertNotSent(string $mailable, \Closure|string $callback = null)
* @method static mixed queue(\Illuminate\Contracts\Mail\Mailable|string|array $view, string $queue = null)
* @method static mixed later(\DateTimeInterface|\DateInterval|int $delay, \Illuminate\Contracts\Mail\Mailable|string|array $view, string $queue = null)
* @method static void assertSent(string $mailable, callable|int $callback = null)
* @method static void assertNotSent(string $mailable, callable|int $callback = null)
* @method static void assertNothingSent()
* @method static void assertQueued(string $mailable, \Closure|string $callback = null)
* @method static void assertNotQueued(string $mailable, \Closure|string $callback = null)
* @method static void assertQueued(string $mailable, callable|int $callback = null)
* @method static void assertNotQueued(string $mailable, callable $callback = null)
* @method static void assertNothingQueued()
* @method static \Illuminate\Support\Collection sent(string $mailable, \Closure|string $callback = null)
* @method static bool hasSent(string $mailable)

View File

@@ -2,8 +2,8 @@
namespace Illuminate\Support\Facades;
use Illuminate\Notifications\ChannelManager;
use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Notifications\ChannelManager;
use Illuminate\Support\Testing\Fakes\NotificationFake;
/**
@@ -11,6 +11,13 @@ use Illuminate\Support\Testing\Fakes\NotificationFake;
* @method static void sendNow(\Illuminate\Support\Collection|array|mixed $notifiables, $notification)
* @method static mixed channel(string|null $name = null)
* @method static \Illuminate\Notifications\ChannelManager locale(string|null $locale)
* @method static void assertSentTo(mixed $notifiable, string $notification, callable $callback = null)
* @method static void assertSentToTimes(mixed $notifiable, string $notification, int $times = 1)
* @method static void assertNotSentTo(mixed $notifiable, string $notification, callable $callback = null)
* @method static void assertNothingSent()
* @method static void assertTimesSent(int $expectedCount, string $notification)
* @method static \Illuminate\Support\Collection sent(mixed $notifiable, string $notification, callable $callback = null)
* @method static bool hasSent(mixed $notifiable, string $notification)
*
* @see \Illuminate\Notifications\ChannelManager
*/

View File

@@ -7,8 +7,6 @@ use Illuminate\Contracts\Auth\PasswordBroker;
/**
* @method static string sendResetLink(array $credentials)
* @method static mixed reset(array $credentials, \Closure $callback)
* @method static void validator(\Closure $callback)
* @method static bool validateNewPassword(array $credentials)
*
* @see \Illuminate\Auth\Passwords\PasswordBroker
*/
@@ -35,13 +33,6 @@ class Password extends Facade
*/
const INVALID_USER = PasswordBroker::INVALID_USER;
/**
* Constant representing an invalid password.
*
* @var string
*/
const INVALID_PASSWORD = PasswordBroker::INVALID_PASSWORD;
/**
* Constant representing an invalid token.
*
@@ -49,6 +40,13 @@ class Password extends Facade
*/
const INVALID_TOKEN = PasswordBroker::INVALID_TOKEN;
/**
* Constant representing a throttled reset attempt.
*
* @var string
*/
const RESET_THROTTLED = PasswordBroker::RESET_THROTTLED;
/**
* Get the registered name of the component.
*

View File

@@ -15,6 +15,11 @@ use Illuminate\Support\Testing\Fakes\QueueFake;
* @method static \Illuminate\Contracts\Queue\Job|null pop(string $queue = null)
* @method static string getConnectionName()
* @method static \Illuminate\Contracts\Queue\Queue setConnectionName(string $name)
* @method static void assertNothingPushed()
* @method static void assertNotPushed(string $job, callable $callback = null)
* @method static void assertPushed(string $job, callable|int $callback = null)
* @method static void assertPushedOn(string $queue, string $job, callable|int $callback = null)
* @method static void assertPushedWithChain(string $job, array $expectedChain = [], callable $callback = null)
*
* @see \Illuminate\Queue\QueueManager
* @see \Illuminate\Queue\Queue

View File

@@ -7,7 +7,7 @@ namespace Illuminate\Support\Facades;
* @method static \Illuminate\Http\RedirectResponse back(int $status = 302, array $headers = [], $fallback = false)
* @method static \Illuminate\Http\RedirectResponse refresh(int $status = 302, array $headers = [])
* @method static \Illuminate\Http\RedirectResponse guest(string $path, int $status = 302, array $headers = [], bool $secure = null)
* @method static intended(string $default = '/', int $status = 302, array $headers = [], bool $secure = null)
* @method static \Illuminate\Http\RedirectResponse intended(string $default = '/', int $status = 302, array $headers = [], bool $secure = null)
* @method static \Illuminate\Http\RedirectResponse to(string $path, int $status = 302, array $headers = [], bool $secure = null)
* @method static \Illuminate\Http\RedirectResponse away(string $path, int $status = 302, array $headers = [])
* @method static \Illuminate\Http\RedirectResponse secure(string $path, int $status = 302, array $headers = [])

View File

@@ -4,6 +4,8 @@ namespace Illuminate\Support\Facades;
/**
* @method static \Illuminate\Redis\Connections\Connection connection(string $name = null)
* @method static \Illuminate\Redis\Limiters\ConcurrencyLimiterBuilder funnel(string $name)
* @method static \Illuminate\Redis\Limiters\DurationLimiterBuilder throttle(string $name)
*
* @see \Illuminate\Redis\RedisManager
* @see \Illuminate\Contracts\Redis\Factory

View File

@@ -3,6 +3,43 @@
namespace Illuminate\Support\Facades;
/**
* @method static bool matchesType(string $actual, string $type)
* @method static bool isJson()
* @method static bool expectsJson()
* @method static bool wantsJson()
* @method static bool accepts(string|array $contentTypes)
* @method static bool prefers(string|array $contentTypes)
* @method static bool acceptsAnyContentType()
* @method static bool acceptsJson()
* @method static bool acceptsHtml()
* @method static string format($default = 'html')
* @method static string|array old(string|null $key = null, string|array|null $default = null)
* @method static void flash()
* @method static void flashOnly(array|mixed $keys)
* @method static void flashExcept(array|mixed $keys)
* @method static void flush()
* @method static string|array|null server(string|null $key = null, string|array|null $default = null)
* @method static bool hasHeader(string $key)
* @method static string|array|null header(string|null $key = null, string|array|null $default = null)
* @method static string|null bearerToken()
* @method static bool exists(string|array $key)
* @method static bool has(string|array $key)
* @method static bool hasAny(string|array $key)
* @method static bool filled(string|array $key)
* @method static bool anyFilled(string|array $key)
* @method static array keys()
* @method static array all(array|mixed|null $keys = null)
* @method static string|array|null input(string|null $key = null, string|array|null $default = null)
* @method static array only(array|mixed $keys)
* @method static array except(array|mixed $keys)
* @method static string|array|null query(string|null $key = null, string|array|null $default = null)
* @method static string|array|null post(string|null $key = null, string|array|null $default = null)
* @method static bool hasCookie(string $key)
* @method static string|array|null cookie(string|null $key = null, string|array|null $default = null)
* @method static array allFiles()
* @method static bool hasFile(string $key)
* @method static \Illuminate\Http\UploadedFile|\Illuminate\Http\UploadedFile[]|array|null file(string|null $key = null, mixed $default = null)
* @method static \Illuminate\Http\Request capture()
* @method static \Illuminate\Http\Request instance()
* @method static string method()
* @method static string root()
@@ -13,23 +50,28 @@ namespace Illuminate\Support\Facades;
* @method static string decodedPath()
* @method static string|null segment(int $index, string|null $default = null)
* @method static array segments()
* @method static bool is(...$patterns)
* @method static bool routeIs(...$patterns)
* @method static bool fullUrlIs(...$patterns)
* @method static bool is(mixed ...$patterns)
* @method static bool routeIs(mixed ...$patterns)
* @method static bool fullUrlIs(mixed ...$patterns)
* @method static bool ajax()
* @method static bool pjax()
* @method static bool prefetch()
* @method static bool secure()
* @method static string ip()
* @method static string|null ip()
* @method static array ips()
* @method static string userAgent()
* @method static \Illuminate\Http\Request merge(array $input)
* @method static \Illuminate\Http\Request replace(array $input)
* @method static \Symfony\Component\HttpFoundation\ParameterBag|mixed json(string $key = null, $default = null)
* @method static \Symfony\Component\HttpFoundation\ParameterBag|mixed json(string|null $key = null, mixed $default = null)
* @method static \Illuminate\Http\Request createFrom(\Illuminate\Http\Request $from, \Illuminate\Http\Request|null $to = null)
* @method static \Illuminate\Http\Request createFromBase(\Symfony\Component\HttpFoundation\Request $request)
* @method static \Illuminate\Http\Request duplicate(array|null $query = null, array|null $request = null, array|null $attributes = null, array|null $cookies = null, array|null $files = null, array|null $server = null)
* @method static mixed filterFiles(mixed $files)
* @method static \Illuminate\Session\Store session()
* @method static \Illuminate\Session\Store|null getSession()
* @method static void setLaravelSession(\Illuminate\Contracts\Session\Session $session)
* @method static mixed user(string|null $guard = null)
* @method static \Illuminate\Routing\Route|object|string route(string|null $param = null)
* @method static \Illuminate\Routing\Route|object|string route(string|null $param = null, string|null $default = null)
* @method static string fingerprint()
* @method static \Illuminate\Http\Request setJson(\Symfony\Component\HttpFoundation\ParameterBag $json)
* @method static \Closure getUserResolver()
@@ -39,8 +81,11 @@ namespace Illuminate\Support\Facades;
* @method static array toArray()
* @method static bool offsetExists(string $offset)
* @method static mixed offsetGet(string $offset)
* @method static void offsetSet(string $offset, $value)
* @method static void offsetSet(string $offset, mixed $value)
* @method static void offsetUnset(string $offset)
* @method static array validate(array $rules, ...$params)
* @method static array validateWithBag(string $errorBag, array $rules, ...$params)
* @method static bool hasValidSignature(bool $absolute = true)
*
* @see \Illuminate\Http\Request
*/

View File

@@ -3,6 +3,7 @@
namespace Illuminate\Support\Facades;
/**
* @method static \Illuminate\Routing\Route fallback(\Closure|array|string|callable|null $action = null)
* @method static \Illuminate\Routing\Route get(string $uri, \Closure|array|string|callable|null $action = null)
* @method static \Illuminate\Routing\Route post(string $uri, \Closure|array|string|callable|null $action = null)
* @method static \Illuminate\Routing\Route put(string $uri, \Closure|array|string|callable|null $action = null)
@@ -14,8 +15,10 @@ namespace Illuminate\Support\Facades;
* @method static \Illuminate\Routing\RouteRegistrar prefix(string $prefix)
* @method static \Illuminate\Routing\RouteRegistrar where(array $where)
* @method static \Illuminate\Routing\PendingResourceRegistration resource(string $name, string $controller, array $options = [])
* @method static void resources(array $resources)
* @method static void pattern(string $key, string $pattern)
* @method static \Illuminate\Routing\PendingResourceRegistration apiResource(string $name, string $controller, array $options = [])
* @method static void apiResources(array $resources)
* @method static void apiResources(array $resources, array $options = [])
* @method static \Illuminate\Routing\RouteRegistrar middleware(array|string|null $middleware)
* @method static \Illuminate\Routing\Route substituteBindings(\Illuminate\Support\Facades\Route $route)
* @method static void substituteImplicitBindings(\Illuminate\Support\Facades\Route $route)
@@ -23,7 +26,7 @@ namespace Illuminate\Support\Facades;
* @method static \Illuminate\Routing\RouteRegistrar domain(string $value)
* @method static \Illuminate\Routing\RouteRegistrar name(string $value)
* @method static \Illuminate\Routing\RouteRegistrar namespace(string $value)
* @method static \Illuminate\Routing\Router|\Illuminate\Routing\RouteRegistrar group(array|\Closure|string $attributes, \Closure|string $routes)
* @method static \Illuminate\Routing\Router|\Illuminate\Routing\RouteRegistrar group(\Closure|string|array $attributes, \Closure|string $routes)
* @method static \Illuminate\Routing\Route redirect(string $uri, string $destination, int $status = 302)
* @method static \Illuminate\Routing\Route permanentRedirect(string $uri, string $destination)
* @method static \Illuminate\Routing\Route view(string $uri, string $view, array $data = [])

View File

@@ -25,6 +25,7 @@ namespace Illuminate\Support\Facades;
* @method static \SessionHandlerInterface getHandler()
* @method static bool handlerNeedsRequest()
* @method static void setRequestOnHandler(\Illuminate\Http\Request $request)
* @method static void push(string $key, mixed $value)
*
* @see \Illuminate\Session\SessionManager
* @see \Illuminate\Session\Store

View File

@@ -6,6 +6,30 @@ use Illuminate\Filesystem\Filesystem;
/**
* @method static \Illuminate\Contracts\Filesystem\Filesystem disk(string $name = null)
* @method static bool exists(string $path)
* @method static string get(string $path)
* @method static resource|null readStream(string $path)
* @method static bool put(string $path, string|resource $contents, mixed $options = [])
* @method static string|false putFile(string $path, \Illuminate\Http\File|\Illuminate\Http\UploadedFile|string $file, mixed $options = [])
* @method static string|false putFileAs(string $path, \Illuminate\Http\File|\Illuminate\Http\UploadedFile|string $file, string $name, mixed $options = [])
* @method static bool writeStream(string $path, resource $resource, array $options = [])
* @method static string getVisibility(string $path)
* @method static bool setVisibility(string $path, string $visibility)
* @method static bool prepend(string $path, string $data)
* @method static bool append(string $path, string $data)
* @method static bool delete(string|array $paths)
* @method static bool copy(string $from, string $to)
* @method static bool move(string $from, string $to)
* @method static int size(string $path)
* @method static int lastModified(string $path)
* @method static array files(string|null $directory = null, bool $recursive = false)
* @method static array allFiles(string|null $directory = null)
* @method static array directories(string|null $directory = null, bool $recursive = false)
* @method static array allDirectories(string|null $directory = null)
* @method static bool makeDirectory(string $path)
* @method static bool deleteDirectory(string $directory)
* @method static \Illuminate\Contracts\Filesystem\Filesystem assertExists(string|array $path)
* @method static \Illuminate\Contracts\Filesystem\Filesystem assertMissing(string|array $path)
*
* @see \Illuminate\Filesystem\FilesystemManager
*/
@@ -15,18 +39,20 @@ class Storage extends Facade
* Replace the given disk with a local testing disk.
*
* @param string|null $disk
*
* @return \Illuminate\Filesystem\Filesystem
* @param array $config
* @return \Illuminate\Contracts\Filesystem\Filesystem
*/
public static function fake($disk = null)
public static function fake($disk = null, array $config = [])
{
$disk = $disk ?: self::$app['config']->get('filesystems.default');
$disk = $disk ?: static::$app['config']->get('filesystems.default');
(new Filesystem)->cleanDirectory(
$root = storage_path('framework/testing/disks/'.$disk)
);
static::set($disk, $fake = self::createLocalDriver(['root' => $root]));
static::set($disk, $fake = static::createLocalDriver(array_merge($config, [
'root' => $root,
])));
return $fake;
}
@@ -35,15 +61,16 @@ class Storage extends Facade
* Replace the given disk with a persistent local testing disk.
*
* @param string|null $disk
* @return \Illuminate\Filesystem\Filesystem
* @param array $config
* @return \Illuminate\Contracts\Filesystem\Filesystem
*/
public static function persistentFake($disk = null)
public static function persistentFake($disk = null, array $config = [])
{
$disk = $disk ?: self::$app['config']->get('filesystems.default');
$disk = $disk ?: static::$app['config']->get('filesystems.default');
static::set($disk, $fake = self::createLocalDriver([
static::set($disk, $fake = static::createLocalDriver(array_merge($config, [
'root' => storage_path('framework/testing/disks/'.$disk),
]));
])));
return $fake;
}

View File

@@ -14,8 +14,9 @@ namespace Illuminate\Support\Facades;
* @method static \Illuminate\Contracts\Routing\UrlGenerator setRootControllerNamespace(string $rootNamespace)
* @method static string signedRoute(string $name, array $parameters = [], \DateTimeInterface|\DateInterval|int $expiration = null, bool $absolute = true)
* @method static string temporarySignedRoute(string $name, \DateTimeInterface|\DateInterval|int $expiration, array $parameters = [], bool $absolute = true)
* @method static string hasValidSignature(\Illuminate\Http\Request $request, bool $absolute = true)
* @method static bool hasValidSignature(\Illuminate\Http\Request $request, bool $absolute = true)
* @method static void defaults(array $defaults)
* @method static void forceScheme(string $scheme)
*
* @see \Illuminate\Routing\UrlGenerator
*/

View File

@@ -3,11 +3,11 @@
namespace Illuminate\Support;
use ArrayAccess;
use JsonSerializable;
use Illuminate\Contracts\Support\Jsonable;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Jsonable;
use JsonSerializable;
class Fluent implements ArrayAccess, Arrayable, Jsonable, JsonSerializable
class Fluent implements Arrayable, ArrayAccess, Jsonable, JsonSerializable
{
/**
* All of the attributes set on the fluent instance.
@@ -33,7 +33,7 @@ class Fluent implements ArrayAccess, Arrayable, Jsonable, JsonSerializable
* Get an attribute from the fluent instance.
*
* @param string $key
* @param mixed $default
* @param mixed $default
* @return mixed
*/
public function get($key, $default = null)
@@ -112,7 +112,7 @@ class Fluent implements ArrayAccess, Arrayable, Jsonable, JsonSerializable
* Set the value at the given offset.
*
* @param string $offset
* @param mixed $value
* @param mixed $value
* @return void
*/
public function offsetSet($offset, $value)
@@ -135,7 +135,7 @@ class Fluent implements ArrayAccess, Arrayable, Jsonable, JsonSerializable
* Handle dynamic calls to the fluent instance to set attributes.
*
* @param string $method
* @param array $parameters
* @param array $parameters
* @return $this
*/
public function __call($method, $parameters)
@@ -160,7 +160,7 @@ class Fluent implements ArrayAccess, Arrayable, Jsonable, JsonSerializable
* Dynamically set the value of an attribute.
*
* @param string $key
* @param mixed $value
* @param mixed $value
* @return void
*/
public function __set($key, $value)

View File

@@ -3,14 +3,14 @@
namespace Illuminate\Support;
/**
* @mixin \Illuminate\Support\Collection
* @mixin \Illuminate\Support\Enumerable
*/
class HigherOrderCollectionProxy
{
/**
* The collection being operated on.
*
* @var \Illuminate\Support\Collection
* @var \Illuminate\Support\Enumerable
*/
protected $collection;
@@ -24,11 +24,11 @@ class HigherOrderCollectionProxy
/**
* Create a new proxy instance.
*
* @param \Illuminate\Support\Collection $collection
* @param \Illuminate\Support\Enumerable $collection
* @param string $method
* @return void
*/
public function __construct(Collection $collection, $method)
public function __construct(Enumerable $collection, $method)
{
$this->method = $method;
$this->collection = $collection;

File diff suppressed because it is too large Load Diff

View File

@@ -3,17 +3,34 @@
namespace Illuminate\Support;
use Closure;
use Illuminate\Contracts\Container\Container;
use InvalidArgumentException;
abstract class Manager
{
/**
* The application instance.
* The container instance.
*
* @var \Illuminate\Contracts\Foundation\Application
* @var \Illuminate\Contracts\Container\Container
*/
protected $container;
/**
* The container instance.
*
* @var \Illuminate\Contracts\Container\Container
*
* @deprecated Use the $container property instead.
*/
protected $app;
/**
* The configuration repository instance.
*
* @var \Illuminate\Contracts\Config\Repository
*/
protected $config;
/**
* The registered custom driver creators.
*
@@ -31,12 +48,14 @@ abstract class Manager
/**
* Create a new manager instance.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @param \Illuminate\Contracts\Container\Container $container
* @return void
*/
public function __construct($app)
public function __construct(Container $container)
{
$this->app = $app;
$this->app = $container;
$this->container = $container;
$this->config = $container->make('config');
}
/**
@@ -96,6 +115,7 @@ abstract class Manager
return $this->$method();
}
}
throw new InvalidArgumentException("Driver [$driver] not supported.");
}
@@ -107,13 +127,13 @@ abstract class Manager
*/
protected function callCustomCreator($driver)
{
return $this->customCreators[$driver]($this->app);
return $this->customCreators[$driver]($this->container);
}
/**
* Register a custom driver creator Closure.
*
* @param string $driver
* @param string $driver
* @param \Closure $callback
* @return $this
*/
@@ -138,7 +158,7 @@ abstract class Manager
* Dynamically call the default driver instance.
*
* @param string $method
* @param array $parameters
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)

View File

@@ -3,11 +3,11 @@
namespace Illuminate\Support;
use Countable;
use JsonSerializable;
use Illuminate\Contracts\Support\Jsonable;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\MessageProvider;
use Illuminate\Contracts\Support\Jsonable;
use Illuminate\Contracts\Support\MessageBag as MessageBagContract;
use Illuminate\Contracts\Support\MessageProvider;
use JsonSerializable;
class MessageBag implements Arrayable, Countable, Jsonable, JsonSerializable, MessageBagContract, MessageProvider
{
@@ -150,8 +150,8 @@ class MessageBag implements Arrayable, Countable, Jsonable, JsonSerializable, Me
/**
* Get the first message from the message bag for a given key.
*
* @param string $key
* @param string $format
* @param string|null $key
* @param string|null $format
* @return string
*/
public function first($key = null, $format = null)
@@ -241,7 +241,7 @@ class MessageBag implements Arrayable, Countable, Jsonable, JsonSerializable, Me
/**
* Format an array of messages.
*
* @param array $messages
* @param array $messages
* @param string $format
* @param string $messageKey
* @return array

View File

@@ -92,7 +92,7 @@ class NamespacedItemResolver
* Set the parsed value of a key.
*
* @param string $key
* @param array $parsed
* @param array $parsed
* @return void
*/
public function setParsedKey($key, $parsed)

View File

@@ -2,7 +2,10 @@
namespace Illuminate\Support;
use Doctrine\Common\Inflector\Inflector;
use Doctrine\Inflector\CachedWordInflector;
use Doctrine\Inflector\Inflector;
use Doctrine\Inflector\Rules\English;
use Doctrine\Inflector\RulesetInflector;
class Pluralizer
{
@@ -61,7 +64,7 @@ class Pluralizer
* Get the plural form of an English word.
*
* @param string $value
* @param int $count
* @param int $count
* @return string
*/
public static function plural($value, $count = 2)
@@ -70,7 +73,7 @@ class Pluralizer
return $value;
}
$plural = Inflector::pluralize($value);
$plural = static::inflector()->pluralize($value);
return static::matchCase($plural, $value);
}
@@ -83,7 +86,7 @@ class Pluralizer
*/
public static function singular($value)
{
$singular = Inflector::singularize($value);
$singular = static::inflector()->singularize($value);
return static::matchCase($singular, $value);
}
@@ -111,11 +114,34 @@ class Pluralizer
$functions = ['mb_strtolower', 'mb_strtoupper', 'ucfirst', 'ucwords'];
foreach ($functions as $function) {
if (call_user_func($function, $comparison) === $comparison) {
return call_user_func($function, $value);
if ($function($comparison) === $comparison) {
return $function($value);
}
}
return $value;
}
/**
* Get the inflector instance.
*
* @return \Doctrine\Inflector\Inflector
*/
public static function inflector()
{
static $inflector;
if (is_null($inflector)) {
$inflector = new Inflector(
new CachedWordInflector(new RulesetInflector(
English\Rules::getSingularRuleset()
)),
new CachedWordInflector(new RulesetInflector(
English\Rules::getPluralRuleset()
))
);
}
return $inflector;
}
}

View File

@@ -0,0 +1,102 @@
<?php
namespace Illuminate\Support;
use ReflectionClass;
use ReflectionMethod;
use ReflectionNamedType;
class Reflector
{
/**
* This is a PHP 7.4 compatible implementation of is_callable.
*
* @param mixed $var
* @param bool $syntaxOnly
* @return bool
*/
public static function isCallable($var, $syntaxOnly = false)
{
if (! is_array($var)) {
return is_callable($var, $syntaxOnly);
}
if ((! isset($var[0]) || ! isset($var[1])) ||
! is_string($var[1] ?? null)) {
return false;
}
if ($syntaxOnly &&
(is_string($var[0]) || is_object($var[0])) &&
is_string($var[1])) {
return true;
}
$class = is_object($var[0]) ? get_class($var[0]) : $var[0];
$method = $var[1];
if (! class_exists($class)) {
return false;
}
if (method_exists($class, $method)) {
return (new ReflectionMethod($class, $method))->isPublic();
}
if (is_object($var[0]) && method_exists($class, '__call')) {
return (new ReflectionMethod($class, '__call'))->isPublic();
}
if (! is_object($var[0]) && method_exists($class, '__callStatic')) {
return (new ReflectionMethod($class, '__callStatic'))->isPublic();
}
return false;
}
/**
* Get the class name of the given parameter's type, if possible.
*
* @param \ReflectionParameter $parameter
* @return string|null
*/
public static function getParameterClassName($parameter)
{
$type = $parameter->getType();
if (! $type instanceof ReflectionNamedType || $type->isBuiltin()) {
return;
}
$name = $type->getName();
if (! is_null($class = $parameter->getDeclaringClass())) {
if ($name === 'self') {
return $class->getName();
}
if ($name === 'parent' && $parent = $class->getParentClass()) {
return $parent->getName();
}
}
return $name;
}
/**
* Determine if the parameter's type is a subclass of the given type.
*
* @param \ReflectionParameter $parameter
* @param string $className
* @return bool
*/
public static function isParameterSubclassOf($parameter, $className)
{
$paramClassName = static::getParameterClassName($parameter);
return ($paramClassName && class_exists($paramClassName))
? (new ReflectionClass($paramClassName))->isSubclassOf($className)
: false;
}
}

View File

@@ -4,6 +4,7 @@ namespace Illuminate\Support;
use Illuminate\Console\Application as Artisan;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Database\Eloquent\Factory as ModelFactory;
abstract class ServiceProvider
{
@@ -14,15 +15,6 @@ abstract class ServiceProvider
*/
protected $app;
/**
* Indicates if loading of the provider is deferred.
*
* @deprecated Implement the \Illuminate\Contracts\Support\DeferrableProvider interface instead. Will be removed in Laravel 6.0.
*
* @var bool
*/
protected $defer = false;
/**
* The paths that should be published.
*
@@ -67,9 +59,11 @@ abstract class ServiceProvider
*/
protected function mergeConfigFrom($path, $key)
{
$config = $this->app['config']->get($key, []);
$this->app['config']->set($key, array_merge(require $path, $config));
if (! $this->app->configurationIsCached()) {
$this->app['config']->set($key, array_merge(
require $path, $this->app['config']->get($key, [])
));
}
}
/**
@@ -94,15 +88,18 @@ abstract class ServiceProvider
*/
protected function loadViewsFrom($path, $namespace)
{
if (isset($this->app->config['view']['paths']) && is_array($this->app->config['view']['paths'])) {
foreach ($this->app->config['view']['paths'] as $viewPath) {
if (is_dir($appPath = $viewPath.'/vendor/'.$namespace)) {
$this->app['view']->addNamespace($namespace, $appPath);
$this->callAfterResolving('view', function ($view) use ($path, $namespace) {
if (isset($this->app->config['view']['paths']) &&
is_array($this->app->config['view']['paths'])) {
foreach ($this->app->config['view']['paths'] as $viewPath) {
if (is_dir($appPath = $viewPath.'/vendor/'.$namespace)) {
$view->addNamespace($namespace, $appPath);
}
}
}
}
$this->app['view']->addNamespace($namespace, $path);
$view->addNamespace($namespace, $path);
});
}
/**
@@ -114,7 +111,9 @@ abstract class ServiceProvider
*/
protected function loadTranslationsFrom($path, $namespace)
{
$this->app['translator']->addNamespace($namespace, $path);
$this->callAfterResolving('translator', function ($translator) use ($path, $namespace) {
$translator->addNamespace($namespace, $path);
});
}
/**
@@ -125,24 +124,57 @@ abstract class ServiceProvider
*/
protected function loadJsonTranslationsFrom($path)
{
$this->app['translator']->addJsonPath($path);
$this->callAfterResolving('translator', function ($translator) use ($path) {
$translator->addJsonPath($path);
});
}
/**
* Register a database migration path.
* Register database migration paths.
*
* @param array|string $paths
* @return void
*/
protected function loadMigrationsFrom($paths)
{
$this->app->afterResolving('migrator', function ($migrator) use ($paths) {
$this->callAfterResolving('migrator', function ($migrator) use ($paths) {
foreach ((array) $paths as $path) {
$migrator->path($path);
}
});
}
/**
* Register Eloquent model factory paths.
*
* @param array|string $paths
* @return void
*/
protected function loadFactoriesFrom($paths)
{
$this->callAfterResolving(ModelFactory::class, function ($factory) use ($paths) {
foreach ((array) $paths as $path) {
$factory->load($path);
}
});
}
/**
* Setup an after resolving listener, or fire immediately if already resolved.
*
* @param string $name
* @param callable $callback
* @return void
*/
protected function callAfterResolving($name, $callback)
{
$this->app->afterResolving($name, $callback);
if ($this->app->resolved($name)) {
$callback($this->app->make($name), $this->app);
}
}
/**
* Register paths to be published by the publish command.
*
@@ -195,8 +227,8 @@ abstract class ServiceProvider
/**
* Get the paths to publish.
*
* @param string $provider
* @param string $group
* @param string|null $provider
* @param string|null $group
* @return array
*/
public static function pathsToPublish($provider = null, $group = null)
@@ -308,6 +340,6 @@ abstract class ServiceProvider
*/
public function isDeferred()
{
return $this->defer || $this instanceof DeferrableProvider;
return $this instanceof DeferrableProvider;
}
}

View File

@@ -2,11 +2,11 @@
namespace Illuminate\Support;
use Illuminate\Support\Traits\Macroable;
use Ramsey\Uuid\Codec\TimestampFirstCombCodec;
use Ramsey\Uuid\Generator\CombGenerator;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidFactory;
use Illuminate\Support\Traits\Macroable;
use Ramsey\Uuid\Generator\CombGenerator;
use Ramsey\Uuid\Codec\TimestampFirstCombCodec;
class Str
{
@@ -34,7 +34,14 @@ class Str
protected static $studlyCache = [];
/**
* Return the remainder of a string after a given value.
* The callback that should be used to generate UUIDs.
*
* @var callable
*/
protected static $uuidFactory;
/**
* Return the remainder of a string after the first occurrence of a given value.
*
* @param string $subject
* @param string $search
@@ -45,6 +52,28 @@ class Str
return $search === '' ? $subject : array_reverse(explode($search, $subject, 2))[0];
}
/**
* Return the remainder of a string after the last occurrence of a given value.
*
* @param string $subject
* @param string $search
* @return string
*/
public static function afterLast($subject, $search)
{
if ($search === '') {
return $subject;
}
$position = strrpos($subject, (string) $search);
if ($position === false) {
return $subject;
}
return substr($subject, $position + strlen($search));
}
/**
* Transliterate a UTF-8 value to ASCII.
*
@@ -68,7 +97,7 @@ class Str
}
/**
* Get the portion of a string before a given value.
* Get the portion of a string before the first occurrence of a given value.
*
* @param string $subject
* @param string $search
@@ -79,6 +108,28 @@ class Str
return $search === '' ? $subject : explode($search, $subject)[0];
}
/**
* Get the portion of a string before the last occurrence of a given value.
*
* @param string $subject
* @param string $search
* @return string
*/
public static function beforeLast($subject, $search)
{
if ($search === '') {
return $subject;
}
$pos = mb_strrpos($subject, $search);
if ($pos === false) {
return $subject;
}
return static::substr($subject, 0, $pos);
}
/**
* Convert a value to camel case.
*
@@ -98,7 +149,7 @@ class Str
* Determine if a given string contains a given substring.
*
* @param string $haystack
* @param string|array $needles
* @param string|string[] $needles
* @return bool
*/
public static function contains($haystack, $needles)
@@ -116,7 +167,7 @@ class Str
* Determine if a given string contains all array values.
*
* @param string $haystack
* @param array $needles
* @param string[] $needles
* @return bool
*/
public static function containsAll($haystack, array $needles)
@@ -134,7 +185,7 @@ class Str
* Determine if a given string ends with a given substring.
*
* @param string $haystack
* @param string|array $needles
* @param string|string[] $needles
* @return bool
*/
public static function endsWith($haystack, $needles)
@@ -200,6 +251,21 @@ class Str
return false;
}
/**
* Determine if a given string is a valid UUID.
*
* @param string $value
* @return bool
*/
public static function isUuid($value)
{
if (! is_string($value)) {
return false;
}
return preg_match('/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iD', $value) > 0;
}
/**
* Convert a string to kebab case.
*
@@ -215,7 +281,7 @@ class Str
* Return the length of the given string.
*
* @param string $value
* @param string $encoding
* @param string|null $encoding
* @return int
*/
public static function length($value, $encoding = null)
@@ -231,7 +297,7 @@ class Str
* Limit the number of characters in a string.
*
* @param string $value
* @param int $limit
* @param int $limit
* @param string $end
* @return string
*/
@@ -259,7 +325,7 @@ class Str
* Limit the number of words in a string.
*
* @param string $value
* @param int $words
* @param int $words
* @param string $end
* @return string
*/
@@ -275,11 +341,11 @@ class Str
}
/**
* Parse a Class@method style callback into class and method.
* Parse a Class[@]method style callback into class and method.
*
* @param string $callback
* @param string|null $default
* @return array
* @return array<int, string|null>
*/
public static function parseCallback($callback, $default = null)
{
@@ -290,7 +356,7 @@ class Str
* Get the plural form of an English word.
*
* @param string $value
* @param int $count
* @param int $count
* @return string
*/
public static function plural($value, $count = 2)
@@ -302,7 +368,7 @@ class Str
* Pluralize the last word of an English, studly caps case string.
*
* @param string $value
* @param int $count
* @param int $count
* @return string
*/
public static function pluralStudly($value, $count = 2)
@@ -339,7 +405,7 @@ class Str
* Replace a given value in the string sequentially with an array.
*
* @param string $search
* @param array $replace
* @param array<int|string, string> $replace
* @param string $subject
* @return string
*/
@@ -389,6 +455,10 @@ class Str
*/
public static function replaceLast($search, $replace, $subject)
{
if ($search === '') {
return $subject;
}
$position = strrpos($subject, $search);
if ($position !== false) {
@@ -502,7 +572,7 @@ class Str
* Determine if a given string starts with a given substring.
*
* @param string $haystack
* @param string|array $needles
* @param string|string[] $needles
* @return bool
*/
public static function startsWith($haystack, $needles)
@@ -566,7 +636,9 @@ class Str
*/
public static function uuid()
{
return Uuid::uuid4();
return static::$uuidFactory
? call_user_func(static::$uuidFactory)
: Uuid::uuid4();
}
/**
@@ -576,7 +648,11 @@ class Str
*/
public static function orderedUuid()
{
$factory = new UuidFactory;
if (static::$uuidFactory) {
return call_user_func(static::$uuidFactory);
}
$factory = new UuidFactory();
$factory->setRandomGenerator(new CombGenerator(
$factory->getRandomGenerator(),
@@ -590,6 +666,27 @@ class Str
return $factory->uuid4();
}
/**
* Set the callable that will be used to generate UUIDs.
*
* @param callable $factory
* @return void
*/
public static function createUuidsUsing(callable $factory = null)
{
static::$uuidFactory = $factory;
}
/**
* Indicate that UUIDs should be created normally and not using a custom factory.
*
* @return void
*/
public static function createUuidsNormally()
{
static::$uuidFactory = null;
}
/**
* Returns the replacements for the ascii method.
*

View File

@@ -2,11 +2,27 @@
namespace Illuminate\Support\Testing\Fakes;
use Closure;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use PHPUnit\Framework\Assert as PHPUnit;
class BusFake implements Dispatcher
{
/**
* The original Bus dispatcher implementation.
*
* @var \Illuminate\Contracts\Bus\Dispatcher
*/
protected $dispatcher;
/**
* The job types that should be intercepted instead of dispatched.
*
* @var array
*/
protected $jobsToFake;
/**
* The commands that have been dispatched.
*
@@ -14,6 +30,27 @@ class BusFake implements Dispatcher
*/
protected $commands = [];
/**
* The commands that have been dispatched after the response has been sent.
*
* @var array
*/
protected $commandsAfterResponse = [];
/**
* Create a new bus fake instance.
*
* @param \Illuminate\Contracts\Bus\Dispatcher $dispatcher
* @param array|string $jobsToFake
* @return void
*/
public function __construct(Dispatcher $dispatcher, $jobsToFake = [])
{
$this->dispatcher = $dispatcher;
$this->jobsToFake = Arr::wrap($jobsToFake);
}
/**
* Assert if a job was dispatched based on a truth-test callback.
*
@@ -28,7 +65,8 @@ class BusFake implements Dispatcher
}
PHPUnit::assertTrue(
$this->dispatched($command, $callback)->count() > 0,
$this->dispatched($command, $callback)->count() > 0 ||
$this->dispatchedAfterResponse($command, $callback)->count() > 0,
"The expected [{$command}] job was not dispatched."
);
}
@@ -40,10 +78,13 @@ class BusFake implements Dispatcher
* @param int $times
* @return void
*/
protected function assertDispatchedTimes($command, $times = 1)
public function assertDispatchedTimes($command, $times = 1)
{
$count = $this->dispatched($command)->count() +
$this->dispatchedAfterResponse($command)->count();
PHPUnit::assertTrue(
($count = $this->dispatched($command)->count()) === $times,
$count === $times,
"The expected [{$command}] job was pushed {$count} times instead of {$times} times."
);
}
@@ -58,11 +99,61 @@ class BusFake implements Dispatcher
public function assertNotDispatched($command, $callback = null)
{
PHPUnit::assertTrue(
$this->dispatched($command, $callback)->count() === 0,
$this->dispatched($command, $callback)->count() === 0 &&
$this->dispatchedAfterResponse($command, $callback)->count() === 0,
"The unexpected [{$command}] job was dispatched."
);
}
/**
* Assert if a job was dispatched after the response was sent based on a truth-test callback.
*
* @param string $command
* @param callable|int|null $callback
* @return void
*/
public function assertDispatchedAfterResponse($command, $callback = null)
{
if (is_numeric($callback)) {
return $this->assertDispatchedAfterResponseTimes($command, $callback);
}
PHPUnit::assertTrue(
$this->dispatchedAfterResponse($command, $callback)->count() > 0,
"The expected [{$command}] job was not dispatched for after sending the response."
);
}
/**
* Assert if a job was pushed after the response was sent a number of times.
*
* @param string $command
* @param int $times
* @return void
*/
public function assertDispatchedAfterResponseTimes($command, $times = 1)
{
PHPUnit::assertTrue(
($count = $this->dispatchedAfterResponse($command)->count()) === $times,
"The expected [{$command}] job was pushed {$count} times instead of {$times} times."
);
}
/**
* Determine if a job was dispatched based on a truth-test callback.
*
* @param string $command
* @param callable|null $callback
* @return void
*/
public function assertNotDispatchedAfterResponse($command, $callback = null)
{
PHPUnit::assertTrue(
$this->dispatchedAfterResponse($command, $callback)->count() === 0,
"The unexpected [{$command}] job was dispatched for after sending the response."
);
}
/**
* Get all of the jobs matching a truth-test callback.
*
@@ -85,6 +176,28 @@ class BusFake implements Dispatcher
});
}
/**
* Get all of the jobs dispatched after the response was sent matching a truth-test callback.
*
* @param string $command
* @param callable|null $callback
* @return \Illuminate\Support\Collection
*/
public function dispatchedAfterResponse(string $command, $callback = null)
{
if (! $this->hasDispatchedAfterResponse($command)) {
return collect();
}
$callback = $callback ?: function () {
return true;
};
return collect($this->commandsAfterResponse[$command])->filter(function ($command) use ($callback) {
return $callback($command);
});
}
/**
* Determine if there are any stored commands for a given class.
*
@@ -96,6 +209,17 @@ class BusFake implements Dispatcher
return isset($this->commands[$command]) && ! empty($this->commands[$command]);
}
/**
* Determine if there are any stored commands for a given class.
*
* @param string $command
* @return bool
*/
public function hasDispatchedAfterResponse($command)
{
return isset($this->commandsAfterResponse[$command]) && ! empty($this->commandsAfterResponse[$command]);
}
/**
* Dispatch a command to its appropriate handler.
*
@@ -104,7 +228,11 @@ class BusFake implements Dispatcher
*/
public function dispatch($command)
{
return $this->dispatchNow($command);
if ($this->shouldFakeJob($command)) {
$this->commands[get_class($command)][] = $command;
} else {
return $this->dispatcher->dispatch($command);
}
}
/**
@@ -116,7 +244,46 @@ class BusFake implements Dispatcher
*/
public function dispatchNow($command, $handler = null)
{
$this->commands[get_class($command)][] = $command;
if ($this->shouldFakeJob($command)) {
$this->commands[get_class($command)][] = $command;
} else {
return $this->dispatcher->dispatchNow($command, $handler);
}
}
/**
* Dispatch a command to its appropriate handler.
*
* @param mixed $command
* @return mixed
*/
public function dispatchAfterResponse($command)
{
if ($this->shouldFakeJob($command)) {
$this->commandsAfterResponse[get_class($command)][] = $command;
} else {
return $this->dispatcher->dispatch($command);
}
}
/**
* Determine if an command should be faked or actually dispatched.
*
* @param mixed $command
* @return bool
*/
protected function shouldFakeJob($command)
{
if (empty($this->jobsToFake)) {
return true;
}
return collect($this->jobsToFake)
->filter(function ($job) use ($command) {
return $job instanceof Closure
? $job($command)
: $job === get_class($command);
})->isNotEmpty();
}
/**
@@ -127,6 +294,8 @@ class BusFake implements Dispatcher
*/
public function pipeThrough(array $pipes)
{
$this->dispatcher->pipeThrough($pipes);
return $this;
}
@@ -138,7 +307,7 @@ class BusFake implements Dispatcher
*/
public function hasCommandHandler($command)
{
return false;
return $this->dispatcher->hasCommandHandler($command);
}
/**
@@ -149,7 +318,7 @@ class BusFake implements Dispatcher
*/
public function getCommandHandler($command)
{
return false;
return $this->dispatcher->getCommandHandler($command);
}
/**
@@ -160,6 +329,8 @@ class BusFake implements Dispatcher
*/
public function map(array $map)
{
$this->dispatcher->map($map);
return $this;
}
}

View File

@@ -3,9 +3,9 @@
namespace Illuminate\Support\Testing\Fakes;
use Closure;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Support\Arr;
use PHPUnit\Framework\Assert as PHPUnit;
use Illuminate\Contracts\Events\Dispatcher;
class EventFake implements Dispatcher
{
@@ -248,8 +248,8 @@ class EventFake implements Dispatcher
/**
* Dispatch an event and call the listeners.
*
* @param string|object $event
* @param mixed $payload
* @param string|object $event
* @param mixed $payload
* @return void
*/
public function until($event, $payload = [])

View File

@@ -2,11 +2,11 @@
namespace Illuminate\Support\Testing\Fakes;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Contracts\Mail\Mailable;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Contracts\Mail\MailQueue;
use PHPUnit\Framework\Assert as PHPUnit;
use Illuminate\Contracts\Queue\ShouldQueue;
use PHPUnit\Framework\Assert as PHPUnit;
class MailFake implements Mailer, MailQueue
{
@@ -86,7 +86,11 @@ class MailFake implements Mailer, MailQueue
*/
public function assertNothingSent()
{
PHPUnit::assertEmpty($this->mailables, 'Mailables were sent unexpectedly.');
$mailableNames = collect($this->mailables)->map(function ($mailable) {
return get_class($mailable);
})->join(', ');
PHPUnit::assertEmpty($this->mailables, 'The following mailables were sent unexpectedly: '.$mailableNames);
}
/**
@@ -145,7 +149,11 @@ class MailFake implements Mailer, MailQueue
*/
public function assertNothingQueued()
{
PHPUnit::assertEmpty($this->queuedMailables, 'Mailables were queued unexpectedly.');
$mailableNames = collect($this->queuedMailables)->map(function ($mailable) {
return get_class($mailable);
})->join(', ');
PHPUnit::assertEmpty($this->queuedMailables, 'The following mailables were queued unexpectedly: '.$mailableNames);
}
/**
@@ -298,7 +306,7 @@ class MailFake implements Mailer, MailQueue
/**
* Queue a new e-mail message for sending.
*
* @param string|array $view
* @param \Illuminate\Contracts\Mail\Mailable|string|array $view
* @param string|null $queue
* @return mixed
*/
@@ -315,7 +323,7 @@ class MailFake implements Mailer, MailQueue
* Queue a new e-mail message for sending after (n) seconds.
*
* @param \DateTimeInterface|\DateInterval|int $delay
* @param string|array|\Illuminate\Contracts\Mail\Mailable $view
* @param \Illuminate\Contracts\Mail\Mailable|string|array $view
* @param string $queue
* @return mixed
*/

View File

@@ -2,15 +2,16 @@
namespace Illuminate\Support\Testing\Fakes;
use Illuminate\Support\Str;
use Exception;
use Illuminate\Contracts\Notifications\Dispatcher as NotificationDispatcher;
use Illuminate\Contracts\Notifications\Factory as NotificationFactory;
use Illuminate\Contracts\Translation\HasLocalePreference;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
use PHPUnit\Framework\Assert as PHPUnit;
use Illuminate\Contracts\Translation\HasLocalePreference;
use Illuminate\Contracts\Notifications\Factory as NotificationFactory;
use Illuminate\Contracts\Notifications\Dispatcher as NotificationDispatcher;
class NotificationFake implements NotificationFactory, NotificationDispatcher
class NotificationFake implements NotificationDispatcher, NotificationFactory
{
use Macroable;
@@ -35,10 +36,16 @@ class NotificationFake implements NotificationFactory, NotificationDispatcher
* @param string $notification
* @param callable|null $callback
* @return void
*
* @throws \Exception
*/
public function assertSentTo($notifiable, $notification, $callback = null)
{
if (is_array($notifiable) || $notifiable instanceof Collection) {
if (count($notifiable) === 0) {
throw new Exception('No notifiable given.');
}
foreach ($notifiable as $singleNotifiable) {
$this->assertSentTo($singleNotifiable, $notification, $callback);
}
@@ -79,10 +86,16 @@ class NotificationFake implements NotificationFactory, NotificationDispatcher
* @param string $notification
* @param callable|null $callback
* @return void
*
* @throws \Exception
*/
public function assertNotSentTo($notifiable, $notification, $callback = null)
{
if (is_array($notifiable) || $notifiable instanceof Collection) {
if (count($notifiable) === 0) {
throw new Exception('No notifiable given.');
}
foreach ($notifiable as $singleNotifiable) {
$this->assertNotSentTo($singleNotifiable, $notification, $callback);
}

View File

@@ -2,8 +2,8 @@
namespace Illuminate\Support\Testing\Fakes;
use Illuminate\Mail\PendingMail;
use Illuminate\Contracts\Mail\Mailable;
use Illuminate\Mail\PendingMail;
class PendingMailFake extends PendingMail
{
@@ -21,7 +21,7 @@ class PendingMailFake extends PendingMail
/**
* Send a new mailable message instance.
*
* @param \Illuminate\Contracts\Mail\Mailable $mailable;
* @param \Illuminate\Contracts\Mail\Mailable $mailable
* @return mixed
*/
public function send(Mailable $mailable)
@@ -32,18 +32,18 @@ class PendingMailFake extends PendingMail
/**
* Send a mailable message immediately.
*
* @param \Illuminate\Contracts\Mail\Mailable $mailable;
* @param \Illuminate\Contracts\Mail\Mailable $mailable
* @return mixed
*/
public function sendNow(Mailable $mailable)
{
$this->mailer->send($this->fill($mailable));
return $this->mailer->send($this->fill($mailable));
}
/**
* Push the given mailable onto the queue.
*
* @param \Illuminate\Contracts\Mail\Mailable $mailable;
* @param \Illuminate\Contracts\Mail\Mailable $mailable
* @return mixed
*/
public function queue(Mailable $mailable)

View File

@@ -3,8 +3,8 @@
namespace Illuminate\Support\Testing\Fakes;
use BadMethodCallException;
use Illuminate\Queue\QueueManager;
use Illuminate\Contracts\Queue\Queue;
use Illuminate\Queue\QueueManager;
use PHPUnit\Framework\Assert as PHPUnit;
class QueueFake extends QueueManager implements Queue
@@ -72,9 +72,9 @@ class QueueFake extends QueueManager implements Queue
/**
* Assert if a job was pushed with chained jobs based on a truth-test callback.
*
* @param string $job
* @param array $expectedChain
* @param callable|null $callback
* @param string $job
* @param array $expectedChain
* @param callable|null $callback
* @return void
*/
public function assertPushedWithChain($job, $expectedChain = [], $callback = null)
@@ -94,12 +94,29 @@ class QueueFake extends QueueManager implements Queue
: $this->assertPushedWithChainOfClasses($job, $expectedChain, $callback);
}
/**
* Assert if a job was pushed with an empty chain based on a truth-test callback.
*
* @param string $job
* @param callable|null $callback
* @return void
*/
public function assertPushedWithoutChain($job, $callback = null)
{
PHPUnit::assertTrue(
$this->pushed($job, $callback)->isNotEmpty(),
"The expected [{$job}] job was not pushed."
);
$this->assertPushedWithChainOfClasses($job, [], $callback);
}
/**
* Assert if a job was pushed with chained jobs based on a truth-test callback.
*
* @param string $job
* @param array $expectedChain
* @param callable|null $callback
* @param string $job
* @param array $expectedChain
* @param callable|null $callback
* @return void
*/
protected function assertPushedWithChainOfObjects($job, $expectedChain, $callback)
@@ -119,9 +136,9 @@ class QueueFake extends QueueManager implements Queue
/**
* Assert if a job was pushed with chained jobs based on a truth-test callback.
*
* @param string $job
* @param array $expectedChain
* @param callable|null $callback
* @param string $job
* @param array $expectedChain
* @param callable|null $callback
* @return void
*/
protected function assertPushedWithChainOfClasses($job, $expectedChain, $callback)
@@ -238,7 +255,7 @@ class QueueFake extends QueueManager implements Queue
* Push a new job onto the queue.
*
* @param string $job
* @param mixed $data
* @param mixed $data
* @param string|null $queue
* @return mixed
*/
@@ -255,7 +272,7 @@ class QueueFake extends QueueManager implements Queue
*
* @param string $payload
* @param string|null $queue
* @param array $options
* @param array $options
* @return mixed
*/
public function pushRaw($payload, $queue = null, array $options = [])
@@ -268,7 +285,7 @@ class QueueFake extends QueueManager implements Queue
*
* @param \DateTimeInterface|\DateInterval|int $delay
* @param string $job
* @param mixed $data
* @param mixed $data
* @param string|null $queue
* @return mixed
*/
@@ -282,7 +299,7 @@ class QueueFake extends QueueManager implements Queue
*
* @param string $queue
* @param string $job
* @param mixed $data
* @param mixed $data
* @return mixed
*/
public function pushOn($queue, $job, $data = '')
@@ -296,7 +313,7 @@ class QueueFake extends QueueManager implements Queue
* @param string $queue
* @param \DateTimeInterface|\DateInterval|int $delay
* @param string $job
* @param mixed $data
* @param mixed $data
* @return mixed
*/
public function laterOn($queue, $delay, $job, $data = '')
@@ -318,9 +335,9 @@ class QueueFake extends QueueManager implements Queue
/**
* Push an array of jobs onto the queue.
*
* @param array $jobs
* @param mixed $data
* @param string|null $queue
* @param array $jobs
* @param mixed $data
* @param string|null $queue
* @return mixed
*/
public function bulk($jobs, $data = '', $queue = null)
@@ -353,7 +370,7 @@ class QueueFake extends QueueManager implements Queue
/**
* Set the connection name for the queue.
*
* @param string $name
* @param string $name
* @return $this
*/
public function setConnectionName($name)
@@ -365,8 +382,10 @@ class QueueFake extends QueueManager implements Queue
* Override the QueueManager to prevent circular dependency.
*
* @param string $method
* @param array $parameters
* @param array $parameters
* @return mixed
*
* @throws \BadMethodCallException
*/
public function __call($method, $parameters)
{

View File

@@ -2,8 +2,8 @@
namespace Illuminate\Support\Traits;
use Illuminate\Support\Fluent;
use Illuminate\Contracts\Container\Container;
use Illuminate\Support\Fluent;
trait CapsuleManagerTrait
{

View File

@@ -0,0 +1,922 @@
<?php
namespace Illuminate\Support\Traits;
use CachingIterator;
use Exception;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Jsonable;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Enumerable;
use Illuminate\Support\HigherOrderCollectionProxy;
use JsonSerializable;
use Symfony\Component\VarDumper\VarDumper;
use Traversable;
/**
* @property-read HigherOrderCollectionProxy $average
* @property-read HigherOrderCollectionProxy $avg
* @property-read HigherOrderCollectionProxy $contains
* @property-read HigherOrderCollectionProxy $each
* @property-read HigherOrderCollectionProxy $every
* @property-read HigherOrderCollectionProxy $filter
* @property-read HigherOrderCollectionProxy $first
* @property-read HigherOrderCollectionProxy $flatMap
* @property-read HigherOrderCollectionProxy $groupBy
* @property-read HigherOrderCollectionProxy $keyBy
* @property-read HigherOrderCollectionProxy $map
* @property-read HigherOrderCollectionProxy $max
* @property-read HigherOrderCollectionProxy $min
* @property-read HigherOrderCollectionProxy $partition
* @property-read HigherOrderCollectionProxy $reject
* @property-read HigherOrderCollectionProxy $sortBy
* @property-read HigherOrderCollectionProxy $sortByDesc
* @property-read HigherOrderCollectionProxy $sum
* @property-read HigherOrderCollectionProxy $unique
*/
trait EnumeratesValues
{
/**
* The methods that can be proxied.
*
* @var array
*/
protected static $proxies = [
'average', 'avg', 'contains', 'each', 'every', 'filter', 'first',
'flatMap', 'groupBy', 'keyBy', 'map', 'max', 'min', 'partition',
'reject', 'some', 'sortBy', 'sortByDesc', 'sum', 'unique',
];
/**
* Create a new collection instance if the value isn't one already.
*
* @param mixed $items
* @return static
*/
public static function make($items = [])
{
return new static($items);
}
/**
* Wrap the given value in a collection if applicable.
*
* @param mixed $value
* @return static
*/
public static function wrap($value)
{
return $value instanceof Enumerable
? new static($value)
: new static(Arr::wrap($value));
}
/**
* Get the underlying items from the given collection if applicable.
*
* @param array|static $value
* @return array
*/
public static function unwrap($value)
{
return $value instanceof Enumerable ? $value->all() : $value;
}
/**
* Alias for the "avg" method.
*
* @param callable|string|null $callback
* @return mixed
*/
public function average($callback = null)
{
return $this->avg($callback);
}
/**
* Alias for the "contains" method.
*
* @param mixed $key
* @param mixed $operator
* @param mixed $value
* @return bool
*/
public function some($key, $operator = null, $value = null)
{
return $this->contains(...func_get_args());
}
/**
* Determine if an item exists, using strict comparison.
*
* @param mixed $key
* @param mixed $value
* @return bool
*/
public function containsStrict($key, $value = null)
{
if (func_num_args() === 2) {
return $this->contains(function ($item) use ($key, $value) {
return data_get($item, $key) === $value;
});
}
if ($this->useAsCallable($key)) {
return ! is_null($this->first($key));
}
foreach ($this as $item) {
if ($item === $key) {
return true;
}
}
return false;
}
/**
* Dump the items and end the script.
*
* @param mixed ...$args
* @return void
*/
public function dd(...$args)
{
$this->dump(...$args);
exit(1);
}
/**
* Dump the items.
*
* @return $this
*/
public function dump()
{
(new static(func_get_args()))
->push($this)
->each(function ($item) {
VarDumper::dump($item);
});
return $this;
}
/**
* Execute a callback over each item.
*
* @param callable $callback
* @return $this
*/
public function each(callable $callback)
{
foreach ($this as $key => $item) {
if ($callback($item, $key) === false) {
break;
}
}
return $this;
}
/**
* Execute a callback over each nested chunk of items.
*
* @param callable $callback
* @return static
*/
public function eachSpread(callable $callback)
{
return $this->each(function ($chunk, $key) use ($callback) {
$chunk[] = $key;
return $callback(...$chunk);
});
}
/**
* Determine if all items pass the given truth test.
*
* @param string|callable $key
* @param mixed $operator
* @param mixed $value
* @return bool
*/
public function every($key, $operator = null, $value = null)
{
if (func_num_args() === 1) {
$callback = $this->valueRetriever($key);
foreach ($this as $k => $v) {
if (! $callback($v, $k)) {
return false;
}
}
return true;
}
return $this->every($this->operatorForWhere(...func_get_args()));
}
/**
* Get the first item by the given key value pair.
*
* @param string $key
* @param mixed $operator
* @param mixed $value
* @return mixed
*/
public function firstWhere($key, $operator = null, $value = null)
{
return $this->first($this->operatorForWhere(...func_get_args()));
}
/**
* Determine if the collection is not empty.
*
* @return bool
*/
public function isNotEmpty()
{
return ! $this->isEmpty();
}
/**
* Run a map over each nested chunk of items.
*
* @param callable $callback
* @return static
*/
public function mapSpread(callable $callback)
{
return $this->map(function ($chunk, $key) use ($callback) {
$chunk[] = $key;
return $callback(...$chunk);
});
}
/**
* Run a grouping map over the items.
*
* The callback should return an associative array with a single key/value pair.
*
* @param callable $callback
* @return static
*/
public function mapToGroups(callable $callback)
{
$groups = $this->mapToDictionary($callback);
return $groups->map([$this, 'make']);
}
/**
* Map a collection and flatten the result by a single level.
*
* @param callable $callback
* @return static
*/
public function flatMap(callable $callback)
{
return $this->map($callback)->collapse();
}
/**
* Map the values into a new class.
*
* @param string $class
* @return static
*/
public function mapInto($class)
{
return $this->map(function ($value, $key) use ($class) {
return new $class($value, $key);
});
}
/**
* Get the min value of a given key.
*
* @param callable|string|null $callback
* @return mixed
*/
public function min($callback = null)
{
$callback = $this->valueRetriever($callback);
return $this->map(function ($value) use ($callback) {
return $callback($value);
})->filter(function ($value) {
return ! is_null($value);
})->reduce(function ($result, $value) {
return is_null($result) || $value < $result ? $value : $result;
});
}
/**
* Get the max value of a given key.
*
* @param callable|string|null $callback
* @return mixed
*/
public function max($callback = null)
{
$callback = $this->valueRetriever($callback);
return $this->filter(function ($value) {
return ! is_null($value);
})->reduce(function ($result, $item) use ($callback) {
$value = $callback($item);
return is_null($result) || $value > $result ? $value : $result;
});
}
/**
* "Paginate" the collection by slicing it into a smaller collection.
*
* @param int $page
* @param int $perPage
* @return static
*/
public function forPage($page, $perPage)
{
$offset = max(0, ($page - 1) * $perPage);
return $this->slice($offset, $perPage);
}
/**
* Partition the collection into two arrays using the given callback or key.
*
* @param callable|string $key
* @param mixed $operator
* @param mixed $value
* @return static
*/
public function partition($key, $operator = null, $value = null)
{
$passed = [];
$failed = [];
$callback = func_num_args() === 1
? $this->valueRetriever($key)
: $this->operatorForWhere(...func_get_args());
foreach ($this as $key => $item) {
if ($callback($item, $key)) {
$passed[$key] = $item;
} else {
$failed[$key] = $item;
}
}
return new static([new static($passed), new static($failed)]);
}
/**
* Get the sum of the given values.
*
* @param callable|string|null $callback
* @return mixed
*/
public function sum($callback = null)
{
if (is_null($callback)) {
$callback = function ($value) {
return $value;
};
} else {
$callback = $this->valueRetriever($callback);
}
return $this->reduce(function ($result, $item) use ($callback) {
return $result + $callback($item);
}, 0);
}
/**
* Apply the callback if the value is truthy.
*
* @param bool|mixed $value
* @param callable $callback
* @param callable $default
* @return static|mixed
*/
public function when($value, callable $callback, callable $default = null)
{
if ($value) {
return $callback($this, $value);
} elseif ($default) {
return $default($this, $value);
}
return $this;
}
/**
* Apply the callback if the collection is empty.
*
* @param callable $callback
* @param callable $default
* @return static|mixed
*/
public function whenEmpty(callable $callback, callable $default = null)
{
return $this->when($this->isEmpty(), $callback, $default);
}
/**
* Apply the callback if the collection is not empty.
*
* @param callable $callback
* @param callable $default
* @return static|mixed
*/
public function whenNotEmpty(callable $callback, callable $default = null)
{
return $this->when($this->isNotEmpty(), $callback, $default);
}
/**
* Apply the callback if the value is falsy.
*
* @param bool $value
* @param callable $callback
* @param callable $default
* @return static|mixed
*/
public function unless($value, callable $callback, callable $default = null)
{
return $this->when(! $value, $callback, $default);
}
/**
* Apply the callback unless the collection is empty.
*
* @param callable $callback
* @param callable $default
* @return static|mixed
*/
public function unlessEmpty(callable $callback, callable $default = null)
{
return $this->whenNotEmpty($callback, $default);
}
/**
* Apply the callback unless the collection is not empty.
*
* @param callable $callback
* @param callable $default
* @return static|mixed
*/
public function unlessNotEmpty(callable $callback, callable $default = null)
{
return $this->whenEmpty($callback, $default);
}
/**
* Filter items by the given key value pair.
*
* @param string $key
* @param mixed $operator
* @param mixed $value
* @return static
*/
public function where($key, $operator = null, $value = null)
{
return $this->filter($this->operatorForWhere(...func_get_args()));
}
/**
* Filter items where the given key is not null.
*
* @param string|null $key
* @return static
*/
public function whereNull($key = null)
{
return $this->whereStrict($key, null);
}
/**
* Filter items where the given key is null.
*
* @param string|null $key
* @return static
*/
public function whereNotNull($key = null)
{
return $this->where($key, '!==', null);
}
/**
* Filter items by the given key value pair using strict comparison.
*
* @param string $key
* @param mixed $value
* @return static
*/
public function whereStrict($key, $value)
{
return $this->where($key, '===', $value);
}
/**
* Filter items by the given key value pair.
*
* @param string $key
* @param mixed $values
* @param bool $strict
* @return static
*/
public function whereIn($key, $values, $strict = false)
{
$values = $this->getArrayableItems($values);
return $this->filter(function ($item) use ($key, $values, $strict) {
return in_array(data_get($item, $key), $values, $strict);
});
}
/**
* Filter items by the given key value pair using strict comparison.
*
* @param string $key
* @param mixed $values
* @return static
*/
public function whereInStrict($key, $values)
{
return $this->whereIn($key, $values, true);
}
/**
* Filter items such that the value of the given key is between the given values.
*
* @param string $key
* @param array $values
* @return static
*/
public function whereBetween($key, $values)
{
return $this->where($key, '>=', reset($values))->where($key, '<=', end($values));
}
/**
* Filter items such that the value of the given key is not between the given values.
*
* @param string $key
* @param array $values
* @return static
*/
public function whereNotBetween($key, $values)
{
return $this->filter(function ($item) use ($key, $values) {
return data_get($item, $key) < reset($values) || data_get($item, $key) > end($values);
});
}
/**
* Filter items by the given key value pair.
*
* @param string $key
* @param mixed $values
* @param bool $strict
* @return static
*/
public function whereNotIn($key, $values, $strict = false)
{
$values = $this->getArrayableItems($values);
return $this->reject(function ($item) use ($key, $values, $strict) {
return in_array(data_get($item, $key), $values, $strict);
});
}
/**
* Filter items by the given key value pair using strict comparison.
*
* @param string $key
* @param mixed $values
* @return static
*/
public function whereNotInStrict($key, $values)
{
return $this->whereNotIn($key, $values, true);
}
/**
* Filter the items, removing any items that don't match the given type.
*
* @param string $type
* @return static
*/
public function whereInstanceOf($type)
{
return $this->filter(function ($value) use ($type) {
return $value instanceof $type;
});
}
/**
* Pass the collection to the given callback and return the result.
*
* @param callable $callback
* @return mixed
*/
public function pipe(callable $callback)
{
return $callback($this);
}
/**
* Pass the collection to the given callback and then return it.
*
* @param callable $callback
* @return $this
*/
public function tap(callable $callback)
{
$callback(clone $this);
return $this;
}
/**
* Create a collection of all elements that do not pass a given truth test.
*
* @param callable|mixed $callback
* @return static
*/
public function reject($callback = true)
{
$useAsCallable = $this->useAsCallable($callback);
return $this->filter(function ($value, $key) use ($callback, $useAsCallable) {
return $useAsCallable
? ! $callback($value, $key)
: $value != $callback;
});
}
/**
* 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.
*
* @param string|callable|null $key
* @return static
*/
public function uniqueStrict($key = null)
{
return $this->unique($key, true);
}
/**
* Collect the values into a collection.
*
* @return \Illuminate\Support\Collection
*/
public function collect()
{
return new Collection($this->all());
}
/**
* Get the collection of items as a plain array.
*
* @return array
*/
public function toArray()
{
return $this->map(function ($value) {
return $value instanceof Arrayable ? $value->toArray() : $value;
})->all();
}
/**
* Convert the object into something JSON serializable.
*
* @return array
*/
public function jsonSerialize()
{
return array_map(function ($value) {
if ($value instanceof JsonSerializable) {
return $value->jsonSerialize();
} elseif ($value instanceof Jsonable) {
return json_decode($value->toJson(), true);
} elseif ($value instanceof Arrayable) {
return $value->toArray();
}
return $value;
}, $this->all());
}
/**
* Get the collection of items as JSON.
*
* @param int $options
* @return string
*/
public function toJson($options = 0)
{
return json_encode($this->jsonSerialize(), $options);
}
/**
* Get a CachingIterator instance.
*
* @param int $flags
* @return \CachingIterator
*/
public function getCachingIterator($flags = CachingIterator::CALL_TOSTRING)
{
return new CachingIterator($this->getIterator(), $flags);
}
/**
* Count the number of items in the collection using a given truth test.
*
* @param callable|null $callback
* @return static
*/
public function countBy($callback = null)
{
if (is_null($callback)) {
$callback = function ($value) {
return $value;
};
}
return new static($this->groupBy($callback)->map(function ($value) {
return $value->count();
}));
}
/**
* Convert the collection to its string representation.
*
* @return string
*/
public function __toString()
{
return $this->toJson();
}
/**
* Add a method to the list of proxied methods.
*
* @param string $method
* @return void
*/
public static function proxy($method)
{
static::$proxies[] = $method;
}
/**
* Dynamically access collection proxies.
*
* @param string $key
* @return mixed
*
* @throws \Exception
*/
public function __get($key)
{
if (! in_array($key, static::$proxies)) {
throw new Exception("Property [{$key}] does not exist on this collection instance.");
}
return new HigherOrderCollectionProxy($this, $key);
}
/**
* Results array of items from Collection or Arrayable.
*
* @param mixed $items
* @return array
*/
protected function getArrayableItems($items)
{
if (is_array($items)) {
return $items;
} elseif ($items instanceof Enumerable) {
return $items->all();
} elseif ($items instanceof Arrayable) {
return $items->toArray();
} elseif ($items instanceof Jsonable) {
return json_decode($items->toJson(), true);
} elseif ($items instanceof JsonSerializable) {
return (array) $items->jsonSerialize();
} elseif ($items instanceof Traversable) {
return iterator_to_array($items);
}
return (array) $items;
}
/**
* Get an operator checker callback.
*
* @param string $key
* @param string|null $operator
* @param mixed $value
* @return \Closure
*/
protected function operatorForWhere($key, $operator = null, $value = null)
{
if (func_num_args() === 1) {
$value = true;
$operator = '=';
}
if (func_num_args() === 2) {
$value = $operator;
$operator = '=';
}
return function ($item) use ($key, $operator, $value) {
$retrieved = data_get($item, $key);
$strings = array_filter([$retrieved, $value], function ($value) {
return is_string($value) || (is_object($value) && method_exists($value, '__toString'));
});
if (count($strings) < 2 && count(array_filter([$retrieved, $value], 'is_object')) == 1) {
return in_array($operator, ['!=', '<>', '!==']);
}
switch ($operator) {
default:
case '=':
case '==': return $retrieved == $value;
case '!=':
case '<>': return $retrieved != $value;
case '<': return $retrieved < $value;
case '>': return $retrieved > $value;
case '<=': return $retrieved <= $value;
case '>=': return $retrieved >= $value;
case '===': return $retrieved === $value;
case '!==': return $retrieved !== $value;
}
};
}
/**
* Determine if the given value is callable, but not a string.
*
* @param mixed $value
* @return bool
*/
protected function useAsCallable($value)
{
return ! is_string($value) && is_callable($value);
}
/**
* Get a value retrieving callback.
*
* @param callable|string|null $value
* @return callable
*/
protected function valueRetriever($value)
{
if ($this->useAsCallable($value)) {
return $value;
}
return function ($item) use ($value) {
return data_get($item, $value);
};
}
}

View File

@@ -2,8 +2,8 @@
namespace Illuminate\Support\Traits;
use Error;
use BadMethodCallException;
use Error;
trait ForwardsCalls
{
@@ -21,7 +21,7 @@ trait ForwardsCalls
{
try {
return $object->{$method}(...$parameters);
} catch (Error | BadMethodCallException $e) {
} catch (Error|BadMethodCallException $e) {
$pattern = '~^Call to undefined method (?P<class>[^:]+)::(?P<method>[^\(]+)\(\)$~';
if (! preg_match($pattern, $e->getMessage(), $matches)) {

View File

@@ -9,8 +9,8 @@ trait Localizable
/**
* Run the callback with the given locale.
*
* @param string $locale
* @param \Closure $callback
* @param string $locale
* @param \Closure $callback
* @return mixed
*/
public function withLocale($locale, $callback)

View File

@@ -2,10 +2,10 @@
namespace Illuminate\Support\Traits;
use BadMethodCallException;
use Closure;
use ReflectionClass;
use ReflectionMethod;
use BadMethodCallException;
trait Macroable
{
@@ -19,9 +19,8 @@ trait Macroable
/**
* Register a custom macro.
*
* @param string $name
* @param string $name
* @param object|callable $macro
*
* @return void
*/
public static function macro($name, $macro)
@@ -83,7 +82,7 @@ trait Macroable
$macro = static::$macros[$method];
if ($macro instanceof Closure) {
return call_user_func_array(Closure::bind($macro, null, static::class), $parameters);
$macro = $macro->bindTo(null, static::class);
}
return $macro(...$parameters);
@@ -109,7 +108,7 @@ trait Macroable
$macro = static::$macros[$method];
if ($macro instanceof Closure) {
return call_user_func_array($macro->bindTo($this, static::class), $parameters);
$macro = $macro->bindTo($this, static::class);
}
return $macro(...$parameters);

View File

@@ -14,12 +14,12 @@
}
],
"require": {
"php": "^7.1.3",
"php": "^7.2.5|^8.0",
"ext-json": "*",
"ext-mbstring": "*",
"doctrine/inflector": "^1.1",
"illuminate/contracts": "5.8.*",
"nesbot/carbon": "^1.26.3 || ^2.0"
"doctrine/inflector": "^1.4|^2.0",
"illuminate/contracts": "^6.0",
"nesbot/carbon": "^2.31"
},
"conflict": {
"tightenco/collect": "<5.5.33"
@@ -34,16 +34,16 @@
},
"extra": {
"branch-alias": {
"dev-master": "5.8-dev"
"dev-master": "6.x-dev"
}
},
"suggest": {
"illuminate/filesystem": "Required to use the composer class (5.8.*).",
"illuminate/filesystem": "Required to use the composer class (^6.0).",
"moontoast/math": "Required to use ordered UUIDs (^1.1).",
"ramsey/uuid": "Required to use Str::uuid() (^3.7).",
"symfony/process": "Required to use the composer class (^4.2).",
"symfony/var-dumper": "Required to use the dd function (^4.2).",
"vlucas/phpdotenv": "Required to use the env helper (^3.3)."
"symfony/process": "Required to use the composer class (^4.3.4).",
"symfony/var-dumper": "Required to use the dd function (^4.3.4).",
"vlucas/phpdotenv": "Required to use the Env class and env helper (^3.3)."
},
"config": {
"sort-packages": true

View File

@@ -1,16 +1,11 @@
<?php
use PhpOption\Option;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Optional;
use Illuminate\Support\Collection;
use Dotenv\Environment\DotenvFactory;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Env;
use Illuminate\Support\HigherOrderTapProxy;
use Dotenv\Environment\Adapter\PutenvAdapter;
use Dotenv\Environment\Adapter\EnvConstAdapter;
use Dotenv\Environment\Adapter\ServerConstAdapter;
use Illuminate\Support\Optional;
if (! function_exists('append_config')) {
/**
@@ -35,348 +30,6 @@ if (! function_exists('append_config')) {
}
}
if (! function_exists('array_add')) {
/**
* Add an element to an array using "dot" notation if it doesn't exist.
*
* @param array $array
* @param string $key
* @param mixed $value
* @return array
*
* @deprecated Arr::add() should be used directly instead. Will be removed in Laravel 6.0.
*/
function array_add($array, $key, $value)
{
return Arr::add($array, $key, $value);
}
}
if (! function_exists('array_collapse')) {
/**
* Collapse an array of arrays into a single array.
*
* @param array $array
* @return array
*
* @deprecated Arr::collapse() should be used directly instead. Will be removed in Laravel 6.0.
*/
function array_collapse($array)
{
return Arr::collapse($array);
}
}
if (! function_exists('array_divide')) {
/**
* Divide an array into two arrays. One with keys and the other with values.
*
* @param array $array
* @return array
*
* @deprecated Arr::divide() should be used directly instead. Will be removed in Laravel 6.0.
*/
function array_divide($array)
{
return Arr::divide($array);
}
}
if (! function_exists('array_dot')) {
/**
* Flatten a multi-dimensional associative array with dots.
*
* @param array $array
* @param string $prepend
* @return array
*
* @deprecated Arr::dot() should be used directly instead. Will be removed in Laravel 6.0.
*/
function array_dot($array, $prepend = '')
{
return Arr::dot($array, $prepend);
}
}
if (! function_exists('array_except')) {
/**
* Get all of the given array except for a specified array of keys.
*
* @param array $array
* @param array|string $keys
* @return array
*
* @deprecated Arr::except() should be used directly instead. Will be removed in Laravel 6.0.
*/
function array_except($array, $keys)
{
return Arr::except($array, $keys);
}
}
if (! function_exists('array_first')) {
/**
* Return the first element in an array passing a given truth test.
*
* @param array $array
* @param callable|null $callback
* @param mixed $default
* @return mixed
*
* @deprecated Arr::first() should be used directly instead. Will be removed in Laravel 6.0.
*/
function array_first($array, callable $callback = null, $default = null)
{
return Arr::first($array, $callback, $default);
}
}
if (! function_exists('array_flatten')) {
/**
* Flatten a multi-dimensional array into a single level.
*
* @param array $array
* @param int $depth
* @return array
*
* @deprecated Arr::flatten() should be used directly instead. Will be removed in Laravel 6.0.
*/
function array_flatten($array, $depth = INF)
{
return Arr::flatten($array, $depth);
}
}
if (! function_exists('array_forget')) {
/**
* Remove one or many array items from a given array using "dot" notation.
*
* @param array $array
* @param array|string $keys
* @return void
*
* @deprecated Arr::forget() should be used directly instead. Will be removed in Laravel 6.0.
*/
function array_forget(&$array, $keys)
{
return Arr::forget($array, $keys);
}
}
if (! function_exists('array_get')) {
/**
* Get an item from an array using "dot" notation.
*
* @param \ArrayAccess|array $array
* @param string $key
* @param mixed $default
* @return mixed
*
* @deprecated Arr::get() should be used directly instead. Will be removed in Laravel 6.0.
*/
function array_get($array, $key, $default = null)
{
return Arr::get($array, $key, $default);
}
}
if (! function_exists('array_has')) {
/**
* Check if an item or items exist in an array using "dot" notation.
*
* @param \ArrayAccess|array $array
* @param string|array $keys
* @return bool
*
* @deprecated Arr::has() should be used directly instead. Will be removed in Laravel 6.0.
*/
function array_has($array, $keys)
{
return Arr::has($array, $keys);
}
}
if (! function_exists('array_last')) {
/**
* Return the last element in an array passing a given truth test.
*
* @param array $array
* @param callable|null $callback
* @param mixed $default
* @return mixed
*
* @deprecated Arr::last() should be used directly instead. Will be removed in Laravel 6.0.
*/
function array_last($array, callable $callback = null, $default = null)
{
return Arr::last($array, $callback, $default);
}
}
if (! function_exists('array_only')) {
/**
* Get a subset of the items from the given array.
*
* @param array $array
* @param array|string $keys
* @return array
*
* @deprecated Arr::only() should be used directly instead. Will be removed in Laravel 6.0.
*/
function array_only($array, $keys)
{
return Arr::only($array, $keys);
}
}
if (! function_exists('array_pluck')) {
/**
* Pluck an array of values from an array.
*
* @param array $array
* @param string|array $value
* @param string|array|null $key
* @return array
*
* @deprecated Arr::pluck() should be used directly instead. Will be removed in Laravel 6.0.
*/
function array_pluck($array, $value, $key = null)
{
return Arr::pluck($array, $value, $key);
}
}
if (! function_exists('array_prepend')) {
/**
* Push an item onto the beginning of an array.
*
* @param array $array
* @param mixed $value
* @param mixed $key
* @return array
*
* @deprecated Arr::prepend() should be used directly instead. Will be removed in Laravel 6.0.
*/
function array_prepend($array, $value, $key = null)
{
return Arr::prepend($array, $value, $key);
}
}
if (! function_exists('array_pull')) {
/**
* Get a value from the array, and remove it.
*
* @param array $array
* @param string $key
* @param mixed $default
* @return mixed
*
* @deprecated Arr::pull() should be used directly instead. Will be removed in Laravel 6.0.
*/
function array_pull(&$array, $key, $default = null)
{
return Arr::pull($array, $key, $default);
}
}
if (! function_exists('array_random')) {
/**
* Get a random value from an array.
*
* @param array $array
* @param int|null $num
* @return mixed
*
* @deprecated Arr::random() should be used directly instead. Will be removed in Laravel 6.0.
*/
function array_random($array, $num = null)
{
return Arr::random($array, $num);
}
}
if (! function_exists('array_set')) {
/**
* Set an array item to a given value using "dot" notation.
*
* If no key is given to the method, the entire array will be replaced.
*
* @param array $array
* @param string $key
* @param mixed $value
* @return array
*
* @deprecated Arr::set() should be used directly instead. Will be removed in Laravel 6.0.
*/
function array_set(&$array, $key, $value)
{
return Arr::set($array, $key, $value);
}
}
if (! function_exists('array_sort')) {
/**
* Sort the array by the given callback or attribute name.
*
* @param array $array
* @param callable|string|null $callback
* @return array
*
* @deprecated Arr::sort() should be used directly instead. Will be removed in Laravel 6.0.
*/
function array_sort($array, $callback = null)
{
return Arr::sort($array, $callback);
}
}
if (! function_exists('array_sort_recursive')) {
/**
* Recursively sort an array by keys and values.
*
* @param array $array
* @return array
*
* @deprecated Arr::sortRecursive() should be used directly instead. Will be removed in Laravel 6.0.
*/
function array_sort_recursive($array)
{
return Arr::sortRecursive($array);
}
}
if (! function_exists('array_where')) {
/**
* Filter the array using the given callback.
*
* @param array $array
* @param callable $callback
* @return array
*
* @deprecated Arr::where() should be used directly instead. Will be removed in Laravel 6.0.
*/
function array_where($array, callable $callback)
{
return Arr::where($array, $callback);
}
}
if (! function_exists('array_wrap')) {
/**
* If the given value is not an array, wrap it in one.
*
* @param mixed $value
* @return array
*
* @deprecated Arr::wrap() should be used directly instead. Will be removed in Laravel 6.0.
*/
function array_wrap($value)
{
return Arr::wrap($value);
}
}
if (! function_exists('blank')) {
/**
* Determine if the given value is "blank".
@@ -406,21 +59,6 @@ if (! function_exists('blank')) {
}
}
if (! function_exists('camel_case')) {
/**
* Convert a value to camel case.
*
* @param string $value
* @return string
*
* @deprecated Str::camel() should be used directly instead. Will be removed in Laravel 6.0.
*/
function camel_case($value)
{
return Str::camel($value);
}
}
if (! function_exists('class_basename')) {
/**
* Get the class "basename" of the given object / class.
@@ -476,7 +114,7 @@ if (! function_exists('data_fill')) {
/**
* Fill in data where it's missing.
*
* @param mixed $target
* @param mixed $target
* @param string|array $key
* @param mixed $value
* @return mixed
@@ -491,9 +129,9 @@ if (! function_exists('data_get')) {
/**
* Get an item from an array or object using "dot" notation.
*
* @param mixed $target
* @param mixed $target
* @param string|array|int $key
* @param mixed $default
* @param mixed $default
* @return mixed
*/
function data_get($target, $key, $default = null)
@@ -614,64 +252,17 @@ if (! function_exists('e')) {
}
}
if (! function_exists('ends_with')) {
/**
* Determine if a given string ends with a given substring.
*
* @param string $haystack
* @param string|array $needles
* @return bool
*
* @deprecated Str::endsWith() should be used directly instead. Will be removed in Laravel 6.0.
*/
function ends_with($haystack, $needles)
{
return Str::endsWith($haystack, $needles);
}
}
if (! function_exists('env')) {
/**
* Gets the value of an environment variable.
*
* @param string $key
* @param mixed $default
* @param mixed $default
* @return mixed
*/
function env($key, $default = null)
{
static $variables;
if ($variables === null) {
$variables = (new DotenvFactory([new EnvConstAdapter, new PutenvAdapter, new ServerConstAdapter]))->createImmutable();
}
return Option::fromValue($variables->get($key))
->map(function ($value) {
switch (strtolower($value)) {
case 'true':
case '(true)':
return true;
case 'false':
case '(false)':
return false;
case 'empty':
case '(empty)':
return '';
case 'null':
case '(null)':
return;
}
if (preg_match('/\A([\'"])(.*)\1\z/', $value, $matches)) {
return $matches[2];
}
return $value;
})
->getOrCall(function () use ($default) {
return value($default);
});
return Env::get($key, $default);
}
}
@@ -701,21 +292,6 @@ if (! function_exists('head')) {
}
}
if (! function_exists('kebab_case')) {
/**
* Convert a string to kebab case.
*
* @param string $value
* @return string
*
* @deprecated Str::kebab() should be used directly instead. Will be removed in Laravel 6.0.
*/
function kebab_case($value)
{
return Str::kebab($value);
}
}
if (! function_exists('last')) {
/**
* Get the last element from an array.
@@ -735,7 +311,7 @@ if (! function_exists('object_get')) {
*
* @param object $object
* @param string $key
* @param mixed $default
* @param mixed $default
* @return mixed
*/
function object_get($object, $key, $default = null)
@@ -779,7 +355,7 @@ if (! function_exists('preg_replace_array')) {
* Replace a given pattern with each value in the array in sequentially.
*
* @param string $pattern
* @param array $replacements
* @param array $replacements
* @param string $subject
* @return string
*/
@@ -808,20 +384,18 @@ if (! function_exists('retry')) {
function retry($times, callable $callback, $sleep = 0, $when = null)
{
$attempts = 0;
$times--;
beginning:
$attempts++;
$times--;
try {
return $callback($attempts);
} catch (Exception $e) {
if (! $times || ($when && ! $when($e))) {
if ($times < 1 || ($when && ! $when($e))) {
throw $e;
}
$times--;
if ($sleep) {
usleep($sleep * 1000);
}
@@ -831,282 +405,6 @@ if (! function_exists('retry')) {
}
}
if (! function_exists('snake_case')) {
/**
* Convert a string to snake case.
*
* @param string $value
* @param string $delimiter
* @return string
*
* @deprecated Str::snake() should be used directly instead. Will be removed in Laravel 6.0.
*/
function snake_case($value, $delimiter = '_')
{
return Str::snake($value, $delimiter);
}
}
if (! function_exists('starts_with')) {
/**
* Determine if a given string starts with a given substring.
*
* @param string $haystack
* @param string|array $needles
* @return bool
*
* @deprecated Str::startsWith() should be used directly instead. Will be removed in Laravel 6.0.
*/
function starts_with($haystack, $needles)
{
return Str::startsWith($haystack, $needles);
}
}
if (! function_exists('str_after')) {
/**
* Return the remainder of a string after a given value.
*
* @param string $subject
* @param string $search
* @return string
*
* @deprecated Str::after() should be used directly instead. Will be removed in Laravel 6.0.
*/
function str_after($subject, $search)
{
return Str::after($subject, $search);
}
}
if (! function_exists('str_before')) {
/**
* Get the portion of a string before a given value.
*
* @param string $subject
* @param string $search
* @return string
*
* @deprecated Str::before() should be used directly instead. Will be removed in Laravel 6.0.
*/
function str_before($subject, $search)
{
return Str::before($subject, $search);
}
}
if (! function_exists('str_contains')) {
/**
* Determine if a given string contains a given substring.
*
* @param string $haystack
* @param string|array $needles
* @return bool
*
* @deprecated Str::contains() should be used directly instead. Will be removed in Laravel 6.0.
*/
function str_contains($haystack, $needles)
{
return Str::contains($haystack, $needles);
}
}
if (! function_exists('str_finish')) {
/**
* Cap a string with a single instance of a given value.
*
* @param string $value
* @param string $cap
* @return string
*
* @deprecated Str::finish() should be used directly instead. Will be removed in Laravel 6.0.
*/
function str_finish($value, $cap)
{
return Str::finish($value, $cap);
}
}
if (! function_exists('str_is')) {
/**
* Determine if a given string matches a given pattern.
*
* @param string|array $pattern
* @param string $value
* @return bool
*
* @deprecated Str::is() should be used directly instead. Will be removed in Laravel 6.0.
*/
function str_is($pattern, $value)
{
return Str::is($pattern, $value);
}
}
if (! function_exists('str_limit')) {
/**
* Limit the number of characters in a string.
*
* @param string $value
* @param int $limit
* @param string $end
* @return string
*
* @deprecated Str::limit() should be used directly instead. Will be removed in Laravel 6.0.
*/
function str_limit($value, $limit = 100, $end = '...')
{
return Str::limit($value, $limit, $end);
}
}
if (! function_exists('str_plural')) {
/**
* Get the plural form of an English word.
*
* @param string $value
* @param int $count
* @return string
*
* @deprecated Str::plural() should be used directly instead. Will be removed in Laravel 6.0.
*/
function str_plural($value, $count = 2)
{
return Str::plural($value, $count);
}
}
if (! function_exists('str_random')) {
/**
* Generate a more truly "random" alpha-numeric string.
*
* @param int $length
* @return string
*
* @throws \RuntimeException
*
* @deprecated Str::random() should be used directly instead. Will be removed in Laravel 6.0.
*/
function str_random($length = 16)
{
return Str::random($length);
}
}
if (! function_exists('str_replace_array')) {
/**
* Replace a given value in the string sequentially with an array.
*
* @param string $search
* @param array $replace
* @param string $subject
* @return string
*
* @deprecated Str::replaceArray() should be used directly instead. Will be removed in Laravel 6.0.
*/
function str_replace_array($search, array $replace, $subject)
{
return Str::replaceArray($search, $replace, $subject);
}
}
if (! function_exists('str_replace_first')) {
/**
* Replace the first occurrence of a given value in the string.
*
* @param string $search
* @param string $replace
* @param string $subject
* @return string
*
* @deprecated Str::replaceFirst() should be used directly instead. Will be removed in Laravel 6.0.
*/
function str_replace_first($search, $replace, $subject)
{
return Str::replaceFirst($search, $replace, $subject);
}
}
if (! function_exists('str_replace_last')) {
/**
* Replace the last occurrence of a given value in the string.
*
* @param string $search
* @param string $replace
* @param string $subject
* @return string
*
* @deprecated Str::replaceLast() should be used directly instead. Will be removed in Laravel 6.0.
*/
function str_replace_last($search, $replace, $subject)
{
return Str::replaceLast($search, $replace, $subject);
}
}
if (! function_exists('str_singular')) {
/**
* Get the singular form of an English word.
*
* @param string $value
* @return string
*
* @deprecated Str::singular() should be used directly instead. Will be removed in Laravel 6.0.
*/
function str_singular($value)
{
return Str::singular($value);
}
}
if (! function_exists('str_slug')) {
/**
* Generate a URL friendly "slug" from a given string.
*
* @param string $title
* @param string $separator
* @param string $language
* @return string
*
* @deprecated Str::slug() should be used directly instead. Will be removed in Laravel 6.0.
*/
function str_slug($title, $separator = '-', $language = 'en')
{
return Str::slug($title, $separator, $language);
}
}
if (! function_exists('str_start')) {
/**
* Begin a string with a single instance of a given value.
*
* @param string $value
* @param string $prefix
* @return string
*
* @deprecated Str::start() should be used directly instead. Will be removed in Laravel 6.0.
*/
function str_start($value, $prefix)
{
return Str::start($value, $prefix);
}
}
if (! function_exists('studly_case')) {
/**
* Convert a value to studly caps case.
*
* @param string $value
* @return string
*
* @deprecated Str::studly() should be used directly instead. Will be removed in Laravel 6.0.
*/
function studly_case($value)
{
return Str::studly($value);
}
}
if (! function_exists('tap')) {
/**
* Call the given Closure with the given value then return the value.
@@ -1156,6 +454,7 @@ if (! function_exists('throw_unless')) {
* @param \Throwable|string $exception
* @param array ...$parameters
* @return mixed
*
* @throws \Throwable
*/
function throw_unless($condition, $exception, ...$parameters)
@@ -1168,21 +467,6 @@ if (! function_exists('throw_unless')) {
}
}
if (! function_exists('title_case')) {
/**
* Convert a value to title case.
*
* @param string $value
* @return string
*
* @deprecated Str::title() should be used directly instead. Will be removed in Laravel 6.0.
*/
function title_case($value)
{
return Str::title($value);
}
}
if (! function_exists('trait_uses_recursive')) {
/**
* Returns all traits used by a trait and its traits.
@@ -1246,7 +530,7 @@ if (! function_exists('windows_os')) {
*/
function windows_os()
{
return strtolower(substr(PHP_OS, 0, 3)) === 'win';
return PHP_OS_FAMILY === 'Windows';
}
}