Update illuminate/database

This commit is contained in:
Floorb 2022-03-14 16:22:30 -04:00
parent 863abeeeaf
commit ba0f8a85f4
980 changed files with 13376 additions and 6966 deletions

View file

@ -18,7 +18,7 @@
"ext-mbstring": "*",
"scrivo/highlight.php": "v9.18.1.7",
"erusev/parsedown": "^1.7",
"illuminate/database": "^8.56",
"illuminate/database": "^9.4",
"ext-redis": "*"
},
"autoload": {

729
composer.lock generated

File diff suppressed because it is too large Load diff

1
vendor/bin/carbon vendored
View file

@ -1 +0,0 @@
../nesbot/carbon/bin/carbon

117
vendor/bin/carbon vendored Executable file
View file

@ -0,0 +1,117 @@
#!/usr/bin/env php
<?php
/**
* Proxy PHP file generated by Composer
*
* This file includes the referenced bin path (../nesbot/carbon/bin/carbon)
* using a stream wrapper to prevent the shebang from being output on PHP<8
*
* @generated
*/
namespace Composer;
$GLOBALS['_composer_bin_dir'] = __DIR__;
$GLOBALS['_composer_autoload_path'] = __DIR__ . '/..'.'/autoload.php';
if (PHP_VERSION_ID < 80000) {
if (!class_exists('Composer\BinProxyWrapper')) {
/**
* @internal
*/
final class BinProxyWrapper
{
private $handle;
private $position;
private $realpath;
public function stream_open($path, $mode, $options, &$opened_path)
{
// get rid of phpvfscomposer:// prefix for __FILE__ & __DIR__ resolution
$opened_path = substr($path, 17);
$this->realpath = realpath($opened_path) ?: $opened_path;
$opened_path = $this->realpath;
$this->handle = fopen($this->realpath, $mode);
$this->position = 0;
return (bool) $this->handle;
}
public function stream_read($count)
{
$data = fread($this->handle, $count);
if ($this->position === 0) {
$data = preg_replace('{^#!.*\r?\n}', '', $data);
}
$this->position += strlen($data);
return $data;
}
public function stream_cast($castAs)
{
return $this->handle;
}
public function stream_close()
{
fclose($this->handle);
}
public function stream_lock($operation)
{
return $operation ? flock($this->handle, $operation) : true;
}
public function stream_seek($offset, $whence)
{
if (0 === fseek($this->handle, $offset, $whence)) {
$this->position = ftell($this->handle);
return true;
}
return false;
}
public function stream_tell()
{
return $this->position;
}
public function stream_eof()
{
return feof($this->handle);
}
public function stream_stat()
{
return array();
}
public function stream_set_option($option, $arg1, $arg2)
{
return true;
}
public function url_stat($path, $flags)
{
$path = substr($path, 17);
if (file_exists($path)) {
return stat($path);
}
return false;
}
}
}
if (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper')) {
include("phpvfscomposer://" . __DIR__ . '/..'.'/nesbot/carbon/bin/carbon');
exit(0);
}
}
include __DIR__ . '/..'.'/nesbot/carbon/bin/carbon';

View file

@ -42,30 +42,75 @@ namespace Composer\Autoload;
*/
class ClassLoader
{
/** @var ?string */
private $vendorDir;
// PSR-4
/**
* @var array[]
* @psalm-var array<string, array<string, int>>
*/
private $prefixLengthsPsr4 = array();
/**
* @var array[]
* @psalm-var array<string, array<int, string>>
*/
private $prefixDirsPsr4 = array();
/**
* @var array[]
* @psalm-var array<string, string>
*/
private $fallbackDirsPsr4 = array();
// PSR-0
/**
* @var array[]
* @psalm-var array<string, array<string, string[]>>
*/
private $prefixesPsr0 = array();
/**
* @var array[]
* @psalm-var array<string, string>
*/
private $fallbackDirsPsr0 = array();
/** @var bool */
private $useIncludePath = false;
/**
* @var string[]
* @psalm-var array<string, string>
*/
private $classMap = array();
/** @var bool */
private $classMapAuthoritative = false;
/**
* @var bool[]
* @psalm-var array<string, bool>
*/
private $missingClasses = array();
/** @var ?string */
private $apcuPrefix;
/**
* @var self[]
*/
private static $registeredLoaders = array();
/**
* @param ?string $vendorDir
*/
public function __construct($vendorDir = null)
{
$this->vendorDir = $vendorDir;
}
/**
* @return string[]
*/
public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
@ -75,28 +120,47 @@ class ClassLoader
return array();
}
/**
* @return array[]
* @psalm-return array<string, array<int, string>>
*/
public function getPrefixesPsr4()
{
return $this->prefixDirsPsr4;
}
/**
* @return array[]
* @psalm-return array<string, string>
*/
public function getFallbackDirs()
{
return $this->fallbackDirsPsr0;
}
/**
* @return array[]
* @psalm-return array<string, string>
*/
public function getFallbackDirsPsr4()
{
return $this->fallbackDirsPsr4;
}
/**
* @return string[] Array of classname => path
* @psalm-return array<string, string>
*/
public function getClassMap()
{
return $this->classMap;
}
/**
* @param array $classMap Class to filename map
* @param string[] $classMap Class to filename map
* @psalm-param array<string, string> $classMap
*
* @return void
*/
public function addClassMap(array $classMap)
{
@ -111,9 +175,11 @@ class ClassLoader
* Registers a set of PSR-0 directories for a given prefix, either
* appending or prepending to the ones previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 root directories
* @param bool $prepend Whether to prepend the directories
* @param string $prefix The prefix
* @param string[]|string $paths The PSR-0 root directories
* @param bool $prepend Whether to prepend the directories
*
* @return void
*/
public function add($prefix, $paths, $prepend = false)
{
@ -156,11 +222,13 @@ class ClassLoader
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prepending to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
* @param bool $prepend Whether to prepend the directories
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param string[]|string $paths The PSR-4 base directories
* @param bool $prepend Whether to prepend the directories
*
* @throws \InvalidArgumentException
*
* @return void
*/
public function addPsr4($prefix, $paths, $prepend = false)
{
@ -204,8 +272,10 @@ class ClassLoader
* Registers a set of PSR-0 directories for a given prefix,
* replacing any others previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 base directories
* @param string $prefix The prefix
* @param string[]|string $paths The PSR-0 base directories
*
* @return void
*/
public function set($prefix, $paths)
{
@ -220,10 +290,12 @@ class ClassLoader
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param string[]|string $paths The PSR-4 base directories
*
* @throws \InvalidArgumentException
*
* @return void
*/
public function setPsr4($prefix, $paths)
{
@ -243,6 +315,8 @@ class ClassLoader
* Turns on searching the include path for class files.
*
* @param bool $useIncludePath
*
* @return void
*/
public function setUseIncludePath($useIncludePath)
{
@ -265,6 +339,8 @@ class ClassLoader
* that have not been registered with the class map.
*
* @param bool $classMapAuthoritative
*
* @return void
*/
public function setClassMapAuthoritative($classMapAuthoritative)
{
@ -285,6 +361,8 @@ class ClassLoader
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
*
* @param string|null $apcuPrefix
*
* @return void
*/
public function setApcuPrefix($apcuPrefix)
{
@ -305,6 +383,8 @@ class ClassLoader
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
*
* @return void
*/
public function register($prepend = false)
{
@ -324,6 +404,8 @@ class ClassLoader
/**
* Unregisters this instance as an autoloader.
*
* @return void
*/
public function unregister()
{
@ -403,6 +485,11 @@ class ClassLoader
return self::$registeredLoaders;
}
/**
* @param string $class
* @param string $ext
* @return string|false
*/
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
@ -474,6 +561,10 @@ class ClassLoader
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*
* @param string $file
* @return void
* @private
*/
function includeFile($file)
{

View file

@ -20,12 +20,25 @@ use Composer\Semver\VersionParser;
*
* See also https://getcomposer.org/doc/07-runtime.md#installed-versions
*
* To require it's presence, you can require `composer-runtime-api ^2.0`
* To require its presence, you can require `composer-runtime-api ^2.0`
*/
class InstalledVersions
{
/**
* @var mixed[]|null
* @psalm-var array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}|array{}|null
*/
private static $installed;
/**
* @var bool|null
*/
private static $canGetVendors;
/**
* @var array[]
* @psalm-var array<string, array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
*/
private static $installedByVendor = array();
/**
@ -228,7 +241,7 @@ class InstalledVersions
/**
* @return array
* @psalm-return array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string}
* @psalm-return array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}
*/
public static function getRootPackage()
{
@ -242,7 +255,7 @@ class InstalledVersions
*
* @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect.
* @return array[]
* @psalm-return array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string}>}
* @psalm-return array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}
*/
public static function getRawData()
{
@ -265,7 +278,7 @@ class InstalledVersions
* Returns the raw data of all installed.php which are currently loaded for custom implementations
*
* @return array[]
* @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string}>}>
* @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
*/
public static function getAllRawData()
{
@ -288,7 +301,7 @@ class InstalledVersions
* @param array[] $data A vendor/composer/installed.php data set
* @return void
*
* @psalm-param array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string}>} $data
* @psalm-param array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>} $data
*/
public static function reload($data)
{
@ -298,7 +311,7 @@ class InstalledVersions
/**
* @return array[]
* @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string}>}>
* @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
*/
private static function getInstalled()
{

View file

@ -8,8 +8,8 @@ $baseDir = dirname($vendorDir);
return array(
'Attribute' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/Attribute.php',
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
'JsonException' => $vendorDir . '/symfony/polyfill-php73/Resources/stubs/JsonException.php',
'Normalizer' => $vendorDir . '/symfony/polyfill-intl-normalizer/Resources/stubs/Normalizer.php',
'PhpToken' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/PhpToken.php',
'Stringable' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/Stringable.php',
'UnhandledMatchError' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php',
'ValueError' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/ValueError.php',

View file

@ -7,15 +7,13 @@ $baseDir = dirname($vendorDir);
return array(
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',
'a4a119a56e50fbb293281d9a48007e0e' => $vendorDir . '/symfony/polyfill-php80/bootstrap.php',
'6e3fae29631ef280660b3cdad06f25a8' => $vendorDir . '/symfony/deprecation-contracts/function.php',
'320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php',
'8825ede83f2f289127722d4e842cf7e8' => $vendorDir . '/symfony/polyfill-intl-grapheme/bootstrap.php',
'e69f7f6ee287b969198c3c9d6777bd38' => $vendorDir . '/symfony/polyfill-intl-normalizer/bootstrap.php',
'0d59ee240a4cd96ddbb4ff164fccea4d' => $vendorDir . '/symfony/polyfill-php73/bootstrap.php',
'8825ede83f2f289127722d4e842cf7e8' => $vendorDir . '/symfony/polyfill-intl-grapheme/bootstrap.php',
'320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php',
'b6b991a57620e2fb6b2f66f03fe9ddc2' => $vendorDir . '/symfony/string/Resources/functions.php',
'60799491728b879e74601d83e38b2cad' => $vendorDir . '/illuminate/collections/helpers.php',
'a1105708a18b76903365ca1c4aa61b02' => $vendorDir . '/symfony/translation/Resources/functions.php',
'a4a119a56e50fbb293281d9a48007e0e' => $vendorDir . '/symfony/polyfill-php80/bootstrap.php',
'60799491728b879e74601d83e38b2cad' => $vendorDir . '/illuminate/collections/helpers.php',
'72579e7bd17821bb1321b87411366eae' => $vendorDir . '/illuminate/support/helpers.php',
'b6ec61354e97f32c0ae683041c78392a' => $vendorDir . '/scrivo/highlight.php/HighlightUtilities/functions.php',
);

View file

@ -8,7 +8,6 @@ $baseDir = dirname($vendorDir);
return array(
'voku\\' => array($vendorDir . '/voku/portable-ascii/src/voku'),
'Symfony\\Polyfill\\Php80\\' => array($vendorDir . '/symfony/polyfill-php80'),
'Symfony\\Polyfill\\Php73\\' => array($vendorDir . '/symfony/polyfill-php73'),
'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'),
'Symfony\\Polyfill\\Intl\\Normalizer\\' => array($vendorDir . '/symfony/polyfill-intl-normalizer'),
'Symfony\\Polyfill\\Intl\\Grapheme\\' => array($vendorDir . '/symfony/polyfill-intl-grapheme'),
@ -21,7 +20,7 @@ return array(
'Psr\\SimpleCache\\' => array($vendorDir . '/psr/simple-cache/src'),
'Psr\\Container\\' => array($vendorDir . '/psr/container/src'),
'PonePaste\\' => array($baseDir . '/includes'),
'Illuminate\\Support\\' => array($vendorDir . '/illuminate/collections', $vendorDir . '/illuminate/macroable', $vendorDir . '/illuminate/support'),
'Illuminate\\Support\\' => array($vendorDir . '/illuminate/conditionable', $vendorDir . '/illuminate/macroable', $vendorDir . '/illuminate/collections', $vendorDir . '/illuminate/support'),
'Illuminate\\Database\\' => array($vendorDir . '/illuminate/database'),
'Illuminate\\Contracts\\' => array($vendorDir . '/illuminate/contracts'),
'Illuminate\\Container\\' => array($vendorDir . '/illuminate/container'),

View file

@ -65,11 +65,16 @@ class ComposerAutoloaderInit5bf95489f4eff2c10ec062bf7ba377da
}
}
/**
* @param string $fileIdentifier
* @param string $file
* @return void
*/
function composerRequire5bf95489f4eff2c10ec062bf7ba377da($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
require $file;
}
}

View file

@ -8,15 +8,13 @@ class ComposerStaticInit5bf95489f4eff2c10ec062bf7ba377da
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
'6e3fae29631ef280660b3cdad06f25a8' => __DIR__ . '/..' . '/symfony/deprecation-contracts/function.php',
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
'8825ede83f2f289127722d4e842cf7e8' => __DIR__ . '/..' . '/symfony/polyfill-intl-grapheme/bootstrap.php',
'e69f7f6ee287b969198c3c9d6777bd38' => __DIR__ . '/..' . '/symfony/polyfill-intl-normalizer/bootstrap.php',
'0d59ee240a4cd96ddbb4ff164fccea4d' => __DIR__ . '/..' . '/symfony/polyfill-php73/bootstrap.php',
'8825ede83f2f289127722d4e842cf7e8' => __DIR__ . '/..' . '/symfony/polyfill-intl-grapheme/bootstrap.php',
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
'b6b991a57620e2fb6b2f66f03fe9ddc2' => __DIR__ . '/..' . '/symfony/string/Resources/functions.php',
'60799491728b879e74601d83e38b2cad' => __DIR__ . '/..' . '/illuminate/collections/helpers.php',
'a1105708a18b76903365ca1c4aa61b02' => __DIR__ . '/..' . '/symfony/translation/Resources/functions.php',
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
'60799491728b879e74601d83e38b2cad' => __DIR__ . '/..' . '/illuminate/collections/helpers.php',
'72579e7bd17821bb1321b87411366eae' => __DIR__ . '/..' . '/illuminate/support/helpers.php',
'b6ec61354e97f32c0ae683041c78392a' => __DIR__ . '/..' . '/scrivo/highlight.php/HighlightUtilities/functions.php',
);
@ -29,7 +27,6 @@ class ComposerStaticInit5bf95489f4eff2c10ec062bf7ba377da
'S' =>
array (
'Symfony\\Polyfill\\Php80\\' => 23,
'Symfony\\Polyfill\\Php73\\' => 23,
'Symfony\\Polyfill\\Mbstring\\' => 26,
'Symfony\\Polyfill\\Intl\\Normalizer\\' => 33,
'Symfony\\Polyfill\\Intl\\Grapheme\\' => 31,
@ -72,10 +69,6 @@ class ComposerStaticInit5bf95489f4eff2c10ec062bf7ba377da
array (
0 => __DIR__ . '/..' . '/symfony/polyfill-php80',
),
'Symfony\\Polyfill\\Php73\\' =>
array (
0 => __DIR__ . '/..' . '/symfony/polyfill-php73',
),
'Symfony\\Polyfill\\Mbstring\\' =>
array (
0 => __DIR__ . '/..' . '/symfony/polyfill-mbstring',
@ -126,9 +119,10 @@ class ComposerStaticInit5bf95489f4eff2c10ec062bf7ba377da
),
'Illuminate\\Support\\' =>
array (
0 => __DIR__ . '/..' . '/illuminate/collections',
0 => __DIR__ . '/..' . '/illuminate/conditionable',
1 => __DIR__ . '/..' . '/illuminate/macroable',
2 => __DIR__ . '/..' . '/illuminate/support',
2 => __DIR__ . '/..' . '/illuminate/collections',
3 => __DIR__ . '/..' . '/illuminate/support',
),
'Illuminate\\Database\\' =>
array (
@ -176,8 +170,8 @@ class ComposerStaticInit5bf95489f4eff2c10ec062bf7ba377da
public static $classMap = array (
'Attribute' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/Attribute.php',
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
'JsonException' => __DIR__ . '/..' . '/symfony/polyfill-php73/Resources/stubs/JsonException.php',
'Normalizer' => __DIR__ . '/..' . '/symfony/polyfill-intl-normalizer/Resources/stubs/Normalizer.php',
'PhpToken' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/PhpToken.php',
'Stringable' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/Stringable.php',
'UnhandledMatchError' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php',
'ValueError' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/ValueError.php',

File diff suppressed because it is too large Load diff

View file

@ -5,7 +5,7 @@
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '070545e294d5191c315f4691080b63cd083955b1',
'reference' => '3c0fc75d296bbf2703fa00ff1a7ece4cc9c2164e',
'name' => 'aftercase/ponepaste',
'dev' => true,
),
@ -16,16 +16,16 @@
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '070545e294d5191c315f4691080b63cd083955b1',
'reference' => '3c0fc75d296bbf2703fa00ff1a7ece4cc9c2164e',
'dev_requirement' => false,
),
'doctrine/inflector' => array(
'pretty_version' => '2.0.3',
'version' => '2.0.3.0',
'pretty_version' => '2.0.4',
'version' => '2.0.4.0',
'type' => 'library',
'install_path' => __DIR__ . '/../doctrine/inflector',
'aliases' => array(),
'reference' => '9cf661f4eb38f7c881cac67c75ea9b00bf97b210',
'reference' => '8b7ff3e4b7de6b2c84da85637b59fd2880ecaa89',
'dev_requirement' => false,
),
'erusev/parsedown' => array(
@ -38,96 +38,105 @@
'dev_requirement' => false,
),
'illuminate/collections' => array(
'pretty_version' => 'v8.57.0',
'version' => '8.57.0.0',
'pretty_version' => 'v9.4.1',
'version' => '9.4.1.0',
'type' => 'library',
'install_path' => __DIR__ . '/../illuminate/collections',
'aliases' => array(),
'reference' => '673d71d9db2827b04c096c4fe9739edddea14ac4',
'reference' => '22c4bb17f4e6c6fb470b5957e8232b1b5baf76b0',
'dev_requirement' => false,
),
'illuminate/conditionable' => array(
'pretty_version' => 'v9.4.1',
'version' => '9.4.1.0',
'type' => 'library',
'install_path' => __DIR__ . '/../illuminate/conditionable',
'aliases' => array(),
'reference' => '56b4ba1166c264064bf63896f498a2bee320d16a',
'dev_requirement' => false,
),
'illuminate/container' => array(
'pretty_version' => 'v8.57.0',
'version' => '8.57.0.0',
'pretty_version' => 'v9.4.1',
'version' => '9.4.1.0',
'type' => 'library',
'install_path' => __DIR__ . '/../illuminate/container',
'aliases' => array(),
'reference' => 'ecb645e1838cdee62eebd07ded490b1de5505f35',
'reference' => '66f9049b19fb34e74134c6eeff92a442cee068e5',
'dev_requirement' => false,
),
'illuminate/contracts' => array(
'pretty_version' => 'v8.57.0',
'version' => '8.57.0.0',
'pretty_version' => 'v9.4.1',
'version' => '9.4.1.0',
'type' => 'library',
'install_path' => __DIR__ . '/../illuminate/contracts',
'aliases' => array(),
'reference' => '7354badf7b57eae805a56d1163fb023e0f58a639',
'reference' => 'ce68106c575410c71f92ac1c91c5d95c561033bc',
'dev_requirement' => false,
),
'illuminate/database' => array(
'pretty_version' => 'v8.57.0',
'version' => '8.57.0.0',
'pretty_version' => 'v9.4.1',
'version' => '9.4.1.0',
'type' => 'library',
'install_path' => __DIR__ . '/../illuminate/database',
'aliases' => array(),
'reference' => '828d1cd4ee824c405f6edc52ab3d333b549be4ee',
'reference' => '0fffd6ba91eb58330cbf7331c77ea38c2a16b5d9',
'dev_requirement' => false,
),
'illuminate/macroable' => array(
'pretty_version' => 'v8.57.0',
'version' => '8.57.0.0',
'pretty_version' => 'v9.4.1',
'version' => '9.4.1.0',
'type' => 'library',
'install_path' => __DIR__ . '/../illuminate/macroable',
'aliases' => array(),
'reference' => '300aa13c086f25116b5f3cde3ca54ff5c822fb05',
'reference' => '25a2c6dac2b7541ecbadef952702e84ae15f5354',
'dev_requirement' => false,
),
'illuminate/support' => array(
'pretty_version' => 'v8.57.0',
'version' => '8.57.0.0',
'pretty_version' => 'v9.4.1',
'version' => '9.4.1.0',
'type' => 'library',
'install_path' => __DIR__ . '/../illuminate/support',
'aliases' => array(),
'reference' => '5e8f059a5d1f298324e847822b997778a3472128',
'reference' => '568ed7a21a75e0bd9ca641b6c4a626872ee26d6f',
'dev_requirement' => false,
),
'nesbot/carbon' => array(
'pretty_version' => '2.52.0',
'version' => '2.52.0.0',
'pretty_version' => '2.57.0',
'version' => '2.57.0.0',
'type' => 'library',
'install_path' => __DIR__ . '/../nesbot/carbon',
'aliases' => array(),
'reference' => '369c0e2737c56a0f39c946dd261855255a6fccbe',
'reference' => '4a54375c21eea4811dbd1149fe6b246517554e78',
'dev_requirement' => false,
),
'psr/container' => array(
'pretty_version' => '1.1.1',
'version' => '1.1.1.0',
'pretty_version' => '2.0.2',
'version' => '2.0.2.0',
'type' => 'library',
'install_path' => __DIR__ . '/../psr/container',
'aliases' => array(),
'reference' => '8622567409010282b7aeebe4bb841fe98b58dcaf',
'reference' => 'c71ecc56dfe541dbd90c5360474fbc405f8d5963',
'dev_requirement' => false,
),
'psr/container-implementation' => array(
'dev_requirement' => false,
'provided' => array(
0 => '1.0',
0 => '1.1|2.0',
),
),
'psr/log-implementation' => array(
'dev_requirement' => false,
'provided' => array(
0 => '1.0|2.0',
0 => '1.0|2.0|3.0',
),
),
'psr/simple-cache' => array(
'pretty_version' => '1.0.1',
'version' => '1.0.1.0',
'pretty_version' => '3.0.0',
'version' => '3.0.0.0',
'type' => 'library',
'install_path' => __DIR__ . '/../psr/simple-cache',
'aliases' => array(),
'reference' => '408d5eafb83c57f6365a3ca330ff23aa4a5fa39b',
'reference' => '764e0b3939f5ca87cb904f570ef9be2d78a07865',
'dev_requirement' => false,
),
'scrivo/highlight.php' => array(
@ -140,44 +149,35 @@
'dev_requirement' => false,
),
'symfony/console' => array(
'pretty_version' => 'v5.3.6',
'version' => '5.3.6.0',
'pretty_version' => 'v6.0.5',
'version' => '6.0.5.0',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/console',
'aliases' => array(),
'reference' => '51b71afd6d2dc8f5063199357b9880cea8d8bfe2',
'dev_requirement' => false,
),
'symfony/deprecation-contracts' => array(
'pretty_version' => 'v2.4.0',
'version' => '2.4.0.0',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/deprecation-contracts',
'aliases' => array(),
'reference' => '5f38c8804a9e97d23e0c8d63341088cd8a22d627',
'reference' => '3bebf4108b9e07492a2a4057d207aa5a77d146b1',
'dev_requirement' => false,
),
'symfony/polyfill-ctype' => array(
'pretty_version' => 'v1.23.0',
'version' => '1.23.0.0',
'pretty_version' => 'v1.25.0',
'version' => '1.25.0.0',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/polyfill-ctype',
'aliases' => array(),
'reference' => '46cd95797e9df938fdd2b03693b5fca5e64b01ce',
'reference' => '30885182c981ab175d4d034db0f6f469898070ab',
'dev_requirement' => false,
),
'symfony/polyfill-intl-grapheme' => array(
'pretty_version' => 'v1.23.1',
'version' => '1.23.1.0',
'pretty_version' => 'v1.25.0',
'version' => '1.25.0.0',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/polyfill-intl-grapheme',
'aliases' => array(),
'reference' => '16880ba9c5ebe3642d1995ab866db29270b36535',
'reference' => '81b86b50cf841a64252b439e738e97f4a34e2783',
'dev_requirement' => false,
),
'symfony/polyfill-intl-normalizer' => array(
'pretty_version' => 'v1.23.0',
'version' => '1.23.0.0',
'pretty_version' => 'v1.25.0',
'version' => '1.25.0.0',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/polyfill-intl-normalizer',
'aliases' => array(),
@ -185,81 +185,72 @@
'dev_requirement' => false,
),
'symfony/polyfill-mbstring' => array(
'pretty_version' => 'v1.23.1',
'version' => '1.23.1.0',
'pretty_version' => 'v1.25.0',
'version' => '1.25.0.0',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/polyfill-mbstring',
'aliases' => array(),
'reference' => '9174a3d80210dca8daa7f31fec659150bbeabfc6',
'dev_requirement' => false,
),
'symfony/polyfill-php73' => array(
'pretty_version' => 'v1.23.0',
'version' => '1.23.0.0',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/polyfill-php73',
'aliases' => array(),
'reference' => 'fba8933c384d6476ab14fb7b8526e5287ca7e010',
'reference' => '0abb51d2f102e00a4eefcf46ba7fec406d245825',
'dev_requirement' => false,
),
'symfony/polyfill-php80' => array(
'pretty_version' => 'v1.23.1',
'version' => '1.23.1.0',
'pretty_version' => 'v1.25.0',
'version' => '1.25.0.0',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/polyfill-php80',
'aliases' => array(),
'reference' => '1100343ed1a92e3a38f9ae122fc0eb21602547be',
'reference' => '4407588e0d3f1f52efb65fbe92babe41f37fe50c',
'dev_requirement' => false,
),
'symfony/service-contracts' => array(
'pretty_version' => 'v2.4.0',
'version' => '2.4.0.0',
'pretty_version' => 'v3.0.0',
'version' => '3.0.0.0',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/service-contracts',
'aliases' => array(),
'reference' => 'f040a30e04b57fbcc9c6cbcf4dbaa96bd318b9bb',
'reference' => '36715ebf9fb9db73db0cb24263c79077c6fe8603',
'dev_requirement' => false,
),
'symfony/string' => array(
'pretty_version' => 'v5.3.3',
'version' => '5.3.3.0',
'pretty_version' => 'v6.0.3',
'version' => '6.0.3.0',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/string',
'aliases' => array(),
'reference' => 'bd53358e3eccec6a670b5f33ab680d8dbe1d4ae1',
'reference' => '522144f0c4c004c80d56fa47e40e17028e2eefc2',
'dev_requirement' => false,
),
'symfony/translation' => array(
'pretty_version' => 'v5.3.4',
'version' => '5.3.4.0',
'pretty_version' => 'v6.0.6',
'version' => '6.0.6.0',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/translation',
'aliases' => array(),
'reference' => 'd89ad7292932c2699cbe4af98d72c5c6bbc504c1',
'reference' => 'f6639cb9b5e0c57fe31e3263b900a77eedb0c908',
'dev_requirement' => false,
),
'symfony/translation-contracts' => array(
'pretty_version' => 'v2.4.0',
'version' => '2.4.0.0',
'pretty_version' => 'v3.0.0',
'version' => '3.0.0.0',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/translation-contracts',
'aliases' => array(),
'reference' => '95c812666f3e91db75385749fe219c5e494c7f95',
'reference' => '1b6ea5a7442af5a12dba3dbd6d71034b5b234e77',
'dev_requirement' => false,
),
'symfony/translation-implementation' => array(
'dev_requirement' => false,
'provided' => array(
0 => '2.3',
0 => '2.3|3.0',
),
),
'voku/portable-ascii' => array(
'pretty_version' => '1.5.6',
'version' => '1.5.6.0',
'pretty_version' => '2.0.1',
'version' => '2.0.1.0',
'type' => 'library',
'install_path' => __DIR__ . '/../voku/portable-ascii',
'aliases' => array(),
'reference' => '80953678b19901e5165c56752d087fc11526017c',
'reference' => 'b56450eed252f6801410d810c8e1727224ae0743',
'dev_requirement' => false,
),
),

View file

@ -4,8 +4,8 @@
$issues = array();
if (!(PHP_VERSION_ID >= 70300)) {
$issues[] = 'Your Composer dependencies require a PHP version ">= 7.3.0". You are running ' . PHP_VERSION . '.';
if (!(PHP_VERSION_ID >= 80002)) {
$issues[] = 'Your Composer dependencies require a PHP version ">= 8.0.2". You are running ' . PHP_VERSION . '.';
}
if ($issues) {

View file

@ -3,6 +3,5 @@
Doctrine Inflector is a small library that can perform string manipulations
with regard to uppercase/lowercase and singular/plural forms of words.
[![Build Status](https://travis-ci.org/doctrine/inflector.svg)](https://travis-ci.org/doctrine/inflector)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/doctrine/inflector/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/doctrine/inflector/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/doctrine/inflector/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/doctrine/inflector/?branch=master)
[![Build Status](https://github.com/doctrine/inflector/workflows/Continuous%20Integration/badge.svg)](https://github.com/doctrine/inflector/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A4.0.x)
[![Code Coverage](https://codecov.io/gh/doctrine/inflector/branch/2.0.x/graph/badge.svg)](https://codecov.io/gh/doctrine/inflector/branch/2.0.x)

View file

@ -16,11 +16,12 @@
"php": "^7.2 || ^8.0"
},
"require-dev": {
"doctrine/coding-standard": "^7.0",
"phpstan/phpstan": "^0.11",
"phpstan/phpstan-phpunit": "^0.11",
"phpstan/phpstan-strict-rules": "^0.11",
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0"
"doctrine/coding-standard": "^8.2",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"phpstan/phpstan-strict-rules": "^0.12",
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0",
"vimeo/psalm": "^4.10"
},
"autoload": {
"psr-4": {
@ -31,10 +32,5 @@
"psr-4": {
"Doctrine\\Tests\\Inflector\\": "tests/Doctrine/Tests/Inflector"
}
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
}
}

View file

@ -17,7 +17,7 @@ class CachedWordInflector implements WordInflector
$this->wordInflector = $wordInflector;
}
public function inflect(string $word) : string
public function inflect(string $word): string
{
return $this->cache[$word] ?? $this->cache[$word] = $this->wordInflector->inflect($word);
}

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Doctrine\Inflector;
use Doctrine\Inflector\Rules\Ruleset;
use function array_unshift;
abstract class GenericLanguageInflectorFactory implements LanguageInflectorFactory
@ -21,7 +22,7 @@ abstract class GenericLanguageInflectorFactory implements LanguageInflectorFacto
$this->pluralRulesets[] = $this->getPluralRuleset();
}
final public function build() : Inflector
final public function build(): Inflector
{
return new Inflector(
new CachedWordInflector(new RulesetInflector(
@ -33,7 +34,7 @@ abstract class GenericLanguageInflectorFactory implements LanguageInflectorFacto
);
}
final public function withSingularRules(?Ruleset $singularRules, bool $reset = false) : LanguageInflectorFactory
final public function withSingularRules(?Ruleset $singularRules, bool $reset = false): LanguageInflectorFactory
{
if ($reset) {
$this->singularRulesets = [];
@ -46,7 +47,7 @@ abstract class GenericLanguageInflectorFactory implements LanguageInflectorFacto
return $this;
}
final public function withPluralRules(?Ruleset $pluralRules, bool $reset = false) : LanguageInflectorFactory
final public function withPluralRules(?Ruleset $pluralRules, bool $reset = false): LanguageInflectorFactory
{
if ($reset) {
$this->pluralRulesets = [];
@ -59,7 +60,7 @@ abstract class GenericLanguageInflectorFactory implements LanguageInflectorFacto
return $this;
}
abstract protected function getSingularRuleset() : Ruleset;
abstract protected function getSingularRuleset(): Ruleset;
abstract protected function getPluralRuleset() : Ruleset;
abstract protected function getPluralRuleset(): Ruleset;
}

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Doctrine\Inflector;
use RuntimeException;
use function chr;
use function function_exists;
use function lcfirst;
@ -228,7 +229,7 @@ class Inflector
/**
* Converts a word into the format for a Doctrine table name. Converts 'ModelName' to 'model_name'.
*/
public function tableize(string $word) : string
public function tableize(string $word): string
{
$tableized = preg_replace('~(?<=\\w)([A-Z])~u', '_$1', $word);
@ -245,7 +246,7 @@ class Inflector
/**
* Converts a word into the format for a Doctrine class name. Converts 'table_name' to 'TableName'.
*/
public function classify(string $word) : string
public function classify(string $word): string
{
return str_replace([' ', '_', '-'], '', ucwords($word, ' _-'));
}
@ -253,7 +254,7 @@ class Inflector
/**
* Camelizes a word. This uses the classify() method and turns the first character to lowercase.
*/
public function camelize(string $word) : string
public function camelize(string $word): string
{
return lcfirst($this->classify($word));
}
@ -283,7 +284,7 @@ class Inflector
*
* @return string The string with all delimiter-separated words capitalized.
*/
public function capitalize(string $string, string $delimiters = " \n\t\r\0\x0B-") : string
public function capitalize(string $string, string $delimiters = " \n\t\r\0\x0B-"): string
{
return ucwords($string, $delimiters);
}
@ -293,7 +294,7 @@ class Inflector
*
* @param string $string The string to check for utf8 characters in.
*/
public function seemsUtf8(string $string) : bool
public function seemsUtf8(string $string): bool
{
for ($i = 0; $i < strlen($string); $i++) {
if (ord($string[$i]) < 0x80) {
@ -331,7 +332,7 @@ class Inflector
*
* @return string Unaccented string
*/
public function unaccent(string $string) : string
public function unaccent(string $string): string
{
if (preg_match('/[\x80-\xff]/', $string) === false) {
return $string;
@ -444,7 +445,7 @@ class Inflector
*
* @return string Urlized string.
*/
public function urlize(string $string) : string
public function urlize(string $string): string
{
// Remove all non url friendly characters with the unaccent function
$unaccented = $this->unaccent($string);
@ -487,7 +488,7 @@ class Inflector
*
* @return string The word in singular form.
*/
public function singularize(string $word) : string
public function singularize(string $word): string
{
return $this->singularizer->inflect($word);
}
@ -499,7 +500,7 @@ class Inflector
*
* @return string The word in plural form.
*/
public function pluralize(string $word) : string
public function pluralize(string $word): string
{
return $this->pluralizer->inflect($word);
}

View file

@ -11,30 +11,37 @@ use Doctrine\Inflector\Rules\Portuguese;
use Doctrine\Inflector\Rules\Spanish;
use Doctrine\Inflector\Rules\Turkish;
use InvalidArgumentException;
use function sprintf;
final class InflectorFactory
{
public static function create() : LanguageInflectorFactory
public static function create(): LanguageInflectorFactory
{
return self::createForLanguage(Language::ENGLISH);
}
public static function createForLanguage(string $language) : LanguageInflectorFactory
public static function createForLanguage(string $language): LanguageInflectorFactory
{
switch ($language) {
case Language::ENGLISH:
return new English\InflectorFactory();
case Language::FRENCH:
return new French\InflectorFactory();
case Language::NORWEGIAN_BOKMAL:
return new NorwegianBokmal\InflectorFactory();
case Language::PORTUGUESE:
return new Portuguese\InflectorFactory();
case Language::SPANISH:
return new Spanish\InflectorFactory();
case Language::TURKISH:
return new Turkish\InflectorFactory();
default:
throw new InvalidArgumentException(sprintf(
'Language "%s" is not supported.',

View file

@ -15,7 +15,7 @@ interface LanguageInflectorFactory
*
* @return $this
*/
public function withSingularRules(?Ruleset $singularRules, bool $reset = false) : self;
public function withSingularRules(?Ruleset $singularRules, bool $reset = false): self;
/**
* Applies custom rules for pluralisation
@ -24,10 +24,10 @@ interface LanguageInflectorFactory
*
* @return $this
*/
public function withPluralRules(?Ruleset $pluralRules, bool $reset = false) : self;
public function withPluralRules(?Ruleset $pluralRules, bool $reset = false): self;
/**
* Builds the inflector instance with all applicable rules
*/
public function build() : Inflector;
public function build(): Inflector;
}

View file

@ -6,7 +6,7 @@ namespace Doctrine\Inflector;
class NoopWordInflector implements WordInflector
{
public function inflect(string $word) : string
public function inflect(string $word): string
{
return $word;
}

View file

@ -14,7 +14,7 @@ class Inflectible
/**
* @return Transformation[]
*/
public static function getSingular() : iterable
public static function getSingular(): iterable
{
yield new Transformation(new Pattern('(s)tatuses$'), '\1\2tatus');
yield new Transformation(new Pattern('(s)tatus$'), '\1\2tatus');
@ -62,7 +62,7 @@ class Inflectible
/**
* @return Transformation[]
*/
public static function getPlural() : iterable
public static function getPlural(): iterable
{
yield new Transformation(new Pattern('(s)tatus$'), '\1\2tatuses');
yield new Transformation(new Pattern('(quiz)$'), '\1zes');
@ -94,7 +94,7 @@ class Inflectible
/**
* @return Substitution[]
*/
public static function getIrregular() : iterable
public static function getIrregular(): iterable
{
yield new Substitution(new Word('atlas'), new Word('atlases'));
yield new Substitution(new Word('axe'), new Word('axes'));

View file

@ -9,12 +9,12 @@ use Doctrine\Inflector\Rules\Ruleset;
final class InflectorFactory extends GenericLanguageInflectorFactory
{
protected function getSingularRuleset() : Ruleset
protected function getSingularRuleset(): Ruleset
{
return Rules::getSingularRuleset();
}
protected function getPluralRuleset() : Ruleset
protected function getPluralRuleset(): Ruleset
{
return Rules::getPluralRuleset();
}

View file

@ -11,7 +11,7 @@ use Doctrine\Inflector\Rules\Transformations;
final class Rules
{
public static function getSingularRuleset() : Ruleset
public static function getSingularRuleset(): Ruleset
{
return new Ruleset(
new Transformations(...Inflectible::getSingular()),
@ -20,7 +20,7 @@ final class Rules
);
}
public static function getPluralRuleset() : Ruleset
public static function getPluralRuleset(): Ruleset
{
return new Ruleset(
new Transformations(...Inflectible::getPlural()),

View file

@ -11,7 +11,7 @@ final class Uninflected
/**
* @return Pattern[]
*/
public static function getSingular() : iterable
public static function getSingular(): iterable
{
yield from self::getDefault();
@ -33,7 +33,7 @@ final class Uninflected
/**
* @return Pattern[]
*/
public static function getPlural() : iterable
public static function getPlural(): iterable
{
yield from self::getDefault();
@ -46,7 +46,7 @@ final class Uninflected
/**
* @return Pattern[]
*/
private static function getDefault() : iterable
private static function getDefault(): iterable
{
yield new Pattern('\w+media');
yield new Pattern('advice');

View file

@ -14,7 +14,7 @@ class Inflectible
/**
* @return Transformation[]
*/
public static function getSingular() : iterable
public static function getSingular(): iterable
{
yield new Transformation(new Pattern('/(b|cor|ém|gemm|soupir|trav|vant|vitr)aux$/'), '\1ail');
yield new Transformation(new Pattern('/ails$/'), 'ail');
@ -26,21 +26,22 @@ class Inflectible
/**
* @return Transformation[]
*/
public static function getPlural() : iterable
public static function getPlural(): iterable
{
yield new Transformation(new Pattern('/(s|x|z)$/'), '\1');
yield new Transformation(new Pattern('/(b|cor|ém|gemm|soupir|trav|vant|vitr)ail$/'), '\1aux');
yield new Transformation(new Pattern('/ail$/'), 'ails');
yield new Transformation(new Pattern('/(chacal|carnaval|festival|récital)$/'), '\1s');
yield new Transformation(new Pattern('/al$/'), 'aux');
yield new Transformation(new Pattern('/(bleu|émeu|landau|lieu|pneu|sarrau)$/'), '\1s');
yield new Transformation(new Pattern('/(bijou|caillou|chou|genou|hibou|joujou|pou|au|eu|eau)$/'), '\1x');
yield new Transformation(new Pattern('/(bleu|émeu|landau|pneu|sarrau)$/'), '\1s');
yield new Transformation(new Pattern('/(bijou|caillou|chou|genou|hibou|joujou|lieu|pou|au|eu|eau)$/'), '\1x');
yield new Transformation(new Pattern('/$/'), 's');
}
/**
* @return Substitution[]
*/
public static function getIrregular() : iterable
public static function getIrregular(): iterable
{
yield new Substitution(new Word('monsieur'), new Word('messieurs'));
yield new Substitution(new Word('madame'), new Word('mesdames'));

View file

@ -9,12 +9,12 @@ use Doctrine\Inflector\Rules\Ruleset;
final class InflectorFactory extends GenericLanguageInflectorFactory
{
protected function getSingularRuleset() : Ruleset
protected function getSingularRuleset(): Ruleset
{
return Rules::getSingularRuleset();
}
protected function getPluralRuleset() : Ruleset
protected function getPluralRuleset(): Ruleset
{
return Rules::getPluralRuleset();
}

View file

@ -11,7 +11,7 @@ use Doctrine\Inflector\Rules\Transformations;
final class Rules
{
public static function getSingularRuleset() : Ruleset
public static function getSingularRuleset(): Ruleset
{
return new Ruleset(
new Transformations(...Inflectible::getSingular()),
@ -20,7 +20,7 @@ final class Rules
);
}
public static function getPluralRuleset() : Ruleset
public static function getPluralRuleset(): Ruleset
{
return new Ruleset(
new Transformations(...Inflectible::getPlural()),

View file

@ -11,7 +11,7 @@ final class Uninflected
/**
* @return Pattern[]
*/
public static function getSingular() : iterable
public static function getSingular(): iterable
{
yield from self::getDefault();
}
@ -19,7 +19,7 @@ final class Uninflected
/**
* @return Pattern[]
*/
public static function getPlural() : iterable
public static function getPlural(): iterable
{
yield from self::getDefault();
}
@ -27,7 +27,7 @@ final class Uninflected
/**
* @return Pattern[]
*/
private static function getDefault() : iterable
private static function getDefault(): iterable
{
yield new Pattern('');
}

View file

@ -14,7 +14,7 @@ class Inflectible
/**
* @return Transformation[]
*/
public static function getSingular() : iterable
public static function getSingular(): iterable
{
yield new Transformation(new Pattern('/re$/i'), 'r');
yield new Transformation(new Pattern('/er$/i'), '');
@ -23,7 +23,7 @@ class Inflectible
/**
* @return Transformation[]
*/
public static function getPlural() : iterable
public static function getPlural(): iterable
{
yield new Transformation(new Pattern('/e$/i'), 'er');
yield new Transformation(new Pattern('/r$/i'), 're');
@ -33,7 +33,7 @@ class Inflectible
/**
* @return Substitution[]
*/
public static function getIrregular() : iterable
public static function getIrregular(): iterable
{
yield new Substitution(new Word('konto'), new Word('konti'));
}

View file

@ -9,12 +9,12 @@ use Doctrine\Inflector\Rules\Ruleset;
final class InflectorFactory extends GenericLanguageInflectorFactory
{
protected function getSingularRuleset() : Ruleset
protected function getSingularRuleset(): Ruleset
{
return Rules::getSingularRuleset();
}
protected function getPluralRuleset() : Ruleset
protected function getPluralRuleset(): Ruleset
{
return Rules::getPluralRuleset();
}

View file

@ -11,7 +11,7 @@ use Doctrine\Inflector\Rules\Transformations;
final class Rules
{
public static function getSingularRuleset() : Ruleset
public static function getSingularRuleset(): Ruleset
{
return new Ruleset(
new Transformations(...Inflectible::getSingular()),
@ -20,7 +20,7 @@ final class Rules
);
}
public static function getPluralRuleset() : Ruleset
public static function getPluralRuleset(): Ruleset
{
return new Ruleset(
new Transformations(...Inflectible::getPlural()),

View file

@ -11,7 +11,7 @@ final class Uninflected
/**
* @return Pattern[]
*/
public static function getSingular() : iterable
public static function getSingular(): iterable
{
yield from self::getDefault();
}
@ -19,7 +19,7 @@ final class Uninflected
/**
* @return Pattern[]
*/
public static function getPlural() : iterable
public static function getPlural(): iterable
{
yield from self::getDefault();
}
@ -27,7 +27,7 @@ final class Uninflected
/**
* @return Pattern[]
*/
private static function getDefault() : iterable
private static function getDefault(): iterable
{
yield new Pattern('barn');
yield new Pattern('fjell');

View file

@ -25,17 +25,17 @@ final class Pattern
}
}
public function getPattern() : string
public function getPattern(): string
{
return $this->pattern;
}
public function getRegex() : string
public function getRegex(): string
{
return $this->regex;
}
public function matches(string $word) : bool
public function matches(string $word): bool
{
return preg_match($this->getRegex(), $word) === 1;
}

View file

@ -20,14 +20,14 @@ class Patterns
{
$this->patterns = $patterns;
$patterns = array_map(static function (Pattern $pattern) : string {
$patterns = array_map(static function (Pattern $pattern): string {
return $pattern->getPattern();
}, $this->patterns);
$this->regex = '/^(?:' . implode('|', $patterns) . ')$/i';
}
public function matches(string $word) : bool
public function matches(string $word): bool
{
return preg_match($this->regex, $word, $regs) === 1;
}

View file

@ -14,7 +14,7 @@ class Inflectible
/**
* @return Transformation[]
*/
public static function getSingular() : iterable
public static function getSingular(): iterable
{
yield new Transformation(new Pattern('/^(g|)ases$/i'), '\1ás');
yield new Transformation(new Pattern('/(japon|escoc|ingl|dinamarqu|fregu|portugu)eses$/i'), '\1ês');
@ -37,7 +37,7 @@ class Inflectible
/**
* @return Transformation[]
*/
public static function getPlural() : iterable
public static function getPlural(): iterable
{
yield new Transformation(new Pattern('/^(alem|c|p)ao$/i'), '\1aes');
yield new Transformation(new Pattern('/^(irm|m)ao$/i'), '\1aos');
@ -61,7 +61,7 @@ class Inflectible
/**
* @return Substitution[]
*/
public static function getIrregular() : iterable
public static function getIrregular(): iterable
{
yield new Substitution(new Word('abdomen'), new Word('abdomens'));
yield new Substitution(new Word('alemão'), new Word('alemães'));

View file

@ -9,12 +9,12 @@ use Doctrine\Inflector\Rules\Ruleset;
final class InflectorFactory extends GenericLanguageInflectorFactory
{
protected function getSingularRuleset() : Ruleset
protected function getSingularRuleset(): Ruleset
{
return Rules::getSingularRuleset();
}
protected function getPluralRuleset() : Ruleset
protected function getPluralRuleset(): Ruleset
{
return Rules::getPluralRuleset();
}

View file

@ -11,7 +11,7 @@ use Doctrine\Inflector\Rules\Transformations;
final class Rules
{
public static function getSingularRuleset() : Ruleset
public static function getSingularRuleset(): Ruleset
{
return new Ruleset(
new Transformations(...Inflectible::getSingular()),
@ -20,7 +20,7 @@ final class Rules
);
}
public static function getPluralRuleset() : Ruleset
public static function getPluralRuleset(): Ruleset
{
return new Ruleset(
new Transformations(...Inflectible::getPlural()),

View file

@ -11,7 +11,7 @@ final class Uninflected
/**
* @return Pattern[]
*/
public static function getSingular() : iterable
public static function getSingular(): iterable
{
yield from self::getDefault();
}
@ -19,7 +19,7 @@ final class Uninflected
/**
* @return Pattern[]
*/
public static function getPlural() : iterable
public static function getPlural(): iterable
{
yield from self::getDefault();
}
@ -27,7 +27,7 @@ final class Uninflected
/**
* @return Pattern[]
*/
private static function getDefault() : iterable
private static function getDefault(): iterable
{
yield new Pattern('tórax');
yield new Pattern('tênis');

View file

@ -22,17 +22,17 @@ class Ruleset
$this->irregular = $irregular;
}
public function getRegular() : Transformations
public function getRegular(): Transformations
{
return $this->regular;
}
public function getUninflected() : Patterns
public function getUninflected(): Patterns
{
return $this->uninflected;
}
public function getIrregular() : Substitutions
public function getIrregular(): Substitutions
{
return $this->irregular;
}

View file

@ -14,7 +14,7 @@ class Inflectible
/**
* @return Transformation[]
*/
public static function getSingular() : iterable
public static function getSingular(): iterable
{
yield new Transformation(new Pattern('/ereses$/'), 'erés');
yield new Transformation(new Pattern('/iones$/'), 'ión');
@ -26,7 +26,7 @@ class Inflectible
/**
* @return Transformation[]
*/
public static function getPlural() : iterable
public static function getPlural(): iterable
{
yield new Transformation(new Pattern('/ú([sn])$/i'), 'u\1es');
yield new Transformation(new Pattern('/ó([sn])$/i'), 'o\1es');
@ -42,7 +42,7 @@ class Inflectible
/**
* @return Substitution[]
*/
public static function getIrregular() : iterable
public static function getIrregular(): iterable
{
yield new Substitution(new Word('el'), new Word('los'));
yield new Substitution(new Word('papá'), new Word('papás'));

View file

@ -9,12 +9,12 @@ use Doctrine\Inflector\Rules\Ruleset;
final class InflectorFactory extends GenericLanguageInflectorFactory
{
protected function getSingularRuleset() : Ruleset
protected function getSingularRuleset(): Ruleset
{
return Rules::getSingularRuleset();
}
protected function getPluralRuleset() : Ruleset
protected function getPluralRuleset(): Ruleset
{
return Rules::getPluralRuleset();
}

View file

@ -11,7 +11,7 @@ use Doctrine\Inflector\Rules\Transformations;
final class Rules
{
public static function getSingularRuleset() : Ruleset
public static function getSingularRuleset(): Ruleset
{
return new Ruleset(
new Transformations(...Inflectible::getSingular()),
@ -20,7 +20,7 @@ final class Rules
);
}
public static function getPluralRuleset() : Ruleset
public static function getPluralRuleset(): Ruleset
{
return new Ruleset(
new Transformations(...Inflectible::getPlural()),

View file

@ -11,7 +11,7 @@ final class Uninflected
/**
* @return Pattern[]
*/
public static function getSingular() : iterable
public static function getSingular(): iterable
{
yield from self::getDefault();
}
@ -19,7 +19,7 @@ final class Uninflected
/**
* @return Pattern[]
*/
public static function getPlural() : iterable
public static function getPlural(): iterable
{
yield from self::getDefault();
}
@ -27,7 +27,7 @@ final class Uninflected
/**
* @return Pattern[]
*/
private static function getDefault() : iterable
private static function getDefault(): iterable
{
yield new Pattern('lunes');
yield new Pattern('rompecabezas');

View file

@ -18,12 +18,12 @@ final class Substitution
$this->to = $to;
}
public function getFrom() : Word
public function getFrom(): Word
{
return $this->from;
}
public function getTo() : Word
public function getTo(): Word
{
return $this->to;
}

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Doctrine\Inflector\Rules;
use Doctrine\Inflector\WordInflector;
use function strtolower;
use function strtoupper;
use function substr;
@ -21,7 +22,7 @@ class Substitutions implements WordInflector
}
}
public function getFlippedSubstitutions() : Substitutions
public function getFlippedSubstitutions(): Substitutions
{
$substitutions = [];
@ -35,7 +36,7 @@ class Substitutions implements WordInflector
return new Substitutions(...$substitutions);
}
public function inflect(string $word) : string
public function inflect(string $word): string
{
$lowerWord = strtolower($word);

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Doctrine\Inflector\Rules;
use Doctrine\Inflector\WordInflector;
use function preg_replace;
final class Transformation implements WordInflector
@ -21,17 +22,17 @@ final class Transformation implements WordInflector
$this->replacement = $replacement;
}
public function getPattern() : Pattern
public function getPattern(): Pattern
{
return $this->pattern;
}
public function getReplacement() : string
public function getReplacement(): string
{
return $this->replacement;
}
public function inflect(string $word) : string
public function inflect(string $word): string
{
return (string) preg_replace($this->pattern->getRegex(), $this->replacement, $word);
}

View file

@ -16,7 +16,7 @@ class Transformations implements WordInflector
$this->transformations = $transformations;
}
public function inflect(string $word) : string
public function inflect(string $word): string
{
foreach ($this->transformations as $transformation) {
if ($transformation->getPattern()->matches($word)) {

View file

@ -14,7 +14,7 @@ class Inflectible
/**
* @return Transformation[]
*/
public static function getSingular() : iterable
public static function getSingular(): iterable
{
yield new Transformation(new Pattern('/l[ae]r$/i'), '');
}
@ -22,7 +22,7 @@ class Inflectible
/**
* @return Transformation[]
*/
public static function getPlural() : iterable
public static function getPlural(): iterable
{
yield new Transformation(new Pattern('/([eöiü][^aoıueöiü]{0,6})$/u'), '\1ler');
yield new Transformation(new Pattern('/([aoıu][^aoıueöiü]{0,6})$/u'), '\1lar');
@ -31,7 +31,7 @@ class Inflectible
/**
* @return Substitution[]
*/
public static function getIrregular() : iterable
public static function getIrregular(): iterable
{
yield new Substitution(new Word('ben'), new Word('biz'));
yield new Substitution(new Word('sen'), new Word('siz'));

View file

@ -9,12 +9,12 @@ use Doctrine\Inflector\Rules\Ruleset;
final class InflectorFactory extends GenericLanguageInflectorFactory
{
protected function getSingularRuleset() : Ruleset
protected function getSingularRuleset(): Ruleset
{
return Rules::getSingularRuleset();
}
protected function getPluralRuleset() : Ruleset
protected function getPluralRuleset(): Ruleset
{
return Rules::getPluralRuleset();
}

View file

@ -11,7 +11,7 @@ use Doctrine\Inflector\Rules\Transformations;
final class Rules
{
public static function getSingularRuleset() : Ruleset
public static function getSingularRuleset(): Ruleset
{
return new Ruleset(
new Transformations(...Inflectible::getSingular()),
@ -20,7 +20,7 @@ final class Rules
);
}
public static function getPluralRuleset() : Ruleset
public static function getPluralRuleset(): Ruleset
{
return new Ruleset(
new Transformations(...Inflectible::getPlural()),

View file

@ -11,7 +11,7 @@ final class Uninflected
/**
* @return Pattern[]
*/
public static function getSingular() : iterable
public static function getSingular(): iterable
{
yield from self::getDefault();
}
@ -19,7 +19,7 @@ final class Uninflected
/**
* @return Pattern[]
*/
public static function getPlural() : iterable
public static function getPlural(): iterable
{
yield from self::getDefault();
}
@ -27,7 +27,7 @@ final class Uninflected
/**
* @return Pattern[]
*/
private static function getDefault() : iterable
private static function getDefault(): iterable
{
yield new Pattern('lunes');
yield new Pattern('rompecabezas');

View file

@ -14,7 +14,7 @@ class Word
$this->word = $word;
}
public function getWord() : string
public function getWord(): string
{
return $this->word;
}

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Doctrine\Inflector;
use Doctrine\Inflector\Rules\Ruleset;
use function array_merge;
/**
@ -26,7 +27,7 @@ class RulesetInflector implements WordInflector
$this->rulesets = array_merge([$ruleset], $rulesets);
}
public function inflect(string $word) : string
public function inflect(string $word): string
{
if ($word === '') {
return '';

View file

@ -6,5 +6,5 @@ namespace Doctrine\Inflector;
interface WordInflector
{
public function inflect(string $word) : string;
public function inflect(string $word): string;
}

15
vendor/doctrine/inflector/psalm.xml vendored Normal file
View file

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="7"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="lib/Doctrine/Inflector" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>

View file

@ -121,6 +121,23 @@ class Arr
return $results;
}
/**
* Convert a flatten "dot" notation array into an expanded array.
*
* @param iterable $array
* @return array
*/
public static function undot($array)
{
$results = [];
foreach ($array as $key => $value) {
static::set($results, $key, $value);
}
return $results;
}
/**
* Get all of the given array except for a specified array of keys.
*
@ -297,7 +314,7 @@ class Arr
return $array[$key];
}
if (strpos($key, '.') === false) {
if (! str_contains($key, '.')) {
return $array[$key] ?? value($default);
}
@ -393,6 +410,31 @@ class Arr
return array_keys($keys) !== $keys;
}
/**
* Determines if an array is a list.
*
* An array is a "list" if all array keys are sequential integers starting from 0 with no gaps in between.
*
* @param array $array
* @return bool
*/
public static function isList($array)
{
return ! self::isAssoc($array);
}
/**
* Key an associative array by a field or using a callback.
*
* @param array $array
* @param callable|array|string
* @return array
*/
public static function keyBy($array, $keyBy)
{
return Collection::make($array)->keyBy($keyBy)->all();
}
/**
* Get a subset of the items from the given array.
*
@ -687,6 +729,19 @@ class Arr
return array_filter($array, $callback, ARRAY_FILTER_USE_BOTH);
}
/**
* Filter items where the value is not null.
*
* @param array $array
* @return array
*/
public static function whereNotNull($array)
{
return static::where($array, function ($value) {
return ! is_null($value);
});
}
/**
* If the given value is not an array and not null, wrap it in one.
*

View file

@ -4,25 +4,37 @@ namespace Illuminate\Support;
use ArrayAccess;
use ArrayIterator;
use Illuminate\Contracts\Support\CanBeEscapedWhenCastToString;
use Illuminate\Support\Traits\EnumeratesValues;
use Illuminate\Support\Traits\Macroable;
use stdClass;
use Traversable;
class Collection implements ArrayAccess, Enumerable
/**
* @template TKey of array-key
* @template TValue
*
* @implements \ArrayAccess<TKey, TValue>
* @implements \Illuminate\Support\Enumerable<TKey, TValue>
*/
class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerable
{
/**
* @use \Illuminate\Support\Traits\EnumeratesValues<TKey, TValue>
*/
use EnumeratesValues, Macroable;
/**
* The items contained in the collection.
*
* @var array
* @var array<TKey, TValue>
*/
protected $items = [];
/**
* Create a new collection.
*
* @param mixed $items
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue>|null $items
* @return void
*/
public function __construct($items = [])
@ -35,7 +47,7 @@ class Collection implements ArrayAccess, Enumerable
*
* @param int $from
* @param int $to
* @return static
* @return static<int, int>
*/
public static function range($from, $to)
{
@ -45,7 +57,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get all of the items in the collection.
*
* @return array
* @return array<TKey, TValue>
*/
public function all()
{
@ -55,7 +67,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get a lazy collection for the items in this collection.
*
* @return \Illuminate\Support\LazyCollection
* @return \Illuminate\Support\LazyCollection<TKey, TValue>
*/
public function lazy()
{
@ -65,8 +77,8 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get the average value of a given key.
*
* @param callable|string|null $callback
* @return mixed
* @param (callable(TValue): float|int)|string|null $callback
* @return float|int|null
*/
public function avg($callback = null)
{
@ -86,8 +98,8 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get the median of a given key.
*
* @param string|array|null $key
* @return mixed
* @param string|array<array-key, string>|null $key
* @return float|int|null
*/
public function median($key = null)
{
@ -116,8 +128,8 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get the mode of a given key.
*
* @param string|array|null $key
* @return array|null
* @param string|array<array-key, string>|null $key
* @return array<int, float|int>|null
*/
public function mode($key = null)
{
@ -145,7 +157,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Collapse the collection of items into a single array.
*
* @return static
* @return static<int, mixed>
*/
public function collapse()
{
@ -155,7 +167,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Determine if an item exists in the collection.
*
* @param mixed $key
* @param (callable(TValue, TKey): bool)|TValue|string $key
* @param mixed $operator
* @param mixed $value
* @return bool
@ -175,11 +187,27 @@ class Collection implements ArrayAccess, Enumerable
return $this->contains($this->operatorForWhere(...func_get_args()));
}
/**
* Determine if an item is not contained in the collection.
*
* @param mixed $key
* @param mixed $operator
* @param mixed $value
* @return bool
*/
public function doesntContain($key, $operator = null, $value = null)
{
return ! $this->contains(...func_get_args());
}
/**
* Cross join with the given lists, returning all possible permutations.
*
* @param mixed ...$lists
* @return static
* @template TCrossJoinKey
* @template TCrossJoinValue
*
* @param \Illuminate\Contracts\Support\Arrayable<TCrossJoinKey, TCrossJoinValue>|iterable<TCrossJoinKey, TCrossJoinValue> ...$lists
* @return static<int, array<int, TValue|TCrossJoinValue>>
*/
public function crossJoin(...$lists)
{
@ -191,7 +219,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get the items in the collection that are not present in the given items.
*
* @param mixed $items
* @param \Illuminate\Contracts\Support\Arrayable<array-key, TValue>|iterable<array-key, TValue> $items
* @return static
*/
public function diff($items)
@ -202,8 +230,8 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get the items in the collection that are not present in the given items, using the callback.
*
* @param mixed $items
* @param callable $callback
* @param \Illuminate\Contracts\Support\Arrayable<array-key, TValue>|iterable<array-key, TValue> $items
* @param callable(TValue, TValue): int $callback
* @return static
*/
public function diffUsing($items, callable $callback)
@ -214,7 +242,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get the items in the collection whose keys and values are not present in the given items.
*
* @param mixed $items
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @return static
*/
public function diffAssoc($items)
@ -225,8 +253,8 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get the items in the collection whose keys and values are not present in the given items, using the callback.
*
* @param mixed $items
* @param callable $callback
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @param callable(TKey, TKey): int $callback
* @return static
*/
public function diffAssocUsing($items, callable $callback)
@ -237,7 +265,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get the items in the collection whose keys are not present in the given items.
*
* @param mixed $items
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @return static
*/
public function diffKeys($items)
@ -248,8 +276,8 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get the items in the collection whose keys are not present in the given items, using the callback.
*
* @param mixed $items
* @param callable $callback
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @param callable(TKey, TKey): int $callback
* @return static
*/
public function diffKeysUsing($items, callable $callback)
@ -260,7 +288,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Retrieve duplicate items from the collection.
*
* @param callable|string|null $callback
* @param (callable(TValue): bool)|string|null $callback
* @param bool $strict
* @return static
*/
@ -288,7 +316,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Retrieve duplicate items from the collection using strict comparison.
*
* @param callable|string|null $callback
* @param (callable(TValue): bool)|string|null $callback
* @return static
*/
public function duplicatesStrict($callback = null)
@ -300,7 +328,7 @@ class Collection implements ArrayAccess, Enumerable
* Get the comparison function to detect duplicates.
*
* @param bool $strict
* @return \Closure
* @return callable(TValue, TValue): bool
*/
protected function duplicateComparator($strict)
{
@ -318,7 +346,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get all items except for those with the specified keys.
*
* @param \Illuminate\Support\Collection|mixed $keys
* @param \Illuminate\Support\Enumerable<array-key, TKey>|array<array-key, TKey> $keys
* @return static
*/
public function except($keys)
@ -335,7 +363,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Run a filter over each of the items.
*
* @param callable|null $callback
* @param (callable(TValue, TKey): bool)|null $callback
* @return static
*/
public function filter(callable $callback = null)
@ -350,9 +378,11 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get the first item from the collection passing the given truth test.
*
* @param callable|null $callback
* @param mixed $default
* @return mixed
* @template TFirstDefault
*
* @param (callable(TValue, TKey): bool)|null $callback
* @param TFirstDefault|(\Closure(): TFirstDefault) $default
* @return TValue|TFirstDefault
*/
public function first(callable $callback = null, $default = null)
{
@ -363,7 +393,7 @@ class Collection implements ArrayAccess, Enumerable
* Get a flattened array of the items in the collection.
*
* @param int $depth
* @return static
* @return static<int, mixed>
*/
public function flatten($depth = INF)
{
@ -373,7 +403,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Flip the items in the collection.
*
* @return static
* @return static<TValue, TKey>
*/
public function flip()
{
@ -383,7 +413,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Remove an item from the collection by key.
*
* @param string|array $keys
* @param TKey|array<array-key, TKey> $keys
* @return $this
*/
public function forget($keys)
@ -398,9 +428,11 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get an item from the collection by key.
*
* @param mixed $key
* @param mixed $default
* @return mixed
* @template TGetDefault
*
* @param TKey $key
* @param TGetDefault|(\Closure(): TGetDefault) $default
* @return TValue|TGetDefault
*/
public function get($key, $default = null)
{
@ -411,12 +443,30 @@ class Collection implements ArrayAccess, Enumerable
return value($default);
}
/**
* Get an item from the collection by key or add it to collection if it does not exist.
*
* @param mixed $key
* @param mixed $value
* @return mixed
*/
public function getOrPut($key, $value)
{
if (array_key_exists($key, $this->items)) {
return $this->items[$key];
}
$this->offsetSet($key, $value = value($value));
return $value;
}
/**
* Group an associative array by a field or using a callback.
*
* @param array|callable|string $groupBy
* @param (callable(TValue, TKey): array-key)|array|string $groupBy
* @param bool $preserveKeys
* @return static
* @return static<array-key, static<array-key, TValue>>
*/
public function groupBy($groupBy, $preserveKeys = false)
{
@ -460,8 +510,8 @@ class Collection implements ArrayAccess, Enumerable
/**
* Key an associative array by a field or using a callback.
*
* @param callable|string $keyBy
* @return static
* @param (callable(TValue, TKey): array-key)|array|string $keyBy
* @return static<array-key, TValue>
*/
public function keyBy($keyBy)
{
@ -485,7 +535,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Determine if an item exists in the collection by key.
*
* @param mixed $key
* @param TKey|array<array-key, TKey> $key
* @return bool
*/
public function has($key)
@ -501,6 +551,29 @@ class Collection implements ArrayAccess, Enumerable
return true;
}
/**
* Determine if any of the keys exist in the collection.
*
* @param mixed $key
* @return bool
*/
public function hasAny($key)
{
if ($this->isEmpty()) {
return false;
}
$keys = is_array($key) ? $key : func_get_args();
foreach ($keys as $value) {
if ($this->has($value)) {
return true;
}
}
return false;
}
/**
* Concatenate values of a given key as a string.
*
@ -522,7 +595,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Intersect the collection with the given items.
*
* @param mixed $items
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @return static
*/
public function intersect($items)
@ -533,7 +606,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Intersect the collection with the given items by key.
*
* @param mixed $items
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @return static
*/
public function intersectByKeys($items)
@ -596,7 +669,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get the keys of the collection items.
*
* @return static
* @return static<int, TKey>
*/
public function keys()
{
@ -606,9 +679,11 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get the last item from the collection.
*
* @param callable|null $callback
* @param mixed $default
* @return mixed
* @template TLastDefault
*
* @param (callable(TValue, TKey): bool)|null $callback
* @param TLastDefault|(\Closure(): TLastDefault) $default
* @return TValue|TLastDefault
*/
public function last(callable $callback = null, $default = null)
{
@ -618,9 +693,9 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get the values of a given key.
*
* @param string|array|int|null $value
* @param string|array<array-key, string> $value
* @param string|null $key
* @return static
* @return static<int, mixed>
*/
public function pluck($value, $key = null)
{
@ -630,8 +705,10 @@ class Collection implements ArrayAccess, Enumerable
/**
* Run a map over each of the items.
*
* @param callable $callback
* @return static
* @template TMapValue
*
* @param callable(TValue, TKey): TMapValue $callback
* @return static<TKey, TMapValue>
*/
public function map(callable $callback)
{
@ -647,8 +724,11 @@ class Collection implements ArrayAccess, Enumerable
*
* The callback should return an associative array with a single key/value pair.
*
* @param callable $callback
* @return static
* @template TMapToDictionaryKey of array-key
* @template TMapToDictionaryValue
*
* @param callable(TValue, TKey): array<TMapToDictionaryKey, TMapToDictionaryValue> $callback
* @return static<TMapToDictionaryKey, array<int, TMapToDictionaryValue>>
*/
public function mapToDictionary(callable $callback)
{
@ -676,8 +756,11 @@ class Collection implements ArrayAccess, Enumerable
*
* The callback should return an associative array with a single key/value pair.
*
* @param callable $callback
* @return static
* @template TMapWithKeysKey of array-key
* @template TMapWithKeysValue
*
* @param callable(TValue, TKey): array<TMapWithKeysKey, TMapWithKeysValue> $callback
* @return static<TMapWithKeysKey, TMapWithKeysValue>
*/
public function mapWithKeys(callable $callback)
{
@ -697,7 +780,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Merge the collection with the given items.
*
* @param mixed $items
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @return static
*/
public function merge($items)
@ -708,8 +791,10 @@ class Collection implements ArrayAccess, Enumerable
/**
* Recursively merge the collection with the given items.
*
* @param mixed $items
* @return static
* @template TMergeRecursiveValue
*
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TMergeRecursiveValue>|iterable<TKey, TMergeRecursiveValue> $items
* @return static<TKey, TValue|TMergeRecursiveValue>
*/
public function mergeRecursive($items)
{
@ -719,8 +804,10 @@ class Collection implements ArrayAccess, Enumerable
/**
* Create a collection by using this collection for keys and another for its values.
*
* @param mixed $values
* @return static
* @template TCombineValue
*
* @param \Illuminate\Contracts\Support\Arrayable<array-key, TCombineValue>|iterable<array-key, TCombineValue> $values
* @return static<TKey, TCombineValue>
*/
public function combine($values)
{
@ -730,7 +817,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Union the collection with the given items.
*
* @param mixed $items
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @return static
*/
public function union($items)
@ -765,7 +852,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get the items with the specified keys.
*
* @param mixed $keys
* @param \Illuminate\Support\Enumerable<array-key, TKey>|array<array-key, TKey> $keys
* @return static
*/
public function only($keys)
@ -787,7 +874,7 @@ class Collection implements ArrayAccess, Enumerable
* Get and remove the last N items from the collection.
*
* @param int $count
* @return mixed
* @return static<int, TValue>|TValue|null
*/
public function pop($count = 1)
{
@ -813,8 +900,8 @@ class Collection implements ArrayAccess, Enumerable
/**
* Push an item onto the beginning of the collection.
*
* @param mixed $value
* @param mixed $key
* @param TValue $value
* @param TKey $key
* @return $this
*/
public function prepend($value, $key = null)
@ -827,7 +914,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Push one or more items onto the end of the collection.
*
* @param mixed $values [optional]
* @param TValue ...$values
* @return $this
*/
public function push(...$values)
@ -842,7 +929,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Push all of the given items onto the collection.
*
* @param iterable $source
* @param iterable<array-key, TValue> $source
* @return static
*/
public function concat($source)
@ -859,9 +946,11 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get and remove an item from the collection.
*
* @param mixed $key
* @param mixed $default
* @return mixed
* @template TPullDefault
*
* @param TKey $key
* @param TPullDefault|(\Closure(): TPullDefault) $default
* @return TValue|TPullDefault
*/
public function pull($key, $default = null)
{
@ -871,8 +960,8 @@ class Collection implements ArrayAccess, Enumerable
/**
* Put an item in the collection by key.
*
* @param mixed $key
* @param mixed $value
* @param TKey $key
* @param TValue $value
* @return $this
*/
public function put($key, $value)
@ -886,7 +975,7 @@ class Collection implements ArrayAccess, Enumerable
* Get one or a specified number of items randomly from the collection.
*
* @param int|null $number
* @return static|mixed
* @return static<int, TValue>|TValue
*
* @throws \InvalidArgumentException
*/
@ -902,7 +991,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Replace the collection items with the given items.
*
* @param mixed $items
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @return static
*/
public function replace($items)
@ -913,7 +1002,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Recursively replace the collection items with the given items.
*
* @param mixed $items
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @return static
*/
public function replaceRecursive($items)
@ -934,9 +1023,9 @@ class Collection implements ArrayAccess, Enumerable
/**
* Search the collection for a given value and return the corresponding key if successful.
*
* @param mixed $value
* @param TValue|(callable(TValue,TKey): bool) $value
* @param bool $strict
* @return mixed
* @return TKey|bool
*/
public function search($value, $strict = false)
{
@ -957,7 +1046,7 @@ class Collection implements ArrayAccess, Enumerable
* Get and remove the first N items from the collection.
*
* @param int $count
* @return mixed
* @return static<int, TValue>|TValue|null
*/
public function shift($count = 1)
{
@ -996,7 +1085,7 @@ class Collection implements ArrayAccess, Enumerable
*
* @param int $size
* @param int $step
* @return static
* @return static<int, static>
*/
public function sliding($size = 2, $step = 1)
{
@ -1021,7 +1110,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Skip items in the collection until the given condition is met.
*
* @param mixed $value
* @param TValue|callable(TValue,TKey): bool $value
* @return static
*/
public function skipUntil($value)
@ -1032,7 +1121,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Skip items in the collection while the given condition is met.
*
* @param mixed $value
* @param TValue|callable(TValue,TKey): bool $value
* @return static
*/
public function skipWhile($value)
@ -1056,7 +1145,7 @@ class Collection implements ArrayAccess, Enumerable
* Split a collection into a certain number of groups.
*
* @param int $numberOfGroups
* @return static
* @return static<int, static>
*/
public function split($numberOfGroups)
{
@ -1093,7 +1182,7 @@ class Collection implements ArrayAccess, Enumerable
* Split a collection into a certain number of groups, and fill the first groups completely.
*
* @param int $numberOfGroups
* @return static
* @return static<int, static>
*/
public function splitIn($numberOfGroups)
{
@ -1103,10 +1192,10 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get the first item in the collection, but only if exactly one item exists. Otherwise, throw an exception.
*
* @param mixed $key
* @param (callable(TValue, TKey): bool)|string $key
* @param mixed $operator
* @param mixed $value
* @return mixed
* @return TValue
*
* @throws \Illuminate\Support\ItemNotFoundException
* @throws \Illuminate\Support\MultipleItemsFoundException
@ -1117,14 +1206,16 @@ class Collection implements ArrayAccess, Enumerable
? $this->operatorForWhere(...func_get_args())
: $key;
$items = $this->when($filter)->filter($filter);
$items = $this->unless($filter == null)->filter($filter);
if ($items->isEmpty()) {
$count = $items->count();
if ($count === 0) {
throw new ItemNotFoundException;
}
if ($items->count() > 1) {
throw new MultipleItemsFoundException;
if ($count > 1) {
throw new MultipleItemsFoundException($count);
}
return $items->first();
@ -1133,10 +1224,10 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get the first item in the collection but throw an exception if no matching items exist.
*
* @param mixed $key
* @param (callable(TValue, TKey): bool)|string $key
* @param mixed $operator
* @param mixed $value
* @return mixed
* @return TValue
*
* @throws \Illuminate\Support\ItemNotFoundException
*/
@ -1161,7 +1252,7 @@ class Collection implements ArrayAccess, Enumerable
* Chunk the collection into chunks of the given size.
*
* @param int $size
* @return static
* @return static<int, static>
*/
public function chunk($size)
{
@ -1181,8 +1272,8 @@ class Collection implements ArrayAccess, Enumerable
/**
* Chunk the collection into chunks with a callback.
*
* @param callable $callback
* @return static
* @param callable(TValue, TKey, static<int, TValue>): bool $callback
* @return static<int, static<int, TValue>>
*/
public function chunkWhile(callable $callback)
{
@ -1194,7 +1285,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Sort through each item with a callback.
*
* @param callable|int|null $callback
* @param (callable(TValue, TValue): int)|null|int $callback
* @return static
*/
public function sort($callback = null)
@ -1226,7 +1317,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Sort the collection using the given callback.
*
* @param callable|array|string $callback
* @param array<array-key, (callable(TValue, TKey): mixed)|array<array-key, string>|(callable(TValue, TKey): mixed)|string $callback
* @param int $options
* @param bool $descending
* @return static
@ -1243,7 +1334,7 @@ class Collection implements ArrayAccess, Enumerable
// First we will loop through the items and get the comparator from a callback
// function which we were given. Then, we will sort the returned values and
// and grab the corresponding values for the sorted keys from this array.
// grab all the corresponding values for the sorted keys from this array.
foreach ($this->items as $key => $value) {
$results[$key] = $callback($value, $key);
}
@ -1264,7 +1355,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Sort the collection using multiple comparisons.
*
* @param array $comparisons
* @param array<array-key, (callable(TValue, TKey): mixed)|array<array-key, string> $comparisons
* @return static
*/
protected function sortByMany(array $comparisons = [])
@ -1280,9 +1371,7 @@ class Collection implements ArrayAccess, Enumerable
$ascending = Arr::get($comparison, 1, true) === true ||
Arr::get($comparison, 1, true) === 'asc';
$result = 0;
if (is_callable($prop)) {
if (! is_string($prop) && is_callable($prop)) {
$result = $prop($a, $b);
} else {
$values = [data_get($a, $prop), data_get($b, $prop)];
@ -1308,7 +1397,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Sort the collection in descending order using the given callback.
*
* @param callable|string $callback
* @param array<array-key, (callable(TValue, TKey): mixed)|array<array-key, string>|(callable(TValue, TKey): mixed)|string $callback
* @param int $options
* @return static
*/
@ -1344,12 +1433,27 @@ class Collection implements ArrayAccess, Enumerable
return $this->sortKeys($options, true);
}
/**
* Sort the collection keys using a callback.
*
* @param callable(TKey, TKey): int $callback
* @return static
*/
public function sortKeysUsing(callable $callback)
{
$items = $this->items;
uksort($items, $callback);
return new static($items);
}
/**
* Splice a portion of the underlying collection array.
*
* @param int $offset
* @param int|null $length
* @param mixed $replacement
* @param array<array-key, TValue> $replacement
* @return static
*/
public function splice($offset, $length = null, $replacement = [])
@ -1358,7 +1462,7 @@ class Collection implements ArrayAccess, Enumerable
return new static(array_splice($this->items, $offset));
}
return new static(array_splice($this->items, $offset, $length, $replacement));
return new static(array_splice($this->items, $offset, $length, $this->getArrayableItems($replacement)));
}
/**
@ -1379,7 +1483,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Take items in the collection until the given condition is met.
*
* @param mixed $value
* @param TValue|callable(TValue,TKey): bool $value
* @return static
*/
public function takeUntil($value)
@ -1390,7 +1494,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Take items in the collection while the given condition is met.
*
* @param mixed $value
* @param TValue|callable(TValue,TKey): bool $value
* @return static
*/
public function takeWhile($value)
@ -1401,7 +1505,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Transform each item in the collection using a callback.
*
* @param callable $callback
* @param callable(TValue, TKey): TValue $callback
* @return $this
*/
public function transform(callable $callback)
@ -1412,10 +1516,46 @@ class Collection implements ArrayAccess, Enumerable
}
/**
* Reset the keys on the underlying array.
* Convert a flatten "dot" notation array into an expanded array.
*
* @return static
*/
public function undot()
{
return new static(Arr::undot($this->all()));
}
/**
* Return only unique items from the collection array.
*
* @param (callable(TValue, TKey): mixed)|string|null $key
* @param bool $strict
* @return static
*/
public function unique($key = null, $strict = false)
{
if (is_null($key) && $strict === false) {
return new static(array_unique($this->items, SORT_REGULAR));
}
$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;
});
}
/**
* Reset the keys on the underlying array.
*
* @return static<int, TValue>
*/
public function values()
{
return new static(array_values($this->items));
@ -1427,8 +1567,10 @@ class Collection implements ArrayAccess, Enumerable
* e.g. new Collection([1, 2, 3])->zip([4, 5, 6]);
* => [[1, 4], [2, 5], [3, 6]]
*
* @param mixed ...$items
* @return static
* @template TZipValue
*
* @param \Illuminate\Contracts\Support\Arrayable<array-key, TZipValue>|iterable<array-key, TZipValue> ...$items
* @return static<int, static<int, TValue|TZipValue>>
*/
public function zip($items)
{
@ -1446,9 +1588,11 @@ class Collection implements ArrayAccess, Enumerable
/**
* Pad collection to the specified length with a value.
*
* @template TPadValue
*
* @param int $size
* @param mixed $value
* @return static
* @param TPadValue $value
* @return static<int, TValue|TPadValue>
*/
public function pad($size, $value)
{
@ -1458,10 +1602,9 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get an iterator for the items.
*
* @return \ArrayIterator
* @return \ArrayIterator<TKey, TValue>
*/
#[\ReturnTypeWillChange]
public function getIterator()
public function getIterator(): Traversable
{
return new ArrayIterator($this->items);
}
@ -1471,8 +1614,7 @@ class Collection implements ArrayAccess, Enumerable
*
* @return int
*/
#[\ReturnTypeWillChange]
public function count()
public function count(): int
{
return count($this->items);
}
@ -1480,8 +1622,8 @@ class Collection implements ArrayAccess, Enumerable
/**
* Count the number of items in the collection by a field or using a callback.
*
* @param callable|string $countBy
* @return static
* @param (callable(TValue, TKey): mixed)|string|null $countBy
* @return static<array-key, int>
*/
public function countBy($countBy = null)
{
@ -1491,7 +1633,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Add an item to the collection.
*
* @param mixed $item
* @param TValue $item
* @return $this
*/
public function add($item)
@ -1504,7 +1646,7 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get a base Support collection instance from this collection.
*
* @return \Illuminate\Support\Collection
* @return \Illuminate\Support\Collection<TKey, TValue>
*/
public function toBase()
{
@ -1514,11 +1656,10 @@ class Collection implements ArrayAccess, Enumerable
/**
* Determine if an item exists at an offset.
*
* @param mixed $key
* @param TKey $key
* @return bool
*/
#[\ReturnTypeWillChange]
public function offsetExists($key)
public function offsetExists($key): bool
{
return isset($this->items[$key]);
}
@ -1526,11 +1667,10 @@ class Collection implements ArrayAccess, Enumerable
/**
* Get an item at a given offset.
*
* @param mixed $key
* @return mixed
* @param TKey $key
* @return TValue
*/
#[\ReturnTypeWillChange]
public function offsetGet($key)
public function offsetGet($key): mixed
{
return $this->items[$key];
}
@ -1538,12 +1678,11 @@ class Collection implements ArrayAccess, Enumerable
/**
* Set the item at a given offset.
*
* @param mixed $key
* @param mixed $value
* @param TKey|null $key
* @param TValue $value
* @return void
*/
#[\ReturnTypeWillChange]
public function offsetSet($key, $value)
public function offsetSet($key, $value): void
{
if (is_null($key)) {
$this->items[] = $value;
@ -1555,11 +1694,10 @@ class Collection implements ArrayAccess, Enumerable
/**
* Unset the item at a given offset.
*
* @param string $key
* @param TKey $key
* @return void
*/
#[\ReturnTypeWillChange]
public function offsetUnset($key)
public function offsetUnset($key): void
{
unset($this->items[$key]);
}

File diff suppressed because it is too large Load diff

View file

@ -5,26 +5,39 @@ namespace Illuminate\Support;
use ArrayIterator;
use Closure;
use DateTimeInterface;
use Generator;
use Illuminate\Contracts\Support\CanBeEscapedWhenCastToString;
use Illuminate\Support\Traits\EnumeratesValues;
use Illuminate\Support\Traits\Macroable;
use InvalidArgumentException;
use IteratorAggregate;
use stdClass;
use Traversable;
class LazyCollection implements Enumerable
/**
* @template TKey of array-key
* @template TValue
*
* @implements \Illuminate\Support\Enumerable<TKey, TValue>
*/
class LazyCollection implements CanBeEscapedWhenCastToString, Enumerable
{
/**
* @use \Illuminate\Support\Traits\EnumeratesValues<TKey, TValue>
*/
use EnumeratesValues, Macroable;
/**
* The source from which to generate items.
*
* @var callable|static
* @var (Closure(): \Generator<TKey, TValue, mixed, void>)|static|array<TKey, TValue>
*/
public $source;
/**
* Create a new lazy collection instance.
*
* @param mixed $source
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue>|(Closure(): \Generator<TKey, TValue, mixed, void>)|self<TKey, TValue>|array<TKey, TValue>|null $source
* @return void
*/
public function __construct($source = null)
@ -33,17 +46,35 @@ class LazyCollection implements Enumerable
$this->source = $source;
} elseif (is_null($source)) {
$this->source = static::empty();
} elseif ($source instanceof Generator) {
throw new InvalidArgumentException(
'Generators should not be passed directly to LazyCollection. Instead, pass a generator function.'
);
} else {
$this->source = $this->getArrayableItems($source);
}
}
/**
* Create a new collection instance if the value isn't one already.
*
* @template TMakeKey of array-key
* @template TMakeValue
*
* @param \Illuminate\Contracts\Support\Arrayable<TMakeKey, TMakeValue>|iterable<TMakeKey, TMakeValue>|(Closure(): \Generator<TMakeKey, TMakeValue, mixed, void>)|self<TMakeKey, TMakeValue>|array<TMakeKey, TMakeValue>|null $items
* @return static<TMakeKey, TMakeValue>
*/
public static function make($items = [])
{
return new static($items);
}
/**
* Create a collection with the given range.
*
* @param int $from
* @param int $to
* @return static
* @return static<int, int>
*/
public static function range($from, $to)
{
@ -63,7 +94,7 @@ class LazyCollection implements Enumerable
/**
* Get all items in the enumerable.
*
* @return array
* @return array<TKey, TValue>
*/
public function all()
{
@ -125,8 +156,8 @@ class LazyCollection implements Enumerable
/**
* Get the average value of a given key.
*
* @param callable|string|null $callback
* @return mixed
* @param (callable(TValue): float|int)|string|null $callback
* @return float|int|null
*/
public function avg($callback = null)
{
@ -136,8 +167,8 @@ class LazyCollection implements Enumerable
/**
* Get the median of a given key.
*
* @param string|array|null $key
* @return mixed
* @param string|array<array-key, string>|null $key
* @return float|int|null
*/
public function median($key = null)
{
@ -147,8 +178,8 @@ class LazyCollection implements Enumerable
/**
* Get the mode of a given key.
*
* @param string|array|null $key
* @return array|null
* @param string|array<string>|null $key
* @return array<int, float|int>|null
*/
public function mode($key = null)
{
@ -158,7 +189,7 @@ class LazyCollection implements Enumerable
/**
* Collapse the collection of items into a single array.
*
* @return static
* @return static<int, mixed>
*/
public function collapse()
{
@ -176,7 +207,7 @@ class LazyCollection implements Enumerable
/**
* Determine if an item exists in the enumerable.
*
* @param mixed $key
* @param (callable(TValue, TKey): bool)|TValue|string $key
* @param mixed $operator
* @param mixed $value
* @return bool
@ -186,6 +217,7 @@ class LazyCollection implements Enumerable
if (func_num_args() === 1 && $this->useAsCallable($key)) {
$placeholder = new stdClass;
/** @var callable $key */
return $this->first($key, $placeholder) !== $placeholder;
}
@ -204,11 +236,27 @@ class LazyCollection implements Enumerable
return $this->contains($this->operatorForWhere(...func_get_args()));
}
/**
* Determine if an item is not contained in the enumerable.
*
* @param mixed $key
* @param mixed $operator
* @param mixed $value
* @return bool
*/
public function doesntContain($key, $operator = null, $value = null)
{
return ! $this->contains(...func_get_args());
}
/**
* Cross join the given iterables, returning all possible permutations.
*
* @param array ...$arrays
* @return static
* @template TCrossJoinKey
* @template TCrossJoinValue
*
* @param \Illuminate\Contracts\Support\Arrayable<TCrossJoinKey, TCrossJoinValue>|iterable<TCrossJoinKey, TCrossJoinValue> ...$arrays
* @return static<int, array<int, TValue|TCrossJoinValue>>
*/
public function crossJoin(...$arrays)
{
@ -218,8 +266,8 @@ class LazyCollection implements Enumerable
/**
* Count the number of items in the collection by a field or using a callback.
*
* @param callable|string $countBy
* @return static
* @param (callable(TValue, TKey): mixed)|string|null $countBy
* @return static<array-key, int>
*/
public function countBy($countBy = null)
{
@ -247,7 +295,7 @@ class LazyCollection implements Enumerable
/**
* Get the items that are not present in the given items.
*
* @param mixed $items
* @param \Illuminate\Contracts\Support\Arrayable<array-key, TValue>|iterable<array-key, TValue> $items
* @return static
*/
public function diff($items)
@ -258,8 +306,8 @@ class LazyCollection implements Enumerable
/**
* Get the items that are not present in the given items, using the callback.
*
* @param mixed $items
* @param callable $callback
* @param \Illuminate\Contracts\Support\Arrayable<array-key, TValue>|iterable<array-key, TValue> $items
* @param callable(TValue, TValue): int $callback
* @return static
*/
public function diffUsing($items, callable $callback)
@ -270,7 +318,7 @@ class LazyCollection implements Enumerable
/**
* Get the items whose keys and values are not present in the given items.
*
* @param mixed $items
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @return static
*/
public function diffAssoc($items)
@ -281,8 +329,8 @@ class LazyCollection implements Enumerable
/**
* Get the items whose keys and values are not present in the given items, using the callback.
*
* @param mixed $items
* @param callable $callback
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @param callable(TKey, TKey): int $callback
* @return static
*/
public function diffAssocUsing($items, callable $callback)
@ -293,7 +341,7 @@ class LazyCollection implements Enumerable
/**
* Get the items whose keys are not present in the given items.
*
* @param mixed $items
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @return static
*/
public function diffKeys($items)
@ -304,8 +352,8 @@ class LazyCollection implements Enumerable
/**
* Get the items whose keys are not present in the given items, using the callback.
*
* @param mixed $items
* @param callable $callback
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @param callable(TKey, TKey): int $callback
* @return static
*/
public function diffKeysUsing($items, callable $callback)
@ -316,7 +364,7 @@ class LazyCollection implements Enumerable
/**
* Retrieve duplicate items.
*
* @param callable|string|null $callback
* @param (callable(TValue): bool)|string|null $callback
* @param bool $strict
* @return static
*/
@ -328,7 +376,7 @@ class LazyCollection implements Enumerable
/**
* Retrieve duplicate items using strict comparison.
*
* @param callable|string|null $callback
* @param (callable(TValue): bool)|string|null $callback
* @return static
*/
public function duplicatesStrict($callback = null)
@ -339,7 +387,7 @@ class LazyCollection implements Enumerable
/**
* Get all items except for those with the specified keys.
*
* @param mixed $keys
* @param \Illuminate\Support\Enumerable<array-key, TKey>|array<array-key, TKey> $keys
* @return static
*/
public function except($keys)
@ -350,7 +398,7 @@ class LazyCollection implements Enumerable
/**
* Run a filter over each of the items.
*
* @param callable|null $callback
* @param (callable(TValue): bool)|null $callback
* @return static
*/
public function filter(callable $callback = null)
@ -373,9 +421,11 @@ class LazyCollection implements Enumerable
/**
* Get the first item from the enumerable passing the given truth test.
*
* @param callable|null $callback
* @param mixed $default
* @return mixed
* @template TFirstDefault
*
* @param (callable(TValue): bool)|null $callback
* @param TFirstDefault|(\Closure(): TFirstDefault) $default
* @return TValue|TFirstDefault
*/
public function first(callable $callback = null, $default = null)
{
@ -402,7 +452,7 @@ class LazyCollection implements Enumerable
* Get a flattened list of the items in the collection.
*
* @param int $depth
* @return static
* @return static<int, mixed>
*/
public function flatten($depth = INF)
{
@ -424,7 +474,7 @@ class LazyCollection implements Enumerable
/**
* Flip the items in the collection.
*
* @return static
* @return static<TValue, TKey>
*/
public function flip()
{
@ -438,9 +488,11 @@ class LazyCollection implements Enumerable
/**
* Get an item by key.
*
* @param mixed $key
* @param mixed $default
* @return mixed
* @template TGetDefault
*
* @param TKey|null $key
* @param TGetDefault|(\Closure(): TGetDefault) $default
* @return TValue|TGetDefault
*/
public function get($key, $default = null)
{
@ -460,9 +512,9 @@ class LazyCollection implements Enumerable
/**
* Group an associative array by a field or using a callback.
*
* @param array|callable|string $groupBy
* @param (callable(TValue, TKey): array-key)|array|string $groupBy
* @param bool $preserveKeys
* @return static
* @return static<array-key, static<array-key, TValue>>
*/
public function groupBy($groupBy, $preserveKeys = false)
{
@ -472,8 +524,8 @@ class LazyCollection implements Enumerable
/**
* Key an associative array by a field or using a callback.
*
* @param callable|string $keyBy
* @return static
* @param (callable(TValue, TKey): array-key)|array|string $keyBy
* @return static<array-key, TValue>
*/
public function keyBy($keyBy)
{
@ -512,6 +564,25 @@ class LazyCollection implements Enumerable
return false;
}
/**
* Determine if any of the keys exist in the collection.
*
* @param mixed $key
* @return bool
*/
public function hasAny($key)
{
$keys = array_flip(is_array($key) ? $key : func_get_args());
foreach ($this as $key => $value) {
if (array_key_exists($key, $keys)) {
return true;
}
}
return false;
}
/**
* Concatenate values of a given key as a string.
*
@ -527,7 +598,7 @@ class LazyCollection implements Enumerable
/**
* Intersect the collection with the given items.
*
* @param mixed $items
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @return static
*/
public function intersect($items)
@ -538,7 +609,7 @@ class LazyCollection implements Enumerable
/**
* Intersect the collection with the given items by key.
*
* @param mixed $items
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @return static
*/
public function intersectByKeys($items)
@ -581,7 +652,7 @@ class LazyCollection implements Enumerable
/**
* Get the keys of the collection items.
*
* @return static
* @return static<int, TKey>
*/
public function keys()
{
@ -595,9 +666,11 @@ class LazyCollection implements Enumerable
/**
* Get the last item from the collection.
*
* @param callable|null $callback
* @param mixed $default
* @return mixed
* @template TLastDefault
*
* @param (callable(TValue, TKey): bool)|null $callback
* @param TLastDefault|(\Closure(): TLastDefault) $default
* @return TValue|TLastDefault
*/
public function last(callable $callback = null, $default = null)
{
@ -615,9 +688,9 @@ class LazyCollection implements Enumerable
/**
* Get the values of a given key.
*
* @param string|array $value
* @param string|array<array-key, string> $value
* @param string|null $key
* @return static
* @return static<int, mixed>
*/
public function pluck($value, $key = null)
{
@ -645,8 +718,10 @@ class LazyCollection implements Enumerable
/**
* Run a map over each of the items.
*
* @param callable $callback
* @return static
* @template TMapValue
*
* @param callable(TValue, TKey): TMapValue $callback
* @return static<TKey, TMapValue>
*/
public function map(callable $callback)
{
@ -662,8 +737,11 @@ class LazyCollection implements Enumerable
*
* The callback should return an associative array with a single key/value pair.
*
* @param callable $callback
* @return static
* @template TMapToDictionaryKey of array-key
* @template TMapToDictionaryValue
*
* @param callable(TValue, TKey): array<TMapToDictionaryKey, TMapToDictionaryValue> $callback
* @return static<TMapToDictionaryKey, array<int, TMapToDictionaryValue>>
*/
public function mapToDictionary(callable $callback)
{
@ -675,8 +753,11 @@ class LazyCollection implements Enumerable
*
* The callback should return an associative array with a single key/value pair.
*
* @param callable $callback
* @return static
* @template TMapWithKeysKey of array-key
* @template TMapWithKeysValue
*
* @param callable(TValue, TKey): array<TMapWithKeysKey, TMapWithKeysValue> $callback
* @return static<TMapWithKeysKey, TMapWithKeysValue>
*/
public function mapWithKeys(callable $callback)
{
@ -690,7 +771,7 @@ class LazyCollection implements Enumerable
/**
* Merge the collection with the given items.
*
* @param mixed $items
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @return static
*/
public function merge($items)
@ -701,8 +782,10 @@ class LazyCollection implements Enumerable
/**
* Recursively merge the collection with the given items.
*
* @param mixed $items
* @return static
* @template TMergeRecursiveValue
*
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TMergeRecursiveValue>|iterable<TKey, TMergeRecursiveValue> $items
* @return static<TKey, TValue|TMergeRecursiveValue>
*/
public function mergeRecursive($items)
{
@ -712,8 +795,10 @@ class LazyCollection implements Enumerable
/**
* Create a collection by using this collection for keys and another for its values.
*
* @param mixed $values
* @return static
* @template TCombineValue
*
* @param \IteratorAggregate<array-key, TCombineValue>|array<array-key, TCombineValue>|(callable(): \Generator<array-key, TCombineValue>) $values
* @return static<TKey, TCombineValue>
*/
public function combine($values)
{
@ -743,7 +828,7 @@ class LazyCollection implements Enumerable
/**
* Union the collection with the given items.
*
* @param mixed $items
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @return static
*/
public function union($items)
@ -776,7 +861,7 @@ class LazyCollection implements Enumerable
/**
* Get the items with the specified keys.
*
* @param mixed $keys
* @param \Illuminate\Support\Enumerable<array-key, TKey>|array<array-key, TKey> $keys
* @return static
*/
public function only($keys)
@ -811,7 +896,7 @@ class LazyCollection implements Enumerable
/**
* Push all of the given items onto the collection.
*
* @param iterable $source
* @param iterable<array-key, TValue> $source
* @return static
*/
public function concat($source)
@ -826,7 +911,7 @@ class LazyCollection implements Enumerable
* Get one or a specified number of items randomly from the collection.
*
* @param int|null $number
* @return static|mixed
* @return static<int, TValue>|TValue
*
* @throws \InvalidArgumentException
*/
@ -840,7 +925,7 @@ class LazyCollection implements Enumerable
/**
* Replace the collection items with the given items.
*
* @param mixed $items
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @return static
*/
public function replace($items)
@ -867,7 +952,7 @@ class LazyCollection implements Enumerable
/**
* Recursively replace the collection items with the given items.
*
* @param mixed $items
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
* @return static
*/
public function replaceRecursive($items)
@ -888,12 +973,13 @@ class LazyCollection implements Enumerable
/**
* Search the collection for a given value and return the corresponding key if successful.
*
* @param mixed $value
* @param TValue|(callable(TValue,TKey): bool) $value
* @param bool $strict
* @return mixed
* @return TKey|bool
*/
public function search($value, $strict = false)
{
/** @var (callable(TValue,TKey): bool) $predicate */
$predicate = $this->useAsCallable($value)
? $value
: function ($item) use ($value, $strict) {
@ -925,7 +1011,7 @@ class LazyCollection implements Enumerable
*
* @param int $size
* @param int $step
* @return static
* @return static<int, static>
*/
public function sliding($size = 2, $step = 1)
{
@ -938,7 +1024,7 @@ class LazyCollection implements Enumerable
$chunk[$iterator->key()] = $iterator->current();
if (count($chunk) == $size) {
yield tap(new static($chunk), function () use (&$chunk, $step) {
yield (new static($chunk))->tap(function () use (&$chunk, $step) {
$chunk = array_slice($chunk, $step, null, true);
});
@ -985,7 +1071,7 @@ class LazyCollection implements Enumerable
/**
* Skip items in the collection until the given condition is met.
*
* @param mixed $value
* @param TValue|callable(TValue,TKey): bool $value
* @return static
*/
public function skipUntil($value)
@ -998,7 +1084,7 @@ class LazyCollection implements Enumerable
/**
* Skip items in the collection while the given condition is met.
*
* @param mixed $value
* @param TValue|callable(TValue,TKey): bool $value
* @return static
*/
public function skipWhile($value)
@ -1042,7 +1128,7 @@ class LazyCollection implements Enumerable
* Split a collection into a certain number of groups.
*
* @param int $numberOfGroups
* @return static
* @return static<int, static>
*/
public function split($numberOfGroups)
{
@ -1052,10 +1138,10 @@ class LazyCollection implements Enumerable
/**
* Get the first item in the collection, but only if exactly one item exists. Otherwise, throw an exception.
*
* @param mixed $key
* @param (callable(TValue, TKey): bool)|string $key
* @param mixed $operator
* @param mixed $value
* @return mixed
* @return TValue
*
* @throws \Illuminate\Support\ItemNotFoundException
* @throws \Illuminate\Support\MultipleItemsFoundException
@ -1067,7 +1153,7 @@ class LazyCollection implements Enumerable
: $key;
return $this
->when($filter)
->unless($filter == null)
->filter($filter)
->take(2)
->collect()
@ -1077,10 +1163,10 @@ class LazyCollection implements Enumerable
/**
* Get the first item in the collection but throw an exception if no matching items exist.
*
* @param mixed $key
* @param (callable(TValue, TKey): bool)|string $key
* @param mixed $operator
* @param mixed $value
* @return mixed
* @return TValue
*
* @throws \Illuminate\Support\ItemNotFoundException
*/
@ -1091,7 +1177,7 @@ class LazyCollection implements Enumerable
: $key;
return $this
->when($filter)
->unless($filter == null)
->filter($filter)
->take(1)
->collect()
@ -1102,7 +1188,7 @@ class LazyCollection implements Enumerable
* Chunk the collection into chunks of the given size.
*
* @param int $size
* @return static
* @return static<int, static>
*/
public function chunk($size)
{
@ -1141,7 +1227,7 @@ class LazyCollection implements Enumerable
* Split a collection into a certain number of groups, and fill the first groups completely.
*
* @param int $numberOfGroups
* @return static
* @return static<int, static>
*/
public function splitIn($numberOfGroups)
{
@ -1151,8 +1237,8 @@ class LazyCollection implements Enumerable
/**
* Chunk the collection into chunks with a callback.
*
* @param callable $callback
* @return static
* @param callable(TValue, TKey, Collection<TKey, TValue>): bool $callback
* @return static<int, static<int, TValue>>
*/
public function chunkWhile(callable $callback)
{
@ -1188,7 +1274,7 @@ class LazyCollection implements Enumerable
/**
* Sort through each item with a callback.
*
* @param callable|null|int $callback
* @param (callable(TValue, TValue): int)|null|int $callback
* @return static
*/
public function sort($callback = null)
@ -1210,7 +1296,7 @@ class LazyCollection implements Enumerable
/**
* Sort the collection using the given callback.
*
* @param callable|string $callback
* @param array<array-key, (callable(TValue, TKey): mixed)|array<array-key, string>|(callable(TValue, TKey): mixed)|string $callback
* @param int $options
* @param bool $descending
* @return static
@ -1223,7 +1309,7 @@ class LazyCollection implements Enumerable
/**
* Sort the collection in descending order using the given callback.
*
* @param callable|string $callback
* @param array<array-key, (callable(TValue, TKey): mixed)|array<array-key, string>|(callable(TValue, TKey): mixed)|string $callback
* @param int $options
* @return static
*/
@ -1255,6 +1341,17 @@ class LazyCollection implements Enumerable
return $this->passthru('sortKeysDesc', func_get_args());
}
/**
* Sort the collection keys using a callback.
*
* @param callable(TKey, TKey): int $callback
* @return static
*/
public function sortKeysUsing(callable $callback)
{
return $this->passthru('sortKeysUsing', func_get_args());
}
/**
* Take the first or last {$limit} items.
*
@ -1287,11 +1384,12 @@ class LazyCollection implements Enumerable
/**
* Take items in the collection until the given condition is met.
*
* @param mixed $value
* @param TValue|callable(TValue,TKey): bool $value
* @return static
*/
public function takeUntil($value)
{
/** @var callable(TValue, TKey): bool $callback */
$callback = $this->useAsCallable($value) ? $value : $this->equality($value);
return new static(function () use ($callback) {
@ -1315,19 +1413,30 @@ class LazyCollection implements Enumerable
{
$timeout = $timeout->getTimestamp();
return $this->takeWhile(function () use ($timeout) {
return $this->now() < $timeout;
return new static(function () use ($timeout) {
if ($this->now() >= $timeout) {
return;
}
foreach ($this as $key => $value) {
yield $key => $value;
if ($this->now() >= $timeout) {
break;
}
}
});
}
/**
* Take items in the collection while the given condition is met.
*
* @param mixed $value
* @param TValue|callable(TValue,TKey): bool $value
* @return static
*/
public function takeWhile($value)
{
/** @var callable(TValue, TKey): bool $callback */
$callback = $this->useAsCallable($value) ? $value : $this->equality($value);
return $this->takeUntil(function ($item, $key) use ($callback) {
@ -1338,7 +1447,7 @@ class LazyCollection implements Enumerable
/**
* Pass each item in the collection to the given callback, lazily.
*
* @param callable $callback
* @param callable(TValue, TKey): mixed $callback
* @return static
*/
public function tapEach(callable $callback)
@ -1353,10 +1462,44 @@ class LazyCollection implements Enumerable
}
/**
* Reset the keys on the underlying array.
* Convert a flatten "dot" notation array into an expanded array.
*
* @return static
*/
public function undot()
{
return $this->passthru('undot', []);
}
/**
* Return only unique items from the collection array.
*
* @param (callable(TValue, TKey): mixed)|string|null $key
* @param bool $strict
* @return static
*/
public function unique($key = null, $strict = false)
{
$callback = $this->valueRetriever($key);
return new static(function () use ($callback, $strict) {
$exists = [];
foreach ($this as $key => $item) {
if (! in_array($id = $callback($item, $key), $exists, $strict)) {
yield $key => $item;
$exists[] = $id;
}
}
});
}
/**
* Reset the keys on the underlying array.
*
* @return static<int, TValue>
*/
public function values()
{
return new static(function () {
@ -1372,8 +1515,10 @@ class LazyCollection implements Enumerable
* e.g. new LazyCollection([1, 2, 3])->zip([4, 5, 6]);
* => [[1, 4], [2, 5], [3, 6]]
*
* @param mixed ...$items
* @return static
* @template TZipValue
*
* @param \Illuminate\Contracts\Support\Arrayable<array-key, TZipValue>|iterable<array-key, TZipValue> ...$items
* @return static<int, static<int, TValue|TZipValue>>
*/
public function zip($items)
{
@ -1395,9 +1540,11 @@ class LazyCollection implements Enumerable
/**
* Pad collection to the specified length with a value.
*
* @template TPadValue
*
* @param int $size
* @param mixed $value
* @return static
* @param TPadValue $value
* @return static<int, TValue|TPadValue>
*/
public function pad($size, $value)
{
@ -1423,10 +1570,9 @@ class LazyCollection implements Enumerable
/**
* Get the values iterator.
*
* @return \Traversable
* @return \Traversable<TKey, TValue>
*/
#[\ReturnTypeWillChange]
public function getIterator()
public function getIterator(): Traversable
{
return $this->makeIterator($this->source);
}
@ -1436,8 +1582,7 @@ class LazyCollection implements Enumerable
*
* @return int
*/
#[\ReturnTypeWillChange]
public function count()
public function count(): int
{
if (is_array($this->source)) {
return count($this->source);
@ -1449,8 +1594,11 @@ class LazyCollection implements Enumerable
/**
* Make an iterator from the given source.
*
* @param mixed $source
* @return \Traversable
* @template TIteratorKey of array-key
* @template TIteratorValue
*
* @param \IteratorAggregate<TIteratorKey, TIteratorValue>|array<TIteratorKey, TIteratorValue>|(callable(): \Generator<TIteratorKey, TIteratorValue>) $source
* @return \Traversable<TIteratorKey, TIteratorValue>
*/
protected function makeIterator($source)
{
@ -1468,9 +1616,9 @@ class LazyCollection implements Enumerable
/**
* Explode the "value" and "key" arguments passed to "pluck".
*
* @param string|array $value
* @param string|array|null $key
* @return array
* @param string|string[] $value
* @param string|string[]|null $key
* @return array{string[],string[]|null}
*/
protected function explodePluckParameters($value, $key)
{
@ -1485,7 +1633,7 @@ class LazyCollection implements Enumerable
* Pass this lazy collection through a method on the collection class.
*
* @param string $method
* @param array $params
* @param array<mixed> $params
* @return static
*/
protected function passthru($method, array $params)

View file

@ -6,4 +6,35 @@ use RuntimeException;
class MultipleItemsFoundException extends RuntimeException
{
/**
* The number of items found.
*
* @var int
*/
public $count;
/**
* Create a new exception instance.
*
* @param int $count
* @param int $code
* @param \Throwable|null $previous
* @return void
*/
public function __construct($count, $code = 0, $previous = null)
{
$this->count = $count;
parent::__construct("$count items were found.", $code, $previous);
}
/**
* Get the number of items found.
*
* @return int
*/
public function getCount()
{
return $this->count;
}
}

View file

@ -11,15 +11,19 @@ use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Enumerable;
use Illuminate\Support\HigherOrderCollectionProxy;
use Illuminate\Support\HigherOrderWhenProxy;
use JsonSerializable;
use Symfony\Component\VarDumper\VarDumper;
use Traversable;
use UnexpectedValueException;
/**
* @template TKey of array-key
* @template TValue
*
* @property-read HigherOrderCollectionProxy $average
* @property-read HigherOrderCollectionProxy $avg
* @property-read HigherOrderCollectionProxy $contains
* @property-read HigherOrderCollectionProxy $doesntContain
* @property-read HigherOrderCollectionProxy $each
* @property-read HigherOrderCollectionProxy $every
* @property-read HigherOrderCollectionProxy $filter
@ -32,28 +36,40 @@ use Traversable;
* @property-read HigherOrderCollectionProxy $min
* @property-read HigherOrderCollectionProxy $partition
* @property-read HigherOrderCollectionProxy $reject
* @property-read HigherOrderCollectionProxy $skipUntil
* @property-read HigherOrderCollectionProxy $skipWhile
* @property-read HigherOrderCollectionProxy $some
* @property-read HigherOrderCollectionProxy $sortBy
* @property-read HigherOrderCollectionProxy $sortByDesc
* @property-read HigherOrderCollectionProxy $skipUntil
* @property-read HigherOrderCollectionProxy $skipWhile
* @property-read HigherOrderCollectionProxy $sum
* @property-read HigherOrderCollectionProxy $takeUntil
* @property-read HigherOrderCollectionProxy $takeWhile
* @property-read HigherOrderCollectionProxy $unique
* @property-read HigherOrderCollectionProxy $unless
* @property-read HigherOrderCollectionProxy $until
* @property-read HigherOrderCollectionProxy $when
*/
trait EnumeratesValues
{
use Conditionable;
/**
* Indicates that the object's string representation should be escaped when __toString is invoked.
*
* @var bool
*/
protected $escapeWhenCastingToString = false;
/**
* The methods that can be proxied.
*
* @var string[]
* @var array<int, string>
*/
protected static $proxies = [
'average',
'avg',
'contains',
'doesntContain',
'each',
'every',
'filter',
@ -75,14 +91,19 @@ trait EnumeratesValues
'takeUntil',
'takeWhile',
'unique',
'unless',
'until',
'when',
];
/**
* Create a new collection instance if the value isn't one already.
*
* @param mixed $items
* @return static
* @template TMakeKey of array-key
* @template TMakeValue
*
* @param \Illuminate\Contracts\Support\Arrayable<TMakeKey, TMakeValue>|iterable<TMakeKey, TMakeValue>|null $items
* @return static<TMakeKey, TMakeValue>
*/
public static function make($items = [])
{
@ -92,8 +113,11 @@ trait EnumeratesValues
/**
* Wrap the given value in a collection if applicable.
*
* @param mixed $value
* @return static
* @template TWrapKey of array-key
* @template TWrapValue
*
* @param iterable<TWrapKey, TWrapValue> $value
* @return static<TWrapKey, TWrapValue>
*/
public static function wrap($value)
{
@ -105,8 +129,11 @@ trait EnumeratesValues
/**
* Get the underlying items from the given collection if applicable.
*
* @param array|static $value
* @return array
* @template TUnwrapKey of array-key
* @template TUnwrapValue
*
* @param array<TUnwrapKey, TUnwrapValue>|static<TUnwrapKey, TUnwrapValue> $value
* @return array<TUnwrapKey, TUnwrapValue>
*/
public static function unwrap($value)
{
@ -126,9 +153,11 @@ trait EnumeratesValues
/**
* Create a new collection by invoking the callback a given amount of times.
*
* @template TTimesValue
*
* @param int $number
* @param callable|null $callback
* @return static
* @param (callable(int): TTimesValue)|null $callback
* @return static<int, TTimesValue>
*/
public static function times($number, callable $callback = null)
{
@ -137,15 +166,15 @@ trait EnumeratesValues
}
return static::range(1, $number)
->when($callback)
->unless($callback == null)
->map($callback);
}
/**
* Alias for the "avg" method.
*
* @param callable|string|null $callback
* @return mixed
* @param (callable(TValue): float|int)|string|null $callback
* @return float|int|null
*/
public function average($callback = null)
{
@ -155,7 +184,7 @@ trait EnumeratesValues
/**
* Alias for the "contains" method.
*
* @param mixed $key
* @param (callable(TValue, TKey): bool)|TValue|string $key
* @param mixed $operator
* @param mixed $value
* @return bool
@ -168,8 +197,8 @@ trait EnumeratesValues
/**
* Determine if an item exists, using strict comparison.
*
* @param mixed $key
* @param mixed $value
* @param (callable(TValue): bool)|TValue|array-key $key
* @param TValue|null $value
* @return bool
*/
public function containsStrict($key, $value = null)
@ -197,7 +226,7 @@ trait EnumeratesValues
* Dump the items and end the script.
*
* @param mixed ...$args
* @return void
* @return never
*/
public function dd(...$args)
{
@ -225,7 +254,7 @@ trait EnumeratesValues
/**
* Execute a callback over each item.
*
* @param callable $callback
* @param callable(TValue, TKey): mixed $callback
* @return $this
*/
public function each(callable $callback)
@ -242,7 +271,7 @@ trait EnumeratesValues
/**
* Execute a callback over each nested chunk of items.
*
* @param callable $callback
* @param callable(...mixed): mixed $callback
* @return static
*/
public function eachSpread(callable $callback)
@ -257,7 +286,7 @@ trait EnumeratesValues
/**
* Determine if all items pass the given truth test.
*
* @param string|callable $key
* @param (callable(TValue, TKey): bool)|TValue|string $key
* @param mixed $operator
* @param mixed $value
* @return bool
@ -285,7 +314,7 @@ trait EnumeratesValues
* @param string $key
* @param mixed $operator
* @param mixed $value
* @return mixed
* @return TValue|null
*/
public function firstWhere($key, $operator = null, $value = null)
{
@ -305,8 +334,10 @@ trait EnumeratesValues
/**
* Run a map over each nested chunk of items.
*
* @param callable $callback
* @return static
* @template TMapSpreadValue
*
* @param callable(mixed): TMapSpreadValue $callback
* @return static<TKey, TMapSpreadValue>
*/
public function mapSpread(callable $callback)
{
@ -322,8 +353,11 @@ trait EnumeratesValues
*
* The callback should return an associative array with a single key/value pair.
*
* @param callable $callback
* @return static
* @template TMapToGroupsKey of array-key
* @template TMapToGroupsValue
*
* @param callable(TValue, TKey): array<TMapToGroupsKey, TMapToGroupsValue> $callback
* @return static<TMapToGroupsKey, static<int, TMapToGroupsValue>>
*/
public function mapToGroups(callable $callback)
{
@ -335,8 +369,8 @@ trait EnumeratesValues
/**
* Map a collection and flatten the result by a single level.
*
* @param callable $callback
* @return static
* @param callable(TValue, TKey): mixed $callback
* @return static<int, mixed>
*/
public function flatMap(callable $callback)
{
@ -346,8 +380,10 @@ trait EnumeratesValues
/**
* Map the values into a new class.
*
* @param string $class
* @return static
* @template TMapIntoValue
*
* @param class-string<TMapIntoValue> $class
* @return static<TKey, TMapIntoValue>
*/
public function mapInto($class)
{
@ -359,8 +395,8 @@ trait EnumeratesValues
/**
* Get the min value of a given key.
*
* @param callable|string|null $callback
* @return mixed
* @param (callable(TValue):mixed)|string|null $callback
* @return TValue
*/
public function min($callback = null)
{
@ -378,8 +414,8 @@ trait EnumeratesValues
/**
* Get the max value of a given key.
*
* @param callable|string|null $callback
* @return mixed
* @param (callable(TValue):mixed)|string|null $callback
* @return TValue
*/
public function max($callback = null)
{
@ -411,10 +447,10 @@ trait EnumeratesValues
/**
* Partition the collection into two arrays using the given callback or key.
*
* @param callable|string $key
* @param mixed $operator
* @param mixed $value
* @return static
* @param (callable(TValue, TKey): bool)|TValue|string $key
* @param TValue|string|null $operator
* @param TValue|null $value
* @return static<int<0, 1>, static<TKey, TValue>>
*/
public function partition($key, $operator = null, $value = null)
{
@ -439,7 +475,7 @@ trait EnumeratesValues
/**
* Get the sum of the given values.
*
* @param callable|string|null $callback
* @param (callable(TValue): mixed)|string|null $callback
* @return mixed
*/
public function sum($callback = null)
@ -453,35 +489,14 @@ trait EnumeratesValues
}, 0);
}
/**
* Apply the callback if the value is truthy.
*
* @param bool|mixed $value
* @param callable|null $callback
* @param callable|null $default
* @return static|mixed
*/
public function when($value, callable $callback = null, callable $default = null)
{
if (! $callback) {
return new HigherOrderWhenProxy($this, $value);
}
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|null $default
* @return static|mixed
* @template TWhenEmptyReturnType
*
* @param (callable($this): TWhenEmptyReturnType) $callback
* @param (callable($this): TWhenEmptyReturnType)|null $default
* @return $this|TWhenEmptyReturnType
*/
public function whenEmpty(callable $callback, callable $default = null)
{
@ -491,34 +506,25 @@ trait EnumeratesValues
/**
* Apply the callback if the collection is not empty.
*
* @param callable $callback
* @param callable|null $default
* @return static|mixed
* @template TWhenNotEmptyReturnType
*
* @param callable($this): TWhenNotEmptyReturnType $callback
* @param (callable($this): TWhenNotEmptyReturnType)|null $default
* @return $this|TWhenNotEmptyReturnType
*/
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|null $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|null $default
* @return static|mixed
* @template TUnlessEmptyReturnType
*
* @param callable($this): TUnlessEmptyReturnType $callback
* @param (callable($this): TUnlessEmptyReturnType)|null $default
* @return $this|TUnlessEmptyReturnType
*/
public function unlessEmpty(callable $callback, callable $default = null)
{
@ -528,9 +534,11 @@ trait EnumeratesValues
/**
* Apply the callback unless the collection is not empty.
*
* @param callable $callback
* @param callable|null $default
* @return static|mixed
* @template TUnlessNotEmptyReturnType
*
* @param callable($this): TUnlessNotEmptyReturnType $callback
* @param (callable($this): TUnlessNotEmptyReturnType)|null $default
* @return $this|TUnlessNotEmptyReturnType
*/
public function unlessNotEmpty(callable $callback, callable $default = null)
{
@ -588,7 +596,7 @@ trait EnumeratesValues
* Filter items by the given key value pair.
*
* @param string $key
* @param mixed $values
* @param \Illuminate\Contracts\Support\Arrayable|iterable $values
* @param bool $strict
* @return static
*/
@ -605,7 +613,7 @@ trait EnumeratesValues
* Filter items by the given key value pair using strict comparison.
*
* @param string $key
* @param mixed $values
* @param \Illuminate\Contracts\Support\Arrayable|iterable $values
* @return static
*/
public function whereInStrict($key, $values)
@ -617,7 +625,7 @@ trait EnumeratesValues
* Filter items such that the value of the given key is between the given values.
*
* @param string $key
* @param array $values
* @param \Illuminate\Contracts\Support\Arrayable|iterable $values
* @return static
*/
public function whereBetween($key, $values)
@ -629,7 +637,7 @@ trait EnumeratesValues
* Filter items such that the value of the given key is not between the given values.
*
* @param string $key
* @param array $values
* @param \Illuminate\Contracts\Support\Arrayable|iterable $values
* @return static
*/
public function whereNotBetween($key, $values)
@ -643,7 +651,7 @@ trait EnumeratesValues
* Filter items by the given key value pair.
*
* @param string $key
* @param mixed $values
* @param \Illuminate\Contracts\Support\Arrayable|iterable $values
* @param bool $strict
* @return static
*/
@ -660,7 +668,7 @@ trait EnumeratesValues
* Filter items by the given key value pair using strict comparison.
*
* @param string $key
* @param mixed $values
* @param \Illuminate\Contracts\Support\Arrayable|iterable $values
* @return static
*/
public function whereNotInStrict($key, $values)
@ -671,7 +679,7 @@ trait EnumeratesValues
/**
* Filter the items, removing any items that don't match the given type(s).
*
* @param string|string[] $type
* @param class-string|array<array-key, class-string> $type
* @return static
*/
public function whereInstanceOf($type)
@ -694,8 +702,10 @@ trait EnumeratesValues
/**
* Pass the collection to the given callback and return the result.
*
* @param callable $callback
* @return mixed
* @template TPipeReturnType
*
* @param callable($this): TPipeReturnType $callback
* @return TPipeReturnType
*/
public function pipe(callable $callback)
{
@ -705,7 +715,7 @@ trait EnumeratesValues
/**
* Pass the collection into a new class.
*
* @param string $class
* @param class-string $class
* @return mixed
*/
public function pipeInto($class)
@ -714,24 +724,30 @@ trait EnumeratesValues
}
/**
* Pass the collection to the given callback and then return it.
* Pass the collection through a series of callable pipes and return the result.
*
* @param callable $callback
* @return $this
* @param array<callable> $callbacks
* @return mixed
*/
public function tap(callable $callback)
public function pipeThrough($callbacks)
{
$callback(clone $this);
return $this;
return Collection::make($callbacks)->reduce(
function ($carry, $callback) {
return $callback($carry);
},
$this,
);
}
/**
* Reduce the collection to a single value.
*
* @param callable $callback
* @param mixed $initial
* @return mixed
* @template TReduceInitial
* @template TReduceReturnType
*
* @param callable(TReduceInitial|TReduceReturnType, TValue, TKey): TReduceReturnType $callback
* @param TReduceInitial $initial
* @return TReduceReturnType
*/
public function reduce(callable $callback, $initial = null)
{
@ -745,21 +761,36 @@ trait EnumeratesValues
}
/**
* Reduce an associative collection to a single value.
* Reduce the collection to multiple aggregate values.
*
* @param callable $callback
* @param mixed $initial
* @return mixed
* @param mixed ...$initial
* @return array
*
* @throws \UnexpectedValueException
*/
public function reduceWithKeys(callable $callback, $initial = null)
public function reduceSpread(callable $callback, ...$initial)
{
return $this->reduce($callback, $initial);
$result = $initial;
foreach ($this as $key => $value) {
$result = call_user_func_array($callback, array_merge($result, [$value, $key]));
if (! is_array($result)) {
throw new UnexpectedValueException(sprintf(
"%s::reduceMany expects reducer to return an array, but got a '%s' instead.",
class_basename(static::class), gettype($result)
));
}
}
return $result;
}
/**
* Create a collection of all elements that do not pass a given truth test.
*
* @param callable|mixed $callback
* @param (callable(TValue, TKey): bool)|bool $callback
* @return static
*/
public function reject($callback = true)
@ -773,10 +804,23 @@ trait EnumeratesValues
});
}
/**
* Pass the collection to the given callback and then return it.
*
* @param callable($this): mixed $callback
* @return $this
*/
public function tap(callable $callback)
{
$callback($this);
return $this;
}
/**
* Return only unique items from the collection array.
*
* @param string|callable|null $key
* @param (callable(TValue, TKey): mixed)|string|null $key
* @param bool $strict
* @return static
*/
@ -798,7 +842,7 @@ trait EnumeratesValues
/**
* Return only unique items from the collection array using strict comparison.
*
* @param string|callable|null $key
* @param (callable(TValue, TKey): mixed)|string|null $key
* @return static
*/
public function uniqueStrict($key = null)
@ -809,7 +853,7 @@ trait EnumeratesValues
/**
* Collect the values into a collection.
*
* @return \Illuminate\Support\Collection
* @return \Illuminate\Support\Collection<TKey, TValue>
*/
public function collect()
{
@ -819,7 +863,7 @@ trait EnumeratesValues
/**
* Get the collection of items as a plain array.
*
* @return array
* @return array<TKey, mixed>
*/
public function toArray()
{
@ -831,10 +875,9 @@ trait EnumeratesValues
/**
* Convert the object into something JSON serializable.
*
* @return array
* @return array<TKey, mixed>
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return array_map(function ($value) {
if ($value instanceof JsonSerializable) {
@ -878,7 +921,22 @@ trait EnumeratesValues
*/
public function __toString()
{
return $this->toJson();
return $this->escapeWhenCastingToString
? e($this->toJson())
: $this->toJson();
}
/**
* Indicate that the model's string representation should be escaped when __toString is invoked.
*
* @param bool $escape
* @return $this
*/
public function escapeWhenCastingToString($escape = true)
{
$this->escapeWhenCastingToString = $escape;
return $this;
}
/**
@ -913,7 +971,7 @@ trait EnumeratesValues
* Results array of items from Collection or Arrayable.
*
* @param mixed $items
* @return array
* @return array<TKey, TValue>
*/
protected function getArrayableItems($items)
{
@ -1015,7 +1073,7 @@ trait EnumeratesValues
* Make a function to check an item's equality.
*
* @param mixed $value
* @return \Closure
* @return \Closure(mixed): bool
*/
protected function equality($value)
{
@ -1040,7 +1098,7 @@ trait EnumeratesValues
/**
* Make a function that returns what's passed to it.
*
* @return \Closure
* @return \Closure(TValue): TValue
*/
protected function identity()
{

View file

@ -14,9 +14,10 @@
}
],
"require": {
"php": "^7.3|^8.0",
"illuminate/contracts": "^8.0",
"illuminate/macroable": "^8.0"
"php": "^8.0.2",
"illuminate/conditionable": "^9.0",
"illuminate/contracts": "^9.0",
"illuminate/macroable": "^9.0"
},
"autoload": {
"psr-4": {
@ -28,11 +29,11 @@
},
"extra": {
"branch-alias": {
"dev-master": "8.x-dev"
"dev-master": "9.x-dev"
}
},
"suggest": {
"symfony/var-dumper": "Required to use the dump method (^5.1.4)."
"symfony/var-dumper": "Required to use the dump method (^6.0)."
},
"config": {
"sort-packages": true

View file

@ -7,8 +7,11 @@ if (! function_exists('collect')) {
/**
* Create a collection from the given value.
*
* @param mixed $value
* @return \Illuminate\Support\Collection
* @template TKey of array-key
* @template TValue
*
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue>|null $value
* @return \Illuminate\Support\Collection<TKey, TValue>
*/
function collect($value = null)
{
@ -58,7 +61,7 @@ if (! function_exists('data_get')) {
if ($segment === '*') {
if ($target instanceof Collection) {
$target = $target->all();
} elseif (! is_array($target)) {
} elseif (! is_iterable($target)) {
return value($default);
}

View file

@ -2,17 +2,14 @@
namespace Illuminate\Support;
/**
* @mixin \Illuminate\Support\Enumerable
*/
class HigherOrderWhenProxy
{
/**
* The collection being operated on.
* The target being conditionally operated on.
*
* @var \Illuminate\Support\Enumerable
* @var mixed
*/
protected $collection;
protected $target;
/**
* The condition for proxying.
@ -24,18 +21,18 @@ class HigherOrderWhenProxy
/**
* Create a new proxy instance.
*
* @param \Illuminate\Support\Enumerable $collection
* @param mixed $target
* @param bool $condition
* @return void
*/
public function __construct(Enumerable $collection, $condition)
public function __construct($target, $condition)
{
$this->target = $target;
$this->condition = $condition;
$this->collection = $collection;
}
/**
* Proxy accessing an attribute onto the collection.
* Proxy accessing an attribute onto the target.
*
* @param string $key
* @return mixed
@ -43,12 +40,12 @@ class HigherOrderWhenProxy
public function __get($key)
{
return $this->condition
? $this->collection->{$key}
: $this->collection;
? $this->target->{$key}
: $this->target;
}
/**
* Proxy a method call onto the collection.
* Proxy a method call on the target.
*
* @param string $method
* @param array $parameters
@ -57,7 +54,7 @@ class HigherOrderWhenProxy
public function __call($method, $parameters)
{
return $this->condition
? $this->collection->{$method}(...$parameters)
: $this->collection;
? $this->target->{$method}(...$parameters)
: $this->target;
}
}

View file

@ -1,14 +1,16 @@
Copyright (c) 2018-2019 Fabien Potencier
The MIT License (MIT)
Copyright (c) Taylor Otwell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

View file

@ -0,0 +1,65 @@
<?php
namespace Illuminate\Support\Traits;
use Closure;
use Illuminate\Support\HigherOrderWhenProxy;
trait Conditionable
{
/**
* Apply the callback if the given "value" is (or resolves to) truthy.
*
* @template TWhenParameter
* @template TWhenReturnType
*
* @param (\Closure($this): TWhenParameter)|TWhenParameter $value
* @param (callable($this, TWhenParameter): TWhenReturnType)|null $callback
* @param (callable($this, TWhenParameter): TWhenReturnType)|null $default
* @return $this|TWhenReturnType
*/
public function when($value, callable $callback = null, callable $default = null)
{
$value = $value instanceof Closure ? $value($this) : $value;
if (! $callback) {
return new HigherOrderWhenProxy($this, $value);
}
if ($value) {
return $callback($this, $value) ?? $this;
} elseif ($default) {
return $default($this, $value) ?? $this;
}
return $this;
}
/**
* Apply the callback if the given "value" is (or resolves to) falsy.
*
* @template TUnlessParameter
* @template TUnlessReturnType
*
* @param (\Closure($this): TUnlessParameter)|TUnlessParameter $value
* @param (callable($this, TUnlessParameter): TUnlessReturnType)|null $callback
* @param (callable($this, TUnlessParameter): TUnlessReturnType)|null $default
* @return $this|TUnlessReturnType
*/
public function unless($value, callable $callback = null, callable $default = null)
{
$value = $value instanceof Closure ? $value($this) : $value;
if (! $callback) {
return new HigherOrderWhenProxy($this, ! $value);
}
if (! $value) {
return $callback($this, $value) ?? $this;
} elseif ($default) {
return $default($this, $value) ?? $this;
}
return $this;
}
}

View file

@ -0,0 +1,33 @@
{
"name": "illuminate/conditionable",
"description": "The Illuminate Conditionable package.",
"license": "MIT",
"homepage": "https://laravel.com",
"support": {
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"authors": [
{
"name": "Taylor Otwell",
"email": "taylor@laravel.com"
}
],
"require": {
"php": "^8.0.2"
},
"autoload": {
"psr-4": {
"Illuminate\\Support\\": ""
}
},
"extra": {
"branch-alias": {
"dev-master": "9.x-dev"
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev"
}

View file

@ -137,7 +137,7 @@ class BoundMethod
*/
protected static function getCallReflector($callback)
{
if (is_string($callback) && strpos($callback, '::') !== false) {
if (is_string($callback) && str_contains($callback, '::')) {
$callback = explode('::', $callback);
} elseif (is_object($callback) && ! $callback instanceof Closure) {
$callback = [$callback, '__invoke'];
@ -171,6 +171,12 @@ class BoundMethod
$dependencies[] = $parameters[$className];
unset($parameters[$className]);
} elseif ($parameter->isVariadic()) {
$variadicDependencies = $container->make($className);
$dependencies = array_merge($dependencies, is_array($variadicDependencies)
? $variadicDependencies
: [$variadicDependencies]);
} else {
$dependencies[] = $container->make($className);
}
@ -191,6 +197,6 @@ class BoundMethod
*/
protected static function isCallableWithAtSign($callback)
{
return is_string($callback) && strpos($callback, '@') !== false;
return is_string($callback) && str_contains($callback, '@');
}
}

View file

@ -187,9 +187,11 @@ class Container implements ArrayAccess, ContainerContract
}
/**
* {@inheritdoc}
* {@inheritdoc}
*
* @return bool
*/
public function has($id)
public function has(string $id): bool
{
return $this->bound($id);
}
@ -607,7 +609,7 @@ class Container implements ArrayAccess, ContainerContract
$instance = $this->make($abstract);
foreach ($this->getReboundCallbacks($abstract) as $callback) {
call_user_func($callback, $this, $instance);
$callback($this, $instance);
}
}
@ -693,9 +695,11 @@ class Container implements ArrayAccess, ContainerContract
}
/**
* {@inheritdoc}
* {@inheritdoc}
*
* @return mixed
*/
public function get($id)
public function get(string $id)
{
try {
return $this->resolve($id);
@ -882,10 +886,6 @@ class Container implements ArrayAccess, ContainerContract
return $this->notInstantiable($concrete);
}
// if (in_array($concrete, $this->buildStack)) {
// throw new CircularDependencyException("Circular dependency detected while resolving [{$concrete}].");
// }
$this->buildStack[] = $concrete;
$constructor = $reflector->getConstructor();
@ -1001,7 +1001,7 @@ class Container implements ArrayAccess, ContainerContract
protected function resolvePrimitive(ReflectionParameter $parameter)
{
if (! is_null($concrete = $this->getContextualConcrete('$'.$parameter->getName()))) {
return $concrete instanceof Closure ? $concrete($this) : $concrete;
return Util::unwrapIfClosure($concrete, $this);
}
if ($parameter->isDefaultValueAvailable()) {
@ -1237,7 +1237,6 @@ class Container implements ArrayAccess, ContainerContract
* @param string $abstract
* @param object $object
* @param array $callbacksPerType
*
* @return array
*/
protected function getCallbacksForType($abstract, $object, array $callbacksPerType)
@ -1402,8 +1401,7 @@ class Container implements ArrayAccess, ContainerContract
* @param string $key
* @return bool
*/
#[\ReturnTypeWillChange]
public function offsetExists($key)
public function offsetExists($key): bool
{
return $this->bound($key);
}
@ -1414,8 +1412,7 @@ class Container implements ArrayAccess, ContainerContract
* @param string $key
* @return mixed
*/
#[\ReturnTypeWillChange]
public function offsetGet($key)
public function offsetGet($key): mixed
{
return $this->make($key);
}
@ -1427,8 +1424,7 @@ class Container implements ArrayAccess, ContainerContract
* @param mixed $value
* @return void
*/
#[\ReturnTypeWillChange]
public function offsetSet($key, $value)
public function offsetSet($key, $value): void
{
$this->bind($key, $value instanceof Closure ? $value : function () use ($value) {
return $value;
@ -1441,8 +1437,7 @@ class Container implements ArrayAccess, ContainerContract
* @param string $key
* @return void
*/
#[\ReturnTypeWillChange]
public function offsetUnset($key)
public function offsetUnset($key): void
{
unset($this->bindings[$key], $this->instances[$key], $this->resolved[$key]);
}

View file

@ -86,7 +86,7 @@ class ContextualBindingBuilder implements ContextualBindingBuilderContract
* Specify the configuration item to bind as a primitive.
*
* @param string $key
* @param ?string $default
* @param mixed $default
* @return void
*/
public function giveConfig($key, $default = null)

View file

@ -4,6 +4,7 @@ namespace Illuminate\Container;
use Countable;
use IteratorAggregate;
use Traversable;
class RewindableGenerator implements Countable, IteratorAggregate
{
@ -37,10 +38,9 @@ class RewindableGenerator implements Countable, IteratorAggregate
/**
* Get an iterator from the generator.
*
* @return mixed
* @return \Traversable
*/
#[\ReturnTypeWillChange]
public function getIterator()
public function getIterator(): Traversable
{
return ($this->generator)();
}
@ -50,8 +50,7 @@ class RewindableGenerator implements Countable, IteratorAggregate
*
* @return int
*/
#[\ReturnTypeWillChange]
public function count()
public function count(): int
{
if (is_callable($count = $this->count)) {
$this->count = $count();

View file

@ -33,11 +33,12 @@ class Util
* From global value() helper in Illuminate\Support.
*
* @param mixed $value
* @param mixed ...$args
* @return mixed
*/
public static function unwrapIfClosure($value)
public static function unwrapIfClosure($value, ...$args)
{
return $value instanceof Closure ? $value() : $value;
return $value instanceof Closure ? $value(...$args) : $value;
}
/**
@ -53,7 +54,7 @@ class Util
$type = $parameter->getType();
if (! $type instanceof ReflectionNamedType || $type->isBuiltin()) {
return;
return null;
}
$name = $type->getName();

View file

@ -14,12 +14,12 @@
}
],
"require": {
"php": "^7.3|^8.0",
"illuminate/contracts": "^8.0",
"psr/container": "^1.0"
"php": "^8.0.2",
"illuminate/contracts": "^9.0",
"psr/container": "^1.1.1|^2.0.1"
},
"provide": {
"psr/container-implementation": "1.0"
"psr/container-implementation": "1.1|2.0"
},
"autoload": {
"psr-4": {
@ -28,7 +28,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "8.x-dev"
"dev-master": "9.x-dev"
}
},
"config": {

View file

@ -40,6 +40,13 @@ interface Guard
*/
public function validate(array $credentials = []);
/**
* Determine if the guard has a user instance.
*
* @return bool
*/
public function hasUser();
/**
* Set the current user.
*

View file

@ -8,7 +8,7 @@ interface PasswordBrokerFactory
* Get a password broker instance by name.
*
* @param string|null $name
* @return mixed
* @return \Illuminate\Contracts\Auth\PasswordBroker
*/
public function broker($name = null);
}

View file

@ -28,6 +28,8 @@ interface Broadcaster
* @param string $event
* @param array $payload
* @return void
*
* @throws \Illuminate\Broadcasting\BroadcastException
*/
public function broadcast(array $channels, $event, array $payload = []);
}

View file

@ -81,6 +81,24 @@ interface Container extends ContainerInterface
*/
public function singletonIf($abstract, $concrete = null);
/**
* Register a scoped binding in the container.
*
* @param string $abstract
* @param \Closure|string|null $concrete
* @return void
*/
public function scoped($abstract, $concrete = null);
/**
* Register a scoped binding if it hasn't already been registered.
*
* @param string $abstract
* @param \Closure|string|null $concrete
* @return void
*/
public function scopedIf($abstract, $concrete = null);
/**
* "Extend" an abstract type in the container.
*
@ -163,6 +181,15 @@ interface Container extends ContainerInterface
*/
public function resolved($abstract);
/**
* Register a new before resolving callback.
*
* @param \Closure|string $abstract
* @param \Closure|null $callback
* @return void
*/
public function beforeResolving($abstract, Closure $callback = null);
/**
* Register a new resolving callback.
*

View file

@ -27,4 +27,13 @@ interface ContextualBindingBuilder
* @return void
*/
public function giveTagged($tag);
/**
* Specify the configuration item to bind as a primitive.
*
* @param string $key
* @param mixed $default
* @return void
*/
public function giveConfig($key, $default = null);
}

View file

@ -0,0 +1,14 @@
<?php
namespace Illuminate\Contracts\Database\Eloquent;
use Illuminate\Contracts\Database\Query\Builder as BaseContract;
/**
* This interface is intentionally empty and exists to improve IDE support.
*
* @mixin \Illuminate\Database\Eloquent\Builder
*/
interface Builder extends BaseContract
{
}

View file

@ -0,0 +1,12 @@
<?php
namespace Illuminate\Contracts\Database\Query;
/**
* This interface is intentionally empty and exists to improve IDE support.
*
* @mixin \Illuminate\Database\Query\Builder
*/
interface Builder
{
}

View file

@ -41,6 +41,8 @@ interface ExceptionHandler
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @param \Throwable $e
* @return void
*
* @internal This method is not meant to be used or overwritten outside the framework.
*/
public function renderForConsole($output, Throwable $e);
}

View file

@ -25,4 +25,11 @@ interface Encrypter
* @throws \Illuminate\Contracts\Encryption\DecryptException
*/
public function decrypt($payload, $unserialize = true);
/**
* Get the encryption key that the encrypter is currently using.
*
* @return string
*/
public function getKey();
}

View file

@ -1,10 +0,0 @@
<?php
namespace Illuminate\Contracts\Filesystem;
use Exception;
class FileExistsException extends Exception
{
//
}

View file

@ -30,9 +30,7 @@ interface Filesystem
* Get the contents of a file.
*
* @param string $path
* @return string
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
* @return string|null
*/
public function get($path);
@ -41,8 +39,6 @@ interface Filesystem
*
* @param string $path
* @return resource|null The path resource or null on failure.
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function readStream($path);
@ -63,9 +59,6 @@ interface Filesystem
* @param resource $resource
* @param array $options
* @return bool
*
* @throws \InvalidArgumentException If $resource is not a file handle.
* @throws \Illuminate\Contracts\Filesystem\FileExistsException
*/
public function writeStream($path, $resource, array $options = []);

View file

@ -24,7 +24,7 @@ interface Application extends Container
/**
* Get the path to the bootstrap directory.
*
* @param string $path Optionally, a path to append to the bootstrap path
* @param string $path
* @return string
*/
public function bootstrapPath($path = '');
@ -32,7 +32,7 @@ interface Application extends Container
/**
* Get the path to the application configuration files.
*
* @param string $path Optionally, a path to append to the config path
* @param string $path
* @return string
*/
public function configPath($path = '');
@ -40,7 +40,7 @@ interface Application extends Container
/**
* Get the path to the database directory.
*
* @param string $path Optionally, a path to append to the database path
* @param string $path
* @return string
*/
public function databasePath($path = '');
@ -56,9 +56,10 @@ interface Application extends Container
/**
* Get the path to the storage directory.
*
* @param string $path
* @return string
*/
public function storagePath();
public function storagePath($path = '');
/**
* Get or check the current application environment.
@ -82,6 +83,13 @@ interface Application extends Container
*/
public function runningUnitTests();
/**
* Get an instance of the maintenance mode manager implementation.
*
* @return \Illuminate\Contracts\Foundation\MaintenanceMode
*/
public function maintenanceMode();
/**
* Determine if the application is currently down for maintenance.
*
@ -206,6 +214,14 @@ interface Application extends Container
*/
public function shouldSkipMiddleware();
/**
* Register a terminating callback with the application.
*
* @param callable|string $callback
* @return \Illuminate\Contracts\Foundation\Application
*/
public function terminating($callback);
/**
* Terminate the application.
*

View file

@ -0,0 +1,14 @@
<?php
namespace Illuminate\Contracts\Foundation;
interface ExceptionRenderer
{
/**
* Renders the given exception as HTML.
*
* @param \Throwable $throwable
* @return string
*/
public function render($throwable);
}

View file

@ -0,0 +1,35 @@
<?php
namespace Illuminate\Contracts\Foundation;
interface MaintenanceMode
{
/**
* Take the application down for maintenance.
*
* @param array $payload
* @return void
*/
public function activate(array $payload): void;
/**
* Take the application out of maintenance.
*
* @return void
*/
public function deactivate(): void;
/**
* Determine if the application is currently down for maintenance.
*
* @return bool
*/
public function active(): bool;
/**
* Get the data array which was provided when the application was placed into maintenance.
*
* @return array
*/
public function data(): array;
}

View file

@ -23,7 +23,7 @@ interface Mailable
public function queue(Queue $queue);
/**
* Deliver the queued message after the given delay.
* Deliver the queued message after (n) seconds.
*
* @param \DateTimeInterface|\DateInterval|int $delay
* @param \Illuminate\Contracts\Queue\Factory $queue

View file

@ -38,11 +38,4 @@ interface Mailer
* @return void
*/
public function send($view, array $data = [], $callback = null);
/**
* Get the array of failed recipients.
*
* @return array
*/
public function failures();
}

View file

@ -33,9 +33,7 @@ interface Job
public function fire();
/**
* Release the job back into the queue.
*
* Accepts a delay specified in seconds.
* Release the job back into the queue after (n) seconds.
*
* @param int $delay
* @return void

View file

@ -43,7 +43,7 @@ interface Queue
public function pushRaw($payload, $queue = null, array $options = []);
/**
* Push a new job onto the queue after a delay.
* Push a new job onto the queue after (n) seconds.
*
* @param \DateTimeInterface|\DateInterval|int $delay
* @param string|object $job
@ -54,7 +54,7 @@ interface Queue
public function later($delay, $job, $data = '', $queue = null);
/**
* Push a new job onto the queue after a delay.
* Push a new job onto a specific queue after (n) seconds.
*
* @param string $queue
* @param \DateTimeInterface|\DateInterval|int $delay

View file

@ -14,14 +14,14 @@ interface QueueableCollection
/**
* Get the identifiers for all of the entities.
*
* @return array
* @return array<int, mixed>
*/
public function getQueueableIds();
/**
* Get the relationships of the entities being queued.
*
* @return array
* @return array<int, string>
*/
public function getQueueableRelations();

View file

@ -7,7 +7,7 @@ interface ResponseFactory
/**
* Create a new response instance.
*
* @param string $content
* @param array|string $content
* @param int $status
* @param array $headers
* @return \Illuminate\Http\Response

View file

@ -69,6 +69,13 @@ interface UrlGenerator
*/
public function action($action, $parameters = [], $absolute = true);
/**
* Get the root controller namespace.
*
* @return string
*/
public function getRootControllerNamespace();
/**
* Set the root controller namespace.
*

View file

@ -0,0 +1,8 @@
<?php
namespace Illuminate\Contracts\Session\Middleware;
interface AuthenticatesSessions
{
//
}

View file

@ -2,12 +2,16 @@
namespace Illuminate\Contracts\Support;
/**
* @template TKey of array-key
* @template TValue
*/
interface Arrayable
{
/**
* Get the instance as an array.
*
* @return array
* @return array<TKey, TValue>
*/
public function toArray();
}

View file

@ -0,0 +1,14 @@
<?php
namespace Illuminate\Contracts\Support;
interface CanBeEscapedWhenCastToString
{
/**
* Indicate that the object's string representation should be escaped when __toString is invoked.
*
* @param bool $escape
* @return $this
*/
public function escapeWhenCastingToString($escape = true);
}

View file

@ -14,9 +14,9 @@
}
],
"require": {
"php": "^7.3|^8.0",
"psr/container": "^1.0",
"psr/simple-cache": "^1.0"
"php": "^8.0.2",
"psr/container": "^1.1.1|^2.0.1",
"psr/simple-cache": "^1.0|^2.0|^3.0"
},
"autoload": {
"psr-4": {
@ -25,7 +25,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "8.x-dev"
"dev-master": "9.x-dev"
}
},
"config": {

Some files were not shown because too many files have changed in this diff Show more