Commit inicial powerservice
This commit is contained in:
+5
@@ -0,0 +1,5 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
The changelog is maintained for all Symfony contracts at the following URL:
|
||||
https://github.com/symfony/contracts/blob/main/CHANGELOG.md
|
||||
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2020-present Fabien Potencier
|
||||
|
||||
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:
|
||||
|
||||
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,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
Symfony Deprecation Contracts
|
||||
=============================
|
||||
|
||||
A generic function and convention to trigger deprecation notices.
|
||||
|
||||
This package provides a single global function named `trigger_deprecation()` that triggers silenced deprecation notices.
|
||||
|
||||
By using a custom PHP error handler such as the one provided by the Symfony ErrorHandler component,
|
||||
the triggered deprecations can be caught and logged for later discovery, both on dev and prod environments.
|
||||
|
||||
The function requires at least 3 arguments:
|
||||
- the name of the Composer package that is triggering the deprecation
|
||||
- the version of the package that introduced the deprecation
|
||||
- the message of the deprecation
|
||||
- more arguments can be provided: they will be inserted in the message using `printf()` formatting
|
||||
|
||||
Example:
|
||||
```php
|
||||
trigger_deprecation('symfony/blockchain', '8.9', 'Using "%s" is deprecated, use "%s" instead.', 'bitcoin', 'fabcoin');
|
||||
```
|
||||
|
||||
This will generate the following message:
|
||||
`Since symfony/blockchain 8.9: Using "bitcoin" is deprecated, use "fabcoin" instead.`
|
||||
|
||||
While not necessarily recommended, the deprecation notices can be completely ignored by declaring an empty
|
||||
`function trigger_deprecation() {}` in your application.
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "symfony\/deprecation-contracts",
|
||||
"type": "library",
|
||||
"description": "A generic function and convention to trigger deprecation notices",
|
||||
"homepage": "https:\/\/symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https:\/\/symfony.com\/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"function.php"
|
||||
]
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "2.5-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony\/contracts",
|
||||
"url": "https:\/\/github.com\/symfony\/contracts"
|
||||
}
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace JooosiFonDeps;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
if (!\function_exists('JooosiFonDeps\trigger_deprecation')) {
|
||||
/**
|
||||
* Triggers a silenced deprecation notice.
|
||||
*
|
||||
* @param string $package The name of the Composer package that is triggering the deprecation
|
||||
* @param string $version The version of the package that introduced the deprecation
|
||||
* @param string $message The message of the deprecation
|
||||
* @param mixed ...$args Values to insert in the message using printf() formatting
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
function trigger_deprecation(string $package, string $version, string $message, ...$args): void
|
||||
{
|
||||
@\trigger_error(($package || $version ? "Since {$package} {$version}: " : '') . ($args ? \vsprintf($message, $args) : $message), \E_USER_DEPRECATED);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
5.4.0
|
||||
-----
|
||||
|
||||
* Deprecate `Comparator::setTarget()` and `Comparator::setOperator()`
|
||||
* Add a constructor to `Comparator` that allows setting target and operator
|
||||
* Finder's iterator has now `Symfony\Component\Finder\SplFileInfo` inner type specified
|
||||
* Add recursive .gitignore files support
|
||||
|
||||
5.0.0
|
||||
-----
|
||||
|
||||
* added `$useNaturalSort` argument to `Finder::sortByName()`
|
||||
|
||||
4.3.0
|
||||
-----
|
||||
|
||||
* added Finder::ignoreVCSIgnored() to ignore files based on rules listed in .gitignore
|
||||
|
||||
4.2.0
|
||||
-----
|
||||
|
||||
* added $useNaturalSort option to Finder::sortByName() method
|
||||
* the `Finder::sortByName()` method will have a new `$useNaturalSort`
|
||||
argument in version 5.0, not defining it is deprecated
|
||||
* added `Finder::reverseSorting()` to reverse the sorting
|
||||
|
||||
4.0.0
|
||||
-----
|
||||
|
||||
* removed `ExceptionInterface`
|
||||
* removed `Symfony\Component\Finder\Iterator\FilterIterator`
|
||||
|
||||
3.4.0
|
||||
-----
|
||||
|
||||
* deprecated `Symfony\Component\Finder\Iterator\FilterIterator`
|
||||
* added Finder::hasResults() method to check if any results were found
|
||||
|
||||
3.3.0
|
||||
-----
|
||||
|
||||
* added double-star matching to Glob::toRegex()
|
||||
|
||||
3.0.0
|
||||
-----
|
||||
|
||||
* removed deprecated classes
|
||||
|
||||
2.8.0
|
||||
-----
|
||||
|
||||
* deprecated adapters and related classes
|
||||
|
||||
2.5.0
|
||||
-----
|
||||
* added support for GLOB_BRACE in the paths passed to Finder::in()
|
||||
|
||||
2.3.0
|
||||
-----
|
||||
|
||||
* added a way to ignore unreadable directories (via Finder::ignoreUnreadableDirs())
|
||||
* unified the way subfolders that are not executable are handled by always throwing an AccessDeniedException exception
|
||||
|
||||
2.2.0
|
||||
-----
|
||||
|
||||
* added Finder::path() and Finder::notPath() methods
|
||||
* added finder adapters to improve performance on specific platforms
|
||||
* added support for wildcard characters (glob patterns) in the paths passed
|
||||
to Finder::in()
|
||||
|
||||
2.1.0
|
||||
-----
|
||||
|
||||
* added Finder::sortByAccessedTime(), Finder::sortByChangedTime(), and
|
||||
Finder::sortByModifiedTime()
|
||||
* added Countable to Finder
|
||||
* added support for an array of directories as an argument to
|
||||
Finder::exclude()
|
||||
* added searching based on the file content via Finder::contains() and
|
||||
Finder::notContains()
|
||||
* added support for the != operator in the Comparator
|
||||
* [BC BREAK] filter expressions (used for file name and content) are no more
|
||||
considered as regexps but glob patterns when they are enclosed in '*' or '?'
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder\Comparator;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class Comparator
|
||||
{
|
||||
private $target;
|
||||
private $operator = '==';
|
||||
public function __construct(?string $target = null, string $operator = '==')
|
||||
{
|
||||
if (null === $target) {
|
||||
trigger_deprecation('symfony/finder', '5.4', 'Constructing a "%s" without setting "$target" is deprecated.', __CLASS__);
|
||||
}
|
||||
$this->target = $target;
|
||||
$this->doSetOperator($operator);
|
||||
}
|
||||
/**
|
||||
* Gets the target value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTarget()
|
||||
{
|
||||
if (null === $this->target) {
|
||||
trigger_deprecation('symfony/finder', '5.4', 'Calling "%s" without initializing the target is deprecated.', __METHOD__);
|
||||
}
|
||||
return $this->target;
|
||||
}
|
||||
/**
|
||||
* @deprecated set the target via the constructor instead
|
||||
*/
|
||||
public function setTarget(string $target)
|
||||
{
|
||||
trigger_deprecation('symfony/finder', '5.4', '"%s" is deprecated. Set the target via the constructor instead.', __METHOD__);
|
||||
$this->target = $target;
|
||||
}
|
||||
/**
|
||||
* Gets the comparison operator.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOperator()
|
||||
{
|
||||
return $this->operator;
|
||||
}
|
||||
/**
|
||||
* Sets the comparison operator.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @deprecated set the operator via the constructor instead
|
||||
*/
|
||||
public function setOperator(string $operator)
|
||||
{
|
||||
trigger_deprecation('symfony/finder', '5.4', '"%s" is deprecated. Set the operator via the constructor instead.', __METHOD__);
|
||||
$this->doSetOperator('' === $operator ? '==' : $operator);
|
||||
}
|
||||
/**
|
||||
* Tests against the target.
|
||||
*
|
||||
* @param mixed $test A test value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function test($test)
|
||||
{
|
||||
if (null === $this->target) {
|
||||
trigger_deprecation('symfony/finder', '5.4', 'Calling "%s" without initializing the target is deprecated.', __METHOD__);
|
||||
}
|
||||
switch ($this->operator) {
|
||||
case '>':
|
||||
return $test > $this->target;
|
||||
case '>=':
|
||||
return $test >= $this->target;
|
||||
case '<':
|
||||
return $test < $this->target;
|
||||
case '<=':
|
||||
return $test <= $this->target;
|
||||
case '!=':
|
||||
return $test != $this->target;
|
||||
}
|
||||
return $test == $this->target;
|
||||
}
|
||||
private function doSetOperator(string $operator): void
|
||||
{
|
||||
if (!\in_array($operator, ['>', '<', '>=', '<=', '==', '!='])) {
|
||||
throw new \InvalidArgumentException(sprintf('Invalid operator "%s".', $operator));
|
||||
}
|
||||
$this->operator = $operator;
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder\Comparator;
|
||||
|
||||
/**
|
||||
* DateCompare compiles date comparisons.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class DateComparator extends Comparator
|
||||
{
|
||||
/**
|
||||
* @param string $test A comparison string
|
||||
*
|
||||
* @throws \InvalidArgumentException If the test is not understood
|
||||
*/
|
||||
public function __construct(string $test)
|
||||
{
|
||||
if (!preg_match('#^\s*(==|!=|[<>]=?|after|since|before|until)?\s*(.+?)\s*$#i', $test, $matches)) {
|
||||
throw new \InvalidArgumentException(sprintf('Don\'t understand "%s" as a date test.', $test));
|
||||
}
|
||||
try {
|
||||
$date = new \DateTime($matches[2]);
|
||||
$target = $date->format('U');
|
||||
} catch (\Exception $e) {
|
||||
throw new \InvalidArgumentException(sprintf('"%s" is not a valid date.', $matches[2]));
|
||||
}
|
||||
$operator = $matches[1] ?? '==';
|
||||
if ('since' === $operator || 'after' === $operator) {
|
||||
$operator = '>';
|
||||
}
|
||||
if ('until' === $operator || 'before' === $operator) {
|
||||
$operator = '<';
|
||||
}
|
||||
parent::__construct($target, $operator);
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder\Comparator;
|
||||
|
||||
/**
|
||||
* NumberComparator compiles a simple comparison to an anonymous
|
||||
* subroutine, which you can call with a value to be tested again.
|
||||
*
|
||||
* Now this would be very pointless, if NumberCompare didn't understand
|
||||
* magnitudes.
|
||||
*
|
||||
* The target value may use magnitudes of kilobytes (k, ki),
|
||||
* megabytes (m, mi), or gigabytes (g, gi). Those suffixed
|
||||
* with an i use the appropriate 2**n version in accordance with the
|
||||
* IEC standard: http://physics.nist.gov/cuu/Units/binary.html
|
||||
*
|
||||
* Based on the Perl Number::Compare module.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com> PHP port
|
||||
* @author Richard Clamp <richardc@unixbeard.net> Perl version
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien@symfony.com>
|
||||
* @copyright 2002 Richard Clamp <richardc@unixbeard.net>
|
||||
*
|
||||
* @see http://physics.nist.gov/cuu/Units/binary.html
|
||||
*/
|
||||
class NumberComparator extends Comparator
|
||||
{
|
||||
/**
|
||||
* @param string|null $test A comparison string or null
|
||||
*
|
||||
* @throws \InvalidArgumentException If the test is not understood
|
||||
*/
|
||||
public function __construct(?string $test)
|
||||
{
|
||||
if (null === $test || !preg_match('#^\s*(==|!=|[<>]=?)?\s*([0-9\.]+)\s*([kmg]i?)?\s*$#i', $test, $matches)) {
|
||||
throw new \InvalidArgumentException(sprintf('Don\'t understand "%s" as a number test.', $test ?? 'null'));
|
||||
}
|
||||
$target = $matches[2];
|
||||
if (!is_numeric($target)) {
|
||||
throw new \InvalidArgumentException(sprintf('Invalid number "%s".', $target));
|
||||
}
|
||||
if (isset($matches[3])) {
|
||||
// magnitude
|
||||
switch (strtolower($matches[3])) {
|
||||
case 'k':
|
||||
$target *= 1000;
|
||||
break;
|
||||
case 'ki':
|
||||
$target *= 1024;
|
||||
break;
|
||||
case 'm':
|
||||
$target *= 1000000;
|
||||
break;
|
||||
case 'mi':
|
||||
$target *= 1024 * 1024;
|
||||
break;
|
||||
case 'g':
|
||||
$target *= 1000000000;
|
||||
break;
|
||||
case 'gi':
|
||||
$target *= 1024 * 1024 * 1024;
|
||||
break;
|
||||
}
|
||||
}
|
||||
parent::__construct($target, $matches[1] ?: '==');
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder\Exception;
|
||||
|
||||
/**
|
||||
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
|
||||
*/
|
||||
class AccessDeniedException extends \UnexpectedValueException
|
||||
{
|
||||
}
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder\Exception;
|
||||
|
||||
/**
|
||||
* @author Andreas Erhard <andreas.erhard@i-med.ac.at>
|
||||
*/
|
||||
class DirectoryNotFoundException extends \InvalidArgumentException
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,707 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder;
|
||||
|
||||
use JooosiFonDeps\Symfony\Component\Finder\Comparator\DateComparator;
|
||||
use JooosiFonDeps\Symfony\Component\Finder\Comparator\NumberComparator;
|
||||
use JooosiFonDeps\Symfony\Component\Finder\Exception\DirectoryNotFoundException;
|
||||
use JooosiFonDeps\Symfony\Component\Finder\Iterator\CustomFilterIterator;
|
||||
use JooosiFonDeps\Symfony\Component\Finder\Iterator\DateRangeFilterIterator;
|
||||
use JooosiFonDeps\Symfony\Component\Finder\Iterator\DepthRangeFilterIterator;
|
||||
use JooosiFonDeps\Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator;
|
||||
use JooosiFonDeps\Symfony\Component\Finder\Iterator\FilecontentFilterIterator;
|
||||
use JooosiFonDeps\Symfony\Component\Finder\Iterator\FilenameFilterIterator;
|
||||
use JooosiFonDeps\Symfony\Component\Finder\Iterator\LazyIterator;
|
||||
use JooosiFonDeps\Symfony\Component\Finder\Iterator\SizeRangeFilterIterator;
|
||||
use JooosiFonDeps\Symfony\Component\Finder\Iterator\SortableIterator;
|
||||
/**
|
||||
* Finder allows to build rules to find files and directories.
|
||||
*
|
||||
* It is a thin wrapper around several specialized iterator classes.
|
||||
*
|
||||
* All rules may be invoked several times.
|
||||
*
|
||||
* All methods return the current Finder object to allow chaining:
|
||||
*
|
||||
* $finder = Finder::create()->files()->name('*.php')->in(__DIR__);
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @implements \IteratorAggregate<string, SplFileInfo>
|
||||
*/
|
||||
class Finder implements \IteratorAggregate, \Countable
|
||||
{
|
||||
public const IGNORE_VCS_FILES = 1;
|
||||
public const IGNORE_DOT_FILES = 2;
|
||||
public const IGNORE_VCS_IGNORED_FILES = 4;
|
||||
private $mode = 0;
|
||||
private $names = [];
|
||||
private $notNames = [];
|
||||
private $exclude = [];
|
||||
private $filters = [];
|
||||
private $depths = [];
|
||||
private $sizes = [];
|
||||
private $followLinks = \false;
|
||||
private $reverseSorting = \false;
|
||||
private $sort = \false;
|
||||
private $ignore = 0;
|
||||
private $dirs = [];
|
||||
private $dates = [];
|
||||
private $iterators = [];
|
||||
private $contains = [];
|
||||
private $notContains = [];
|
||||
private $paths = [];
|
||||
private $notPaths = [];
|
||||
private $ignoreUnreadableDirs = \false;
|
||||
private static $vcsPatterns = ['.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg'];
|
||||
public function __construct()
|
||||
{
|
||||
$this->ignore = static::IGNORE_VCS_FILES | static::IGNORE_DOT_FILES;
|
||||
}
|
||||
/**
|
||||
* Creates a new Finder.
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function create()
|
||||
{
|
||||
return new static();
|
||||
}
|
||||
/**
|
||||
* Restricts the matching to directories only.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function directories()
|
||||
{
|
||||
$this->mode = Iterator\FileTypeFilterIterator::ONLY_DIRECTORIES;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Restricts the matching to files only.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function files()
|
||||
{
|
||||
$this->mode = Iterator\FileTypeFilterIterator::ONLY_FILES;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Adds tests for the directory depth.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* $finder->depth('> 1') // the Finder will start matching at level 1.
|
||||
* $finder->depth('< 3') // the Finder will descend at most 3 levels of directories below the starting point.
|
||||
* $finder->depth(['>= 1', '< 3'])
|
||||
*
|
||||
* @param string|int|string[]|int[] $levels The depth level expression or an array of depth levels
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see DepthRangeFilterIterator
|
||||
* @see NumberComparator
|
||||
*/
|
||||
public function depth($levels)
|
||||
{
|
||||
foreach ((array) $levels as $level) {
|
||||
$this->depths[] = new Comparator\NumberComparator($level);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Adds tests for file dates (last modified).
|
||||
*
|
||||
* The date must be something that strtotime() is able to parse:
|
||||
*
|
||||
* $finder->date('since yesterday');
|
||||
* $finder->date('until 2 days ago');
|
||||
* $finder->date('> now - 2 hours');
|
||||
* $finder->date('>= 2005-10-15');
|
||||
* $finder->date(['>= 2005-10-15', '<= 2006-05-27']);
|
||||
*
|
||||
* @param string|string[] $dates A date range string or an array of date ranges
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see strtotime
|
||||
* @see DateRangeFilterIterator
|
||||
* @see DateComparator
|
||||
*/
|
||||
public function date($dates)
|
||||
{
|
||||
foreach ((array) $dates as $date) {
|
||||
$this->dates[] = new Comparator\DateComparator($date);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Adds rules that files must match.
|
||||
*
|
||||
* You can use patterns (delimited with / sign), globs or simple strings.
|
||||
*
|
||||
* $finder->name('/\.php$/')
|
||||
* $finder->name('*.php') // same as above, without dot files
|
||||
* $finder->name('test.php')
|
||||
* $finder->name(['test.py', 'test.php'])
|
||||
*
|
||||
* @param string|string[] $patterns A pattern (a regexp, a glob, or a string) or an array of patterns
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see FilenameFilterIterator
|
||||
*/
|
||||
public function name($patterns)
|
||||
{
|
||||
$this->names = array_merge($this->names, (array) $patterns);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Adds rules that files must not match.
|
||||
*
|
||||
* @param string|string[] $patterns A pattern (a regexp, a glob, or a string) or an array of patterns
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see FilenameFilterIterator
|
||||
*/
|
||||
public function notName($patterns)
|
||||
{
|
||||
$this->notNames = array_merge($this->notNames, (array) $patterns);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Adds tests that file contents must match.
|
||||
*
|
||||
* Strings or PCRE patterns can be used:
|
||||
*
|
||||
* $finder->contains('Lorem ipsum')
|
||||
* $finder->contains('/Lorem ipsum/i')
|
||||
* $finder->contains(['dolor', '/ipsum/i'])
|
||||
*
|
||||
* @param string|string[] $patterns A pattern (string or regexp) or an array of patterns
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see FilecontentFilterIterator
|
||||
*/
|
||||
public function contains($patterns)
|
||||
{
|
||||
$this->contains = array_merge($this->contains, (array) $patterns);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Adds tests that file contents must not match.
|
||||
*
|
||||
* Strings or PCRE patterns can be used:
|
||||
*
|
||||
* $finder->notContains('Lorem ipsum')
|
||||
* $finder->notContains('/Lorem ipsum/i')
|
||||
* $finder->notContains(['lorem', '/dolor/i'])
|
||||
*
|
||||
* @param string|string[] $patterns A pattern (string or regexp) or an array of patterns
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see FilecontentFilterIterator
|
||||
*/
|
||||
public function notContains($patterns)
|
||||
{
|
||||
$this->notContains = array_merge($this->notContains, (array) $patterns);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Adds rules that filenames must match.
|
||||
*
|
||||
* You can use patterns (delimited with / sign) or simple strings.
|
||||
*
|
||||
* $finder->path('some/special/dir')
|
||||
* $finder->path('/some\/special\/dir/') // same as above
|
||||
* $finder->path(['some dir', 'another/dir'])
|
||||
*
|
||||
* Use only / as dirname separator.
|
||||
*
|
||||
* @param string|string[] $patterns A pattern (a regexp or a string) or an array of patterns
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see FilenameFilterIterator
|
||||
*/
|
||||
public function path($patterns)
|
||||
{
|
||||
$this->paths = array_merge($this->paths, (array) $patterns);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Adds rules that filenames must not match.
|
||||
*
|
||||
* You can use patterns (delimited with / sign) or simple strings.
|
||||
*
|
||||
* $finder->notPath('some/special/dir')
|
||||
* $finder->notPath('/some\/special\/dir/') // same as above
|
||||
* $finder->notPath(['some/file.txt', 'another/file.log'])
|
||||
*
|
||||
* Use only / as dirname separator.
|
||||
*
|
||||
* @param string|string[] $patterns A pattern (a regexp or a string) or an array of patterns
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see FilenameFilterIterator
|
||||
*/
|
||||
public function notPath($patterns)
|
||||
{
|
||||
$this->notPaths = array_merge($this->notPaths, (array) $patterns);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Adds tests for file sizes.
|
||||
*
|
||||
* $finder->size('> 10K');
|
||||
* $finder->size('<= 1Ki');
|
||||
* $finder->size(4);
|
||||
* $finder->size(['> 10K', '< 20K'])
|
||||
*
|
||||
* @param string|int|string[]|int[] $sizes A size range string or an integer or an array of size ranges
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see SizeRangeFilterIterator
|
||||
* @see NumberComparator
|
||||
*/
|
||||
public function size($sizes)
|
||||
{
|
||||
foreach ((array) $sizes as $size) {
|
||||
$this->sizes[] = new Comparator\NumberComparator($size);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Excludes directories.
|
||||
*
|
||||
* Directories passed as argument must be relative to the ones defined with the `in()` method. For example:
|
||||
*
|
||||
* $finder->in(__DIR__)->exclude('ruby');
|
||||
*
|
||||
* @param string|array $dirs A directory path or an array of directories
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see ExcludeDirectoryFilterIterator
|
||||
*/
|
||||
public function exclude($dirs)
|
||||
{
|
||||
$this->exclude = array_merge($this->exclude, (array) $dirs);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Excludes "hidden" directories and files (starting with a dot).
|
||||
*
|
||||
* This option is enabled by default.
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see ExcludeDirectoryFilterIterator
|
||||
*/
|
||||
public function ignoreDotFiles(bool $ignoreDotFiles)
|
||||
{
|
||||
if ($ignoreDotFiles) {
|
||||
$this->ignore |= static::IGNORE_DOT_FILES;
|
||||
} else {
|
||||
$this->ignore &= ~static::IGNORE_DOT_FILES;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Forces the finder to ignore version control directories.
|
||||
*
|
||||
* This option is enabled by default.
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see ExcludeDirectoryFilterIterator
|
||||
*/
|
||||
public function ignoreVCS(bool $ignoreVCS)
|
||||
{
|
||||
if ($ignoreVCS) {
|
||||
$this->ignore |= static::IGNORE_VCS_FILES;
|
||||
} else {
|
||||
$this->ignore &= ~static::IGNORE_VCS_FILES;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Forces Finder to obey .gitignore and ignore files based on rules listed there.
|
||||
*
|
||||
* This option is disabled by default.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function ignoreVCSIgnored(bool $ignoreVCSIgnored)
|
||||
{
|
||||
if ($ignoreVCSIgnored) {
|
||||
$this->ignore |= static::IGNORE_VCS_IGNORED_FILES;
|
||||
} else {
|
||||
$this->ignore &= ~static::IGNORE_VCS_IGNORED_FILES;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Adds VCS patterns.
|
||||
*
|
||||
* @see ignoreVCS()
|
||||
*
|
||||
* @param string|string[] $pattern VCS patterns to ignore
|
||||
*/
|
||||
public static function addVCSPattern($pattern)
|
||||
{
|
||||
foreach ((array) $pattern as $p) {
|
||||
self::$vcsPatterns[] = $p;
|
||||
}
|
||||
self::$vcsPatterns = array_unique(self::$vcsPatterns);
|
||||
}
|
||||
/**
|
||||
* Sorts files and directories by an anonymous function.
|
||||
*
|
||||
* The anonymous function receives two \SplFileInfo instances to compare.
|
||||
*
|
||||
* This can be slow as all the matching files and directories must be retrieved for comparison.
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see SortableIterator
|
||||
*/
|
||||
public function sort(\Closure $closure)
|
||||
{
|
||||
$this->sort = $closure;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Sorts files and directories by name.
|
||||
*
|
||||
* This can be slow as all the matching files and directories must be retrieved for comparison.
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see SortableIterator
|
||||
*/
|
||||
public function sortByName(bool $useNaturalSort = \false)
|
||||
{
|
||||
$this->sort = $useNaturalSort ? Iterator\SortableIterator::SORT_BY_NAME_NATURAL : Iterator\SortableIterator::SORT_BY_NAME;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Sorts files and directories by type (directories before files), then by name.
|
||||
*
|
||||
* This can be slow as all the matching files and directories must be retrieved for comparison.
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see SortableIterator
|
||||
*/
|
||||
public function sortByType()
|
||||
{
|
||||
$this->sort = Iterator\SortableIterator::SORT_BY_TYPE;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Sorts files and directories by the last accessed time.
|
||||
*
|
||||
* This is the time that the file was last accessed, read or written to.
|
||||
*
|
||||
* This can be slow as all the matching files and directories must be retrieved for comparison.
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see SortableIterator
|
||||
*/
|
||||
public function sortByAccessedTime()
|
||||
{
|
||||
$this->sort = Iterator\SortableIterator::SORT_BY_ACCESSED_TIME;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Reverses the sorting.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function reverseSorting()
|
||||
{
|
||||
$this->reverseSorting = \true;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Sorts files and directories by the last inode changed time.
|
||||
*
|
||||
* This is the time that the inode information was last modified (permissions, owner, group or other metadata).
|
||||
*
|
||||
* On Windows, since inode is not available, changed time is actually the file creation time.
|
||||
*
|
||||
* This can be slow as all the matching files and directories must be retrieved for comparison.
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see SortableIterator
|
||||
*/
|
||||
public function sortByChangedTime()
|
||||
{
|
||||
$this->sort = Iterator\SortableIterator::SORT_BY_CHANGED_TIME;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Sorts files and directories by the last modified time.
|
||||
*
|
||||
* This is the last time the actual contents of the file were last modified.
|
||||
*
|
||||
* This can be slow as all the matching files and directories must be retrieved for comparison.
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see SortableIterator
|
||||
*/
|
||||
public function sortByModifiedTime()
|
||||
{
|
||||
$this->sort = Iterator\SortableIterator::SORT_BY_MODIFIED_TIME;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Filters the iterator with an anonymous function.
|
||||
*
|
||||
* The anonymous function receives a \SplFileInfo and must return false
|
||||
* to remove files.
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see CustomFilterIterator
|
||||
*/
|
||||
public function filter(\Closure $closure)
|
||||
{
|
||||
$this->filters[] = $closure;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Forces the following of symlinks.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function followLinks()
|
||||
{
|
||||
$this->followLinks = \true;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Tells finder to ignore unreadable directories.
|
||||
*
|
||||
* By default, scanning unreadable directories content throws an AccessDeniedException.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function ignoreUnreadableDirs(bool $ignore = \true)
|
||||
{
|
||||
$this->ignoreUnreadableDirs = $ignore;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Searches files and directories which match defined rules.
|
||||
*
|
||||
* @param string|string[] $dirs A directory path or an array of directories
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws DirectoryNotFoundException if one of the directories does not exist
|
||||
*/
|
||||
public function in($dirs)
|
||||
{
|
||||
$resolvedDirs = [];
|
||||
foreach ((array) $dirs as $dir) {
|
||||
if (is_dir($dir)) {
|
||||
$resolvedDirs[] = [$this->normalizeDir($dir)];
|
||||
} elseif ($glob = glob($dir, (\defined('GLOB_BRACE') ? \GLOB_BRACE : 0) | \GLOB_ONLYDIR | \GLOB_NOSORT)) {
|
||||
sort($glob);
|
||||
$resolvedDirs[] = array_map([$this, 'normalizeDir'], $glob);
|
||||
} else {
|
||||
throw new DirectoryNotFoundException(sprintf('The "%s" directory does not exist.', $dir));
|
||||
}
|
||||
}
|
||||
$this->dirs = array_merge($this->dirs, ...$resolvedDirs);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Returns an Iterator for the current Finder configuration.
|
||||
*
|
||||
* This method implements the IteratorAggregate interface.
|
||||
*
|
||||
* @return \Iterator<string, SplFileInfo>
|
||||
*
|
||||
* @throws \LogicException if the in() method has not been called
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
if (0 === \count($this->dirs) && 0 === \count($this->iterators)) {
|
||||
throw new \LogicException('You must call one of in() or append() methods before iterating over a Finder.');
|
||||
}
|
||||
if (1 === \count($this->dirs) && 0 === \count($this->iterators)) {
|
||||
$iterator = $this->searchInDirectory($this->dirs[0]);
|
||||
if ($this->sort || $this->reverseSorting) {
|
||||
$iterator = (new Iterator\SortableIterator($iterator, $this->sort, $this->reverseSorting))->getIterator();
|
||||
}
|
||||
return $iterator;
|
||||
}
|
||||
$iterator = new \AppendIterator();
|
||||
foreach ($this->dirs as $dir) {
|
||||
$iterator->append(new \IteratorIterator(new LazyIterator(function () use ($dir) {
|
||||
return $this->searchInDirectory($dir);
|
||||
})));
|
||||
}
|
||||
foreach ($this->iterators as $it) {
|
||||
$iterator->append($it);
|
||||
}
|
||||
if ($this->sort || $this->reverseSorting) {
|
||||
$iterator = (new Iterator\SortableIterator($iterator, $this->sort, $this->reverseSorting))->getIterator();
|
||||
}
|
||||
return $iterator;
|
||||
}
|
||||
/**
|
||||
* Appends an existing set of files/directories to the finder.
|
||||
*
|
||||
* The set can be another Finder, an Iterator, an IteratorAggregate, or even a plain array.
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws \InvalidArgumentException when the given argument is not iterable
|
||||
*/
|
||||
public function append(iterable $iterator)
|
||||
{
|
||||
if ($iterator instanceof \IteratorAggregate) {
|
||||
$this->iterators[] = $iterator->getIterator();
|
||||
} elseif ($iterator instanceof \Iterator) {
|
||||
$this->iterators[] = $iterator;
|
||||
} elseif (is_iterable($iterator)) {
|
||||
$it = new \ArrayIterator();
|
||||
foreach ($iterator as $file) {
|
||||
$file = $file instanceof \SplFileInfo ? $file : new \SplFileInfo($file);
|
||||
$it[$file->getPathname()] = $file;
|
||||
}
|
||||
$this->iterators[] = $it;
|
||||
} else {
|
||||
throw new \InvalidArgumentException('Finder::append() method wrong argument type.');
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Check if any results were found.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasResults()
|
||||
{
|
||||
foreach ($this->getIterator() as $_) {
|
||||
return \true;
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
/**
|
||||
* Counts all the results collected by the iterators.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function count()
|
||||
{
|
||||
return iterator_count($this->getIterator());
|
||||
}
|
||||
private function searchInDirectory(string $dir): \Iterator
|
||||
{
|
||||
$exclude = $this->exclude;
|
||||
$notPaths = $this->notPaths;
|
||||
if (static::IGNORE_VCS_FILES === (static::IGNORE_VCS_FILES & $this->ignore)) {
|
||||
$exclude = array_merge($exclude, self::$vcsPatterns);
|
||||
}
|
||||
if (static::IGNORE_DOT_FILES === (static::IGNORE_DOT_FILES & $this->ignore)) {
|
||||
$notPaths[] = '#(^|/)\..+(/|$)#';
|
||||
}
|
||||
$minDepth = 0;
|
||||
$maxDepth = \PHP_INT_MAX;
|
||||
foreach ($this->depths as $comparator) {
|
||||
switch ($comparator->getOperator()) {
|
||||
case '>':
|
||||
$minDepth = $comparator->getTarget() + 1;
|
||||
break;
|
||||
case '>=':
|
||||
$minDepth = $comparator->getTarget();
|
||||
break;
|
||||
case '<':
|
||||
$maxDepth = $comparator->getTarget() - 1;
|
||||
break;
|
||||
case '<=':
|
||||
$maxDepth = $comparator->getTarget();
|
||||
break;
|
||||
default:
|
||||
$minDepth = $maxDepth = $comparator->getTarget();
|
||||
}
|
||||
}
|
||||
$flags = \RecursiveDirectoryIterator::SKIP_DOTS;
|
||||
if ($this->followLinks) {
|
||||
$flags |= \RecursiveDirectoryIterator::FOLLOW_SYMLINKS;
|
||||
}
|
||||
$iterator = new Iterator\RecursiveDirectoryIterator($dir, $flags, $this->ignoreUnreadableDirs);
|
||||
if ($exclude) {
|
||||
$iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $exclude);
|
||||
}
|
||||
$iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
|
||||
if ($minDepth > 0 || $maxDepth < \PHP_INT_MAX) {
|
||||
$iterator = new Iterator\DepthRangeFilterIterator($iterator, $minDepth, $maxDepth);
|
||||
}
|
||||
if ($this->mode) {
|
||||
$iterator = new Iterator\FileTypeFilterIterator($iterator, $this->mode);
|
||||
}
|
||||
if ($this->names || $this->notNames) {
|
||||
$iterator = new Iterator\FilenameFilterIterator($iterator, $this->names, $this->notNames);
|
||||
}
|
||||
if ($this->contains || $this->notContains) {
|
||||
$iterator = new Iterator\FilecontentFilterIterator($iterator, $this->contains, $this->notContains);
|
||||
}
|
||||
if ($this->sizes) {
|
||||
$iterator = new Iterator\SizeRangeFilterIterator($iterator, $this->sizes);
|
||||
}
|
||||
if ($this->dates) {
|
||||
$iterator = new Iterator\DateRangeFilterIterator($iterator, $this->dates);
|
||||
}
|
||||
if ($this->filters) {
|
||||
$iterator = new Iterator\CustomFilterIterator($iterator, $this->filters);
|
||||
}
|
||||
if ($this->paths || $notPaths) {
|
||||
$iterator = new Iterator\PathFilterIterator($iterator, $this->paths, $notPaths);
|
||||
}
|
||||
if (static::IGNORE_VCS_IGNORED_FILES === (static::IGNORE_VCS_IGNORED_FILES & $this->ignore)) {
|
||||
$iterator = new Iterator\VcsIgnoredFilterIterator($iterator, $dir);
|
||||
}
|
||||
return $iterator;
|
||||
}
|
||||
/**
|
||||
* Normalizes given directory names by removing trailing slashes.
|
||||
*
|
||||
* Excluding: (s)ftp:// or ssh2.(s)ftp:// wrapper
|
||||
*/
|
||||
private function normalizeDir(string $dir): string
|
||||
{
|
||||
if ('/' === $dir) {
|
||||
return $dir;
|
||||
}
|
||||
$dir = rtrim($dir, '/' . \DIRECTORY_SEPARATOR);
|
||||
if (preg_match('#^(ssh2\.)?s?ftp://#', $dir)) {
|
||||
$dir .= '/';
|
||||
}
|
||||
return $dir;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder;
|
||||
|
||||
/**
|
||||
* Gitignore matches against text.
|
||||
*
|
||||
* @author Michael Voříšek <vorismi3@fel.cvut.cz>
|
||||
* @author Ahmed Abdou <mail@ahmd.io>
|
||||
*/
|
||||
class Gitignore
|
||||
{
|
||||
/**
|
||||
* Returns a regexp which is the equivalent of the gitignore pattern.
|
||||
*
|
||||
* Format specification: https://git-scm.com/docs/gitignore#_pattern_format
|
||||
*/
|
||||
public static function toRegex(string $gitignoreFileContent): string
|
||||
{
|
||||
return self::buildRegex($gitignoreFileContent, \false);
|
||||
}
|
||||
public static function toRegexMatchingNegatedPatterns(string $gitignoreFileContent): string
|
||||
{
|
||||
return self::buildRegex($gitignoreFileContent, \true);
|
||||
}
|
||||
private static function buildRegex(string $gitignoreFileContent, bool $inverted): string
|
||||
{
|
||||
$gitignoreFileContent = preg_replace('~(?<!\\\\)#[^\n\r]*~', '', $gitignoreFileContent);
|
||||
$gitignoreLines = preg_split('~\r\n?|\n~', $gitignoreFileContent);
|
||||
$res = self::lineToRegex('');
|
||||
foreach ($gitignoreLines as $line) {
|
||||
$line = preg_replace('~(?<!\\\\)[ \t]+$~', '', $line);
|
||||
if ('!' === substr($line, 0, 1)) {
|
||||
$line = substr($line, 1);
|
||||
$isNegative = \true;
|
||||
} else {
|
||||
$isNegative = \false;
|
||||
}
|
||||
if ('' !== $line) {
|
||||
if ($isNegative xor $inverted) {
|
||||
$res = '(?!' . self::lineToRegex($line) . '$)' . $res;
|
||||
} else {
|
||||
$res = '(?:' . $res . '|' . self::lineToRegex($line) . ')';
|
||||
}
|
||||
}
|
||||
}
|
||||
return '~^(?:' . $res . ')~s';
|
||||
}
|
||||
private static function lineToRegex(string $gitignoreLine): string
|
||||
{
|
||||
if ('' === $gitignoreLine) {
|
||||
return '$f';
|
||||
// always false
|
||||
}
|
||||
$slashPos = strpos($gitignoreLine, '/');
|
||||
if (\false !== $slashPos && \strlen($gitignoreLine) - 1 !== $slashPos) {
|
||||
if (0 === $slashPos) {
|
||||
$gitignoreLine = substr($gitignoreLine, 1);
|
||||
}
|
||||
$isAbsolute = \true;
|
||||
} else {
|
||||
$isAbsolute = \false;
|
||||
}
|
||||
$regex = preg_quote(str_replace('\\', '', $gitignoreLine), '~');
|
||||
$regex = preg_replace_callback('~\\\\\\[((?:\\\\!)?)([^\[\]]*)\\\\\\]~', function (array $matches): string {
|
||||
return '[' . ('' !== $matches[1] ? '^' : '') . str_replace('\-', '-', $matches[2]) . ']';
|
||||
}, $regex);
|
||||
$regex = preg_replace('~(?:(?:\\\\\\*){2,}(/?))+~', '(?:(?:(?!//).(?<!//))+$1)?', $regex);
|
||||
$regex = preg_replace('~\\\\\\*~', '[^/]*', $regex);
|
||||
$regex = preg_replace('~\\\\\\?~', '[^/]', $regex);
|
||||
return ($isAbsolute ? '' : '(?:[^/]+/)*') . $regex . (!str_ends_with($gitignoreLine, '/') ? '(?:$|/)' : '');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder;
|
||||
|
||||
/**
|
||||
* Glob matches globbing patterns against text.
|
||||
*
|
||||
* if match_glob("foo.*", "foo.bar") echo "matched\n";
|
||||
*
|
||||
* // prints foo.bar and foo.baz
|
||||
* $regex = glob_to_regex("foo.*");
|
||||
* for (['foo.bar', 'foo.baz', 'foo', 'bar'] as $t)
|
||||
* {
|
||||
* if (/$regex/) echo "matched: $car\n";
|
||||
* }
|
||||
*
|
||||
* Glob implements glob(3) style matching that can be used to match
|
||||
* against text, rather than fetching names from a filesystem.
|
||||
*
|
||||
* Based on the Perl Text::Glob module.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com> PHP port
|
||||
* @author Richard Clamp <richardc@unixbeard.net> Perl version
|
||||
* @copyright 2004-2005 Fabien Potencier <fabien@symfony.com>
|
||||
* @copyright 2002 Richard Clamp <richardc@unixbeard.net>
|
||||
*/
|
||||
class Glob
|
||||
{
|
||||
/**
|
||||
* Returns a regexp which is the equivalent of the glob pattern.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function toRegex(string $glob, bool $strictLeadingDot = \true, bool $strictWildcardSlash = \true, string $delimiter = '#')
|
||||
{
|
||||
$firstByte = \true;
|
||||
$escaping = \false;
|
||||
$inCurlies = 0;
|
||||
$regex = '';
|
||||
$sizeGlob = \strlen($glob);
|
||||
for ($i = 0; $i < $sizeGlob; ++$i) {
|
||||
$car = $glob[$i];
|
||||
if ($firstByte && $strictLeadingDot && '.' !== $car) {
|
||||
$regex .= '(?=[^\.])';
|
||||
}
|
||||
$firstByte = '/' === $car;
|
||||
if ($firstByte && $strictWildcardSlash && isset($glob[$i + 2]) && '**' === $glob[$i + 1] . $glob[$i + 2] && (!isset($glob[$i + 3]) || '/' === $glob[$i + 3])) {
|
||||
$car = '[^/]++/';
|
||||
if (!isset($glob[$i + 3])) {
|
||||
$car .= '?';
|
||||
}
|
||||
if ($strictLeadingDot) {
|
||||
$car = '(?=[^\.])' . $car;
|
||||
}
|
||||
$car = '/(?:' . $car . ')*';
|
||||
$i += 2 + isset($glob[$i + 3]);
|
||||
if ('/' === $delimiter) {
|
||||
$car = str_replace('/', '\/', $car);
|
||||
}
|
||||
}
|
||||
if ($delimiter === $car || '.' === $car || '(' === $car || ')' === $car || '|' === $car || '+' === $car || '^' === $car || '$' === $car) {
|
||||
$regex .= "\\{$car}";
|
||||
} elseif ('*' === $car) {
|
||||
$regex .= $escaping ? '\*' : ($strictWildcardSlash ? '[^/]*' : '.*');
|
||||
} elseif ('?' === $car) {
|
||||
$regex .= $escaping ? '\?' : ($strictWildcardSlash ? '[^/]' : '.');
|
||||
} elseif ('{' === $car) {
|
||||
$regex .= $escaping ? '\{' : '(';
|
||||
if (!$escaping) {
|
||||
++$inCurlies;
|
||||
}
|
||||
} elseif ('}' === $car && $inCurlies) {
|
||||
$regex .= $escaping ? '}' : ')';
|
||||
if (!$escaping) {
|
||||
--$inCurlies;
|
||||
}
|
||||
} elseif (',' === $car && $inCurlies) {
|
||||
$regex .= $escaping ? ',' : '|';
|
||||
} elseif ('\\' === $car) {
|
||||
if ($escaping) {
|
||||
$regex .= '\\\\';
|
||||
$escaping = \false;
|
||||
} else {
|
||||
$escaping = \true;
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
$regex .= $car;
|
||||
}
|
||||
$escaping = \false;
|
||||
}
|
||||
return $delimiter . '^' . $regex . '$' . $delimiter;
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder\Iterator;
|
||||
|
||||
/**
|
||||
* CustomFilterIterator filters files by applying anonymous functions.
|
||||
*
|
||||
* The anonymous function receives a \SplFileInfo and must return false
|
||||
* to remove files.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @extends \FilterIterator<string, \SplFileInfo>
|
||||
*/
|
||||
class CustomFilterIterator extends \FilterIterator
|
||||
{
|
||||
private $filters = [];
|
||||
/**
|
||||
* @param \Iterator<string, \SplFileInfo> $iterator The Iterator to filter
|
||||
* @param callable[] $filters An array of PHP callbacks
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct(\Iterator $iterator, array $filters)
|
||||
{
|
||||
foreach ($filters as $filter) {
|
||||
if (!\is_callable($filter)) {
|
||||
throw new \InvalidArgumentException('Invalid PHP callback.');
|
||||
}
|
||||
}
|
||||
$this->filters = $filters;
|
||||
parent::__construct($iterator);
|
||||
}
|
||||
/**
|
||||
* Filters the iterator values.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function accept()
|
||||
{
|
||||
$fileinfo = $this->current();
|
||||
foreach ($this->filters as $filter) {
|
||||
if (\false === $filter($fileinfo)) {
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder\Iterator;
|
||||
|
||||
use JooosiFonDeps\Symfony\Component\Finder\Comparator\DateComparator;
|
||||
/**
|
||||
* DateRangeFilterIterator filters out files that are not in the given date range (last modified dates).
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @extends \FilterIterator<string, \SplFileInfo>
|
||||
*/
|
||||
class DateRangeFilterIterator extends \FilterIterator
|
||||
{
|
||||
private $comparators = [];
|
||||
/**
|
||||
* @param \Iterator<string, \SplFileInfo> $iterator
|
||||
* @param DateComparator[] $comparators
|
||||
*/
|
||||
public function __construct(\Iterator $iterator, array $comparators)
|
||||
{
|
||||
$this->comparators = $comparators;
|
||||
parent::__construct($iterator);
|
||||
}
|
||||
/**
|
||||
* Filters the iterator values.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function accept()
|
||||
{
|
||||
$fileinfo = $this->current();
|
||||
if (!file_exists($fileinfo->getPathname())) {
|
||||
return \false;
|
||||
}
|
||||
$filedate = $fileinfo->getMTime();
|
||||
foreach ($this->comparators as $compare) {
|
||||
if (!$compare->test($filedate)) {
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
Vendored
+47
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder\Iterator;
|
||||
|
||||
/**
|
||||
* DepthRangeFilterIterator limits the directory depth.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @template-covariant TKey
|
||||
* @template-covariant TValue
|
||||
*
|
||||
* @extends \FilterIterator<TKey, TValue>
|
||||
*/
|
||||
class DepthRangeFilterIterator extends \FilterIterator
|
||||
{
|
||||
private $minDepth = 0;
|
||||
/**
|
||||
* @param \RecursiveIteratorIterator<\RecursiveIterator<TKey, TValue>> $iterator The Iterator to filter
|
||||
* @param int $minDepth The min depth
|
||||
* @param int $maxDepth The max depth
|
||||
*/
|
||||
public function __construct(\RecursiveIteratorIterator $iterator, int $minDepth = 0, int $maxDepth = \PHP_INT_MAX)
|
||||
{
|
||||
$this->minDepth = $minDepth;
|
||||
$iterator->setMaxDepth(\PHP_INT_MAX === $maxDepth ? -1 : $maxDepth);
|
||||
parent::__construct($iterator);
|
||||
}
|
||||
/**
|
||||
* Filters the iterator values.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function accept()
|
||||
{
|
||||
return $this->getInnerIterator()->getDepth() >= $this->minDepth;
|
||||
}
|
||||
}
|
||||
Vendored
+87
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder\Iterator;
|
||||
|
||||
/**
|
||||
* ExcludeDirectoryFilterIterator filters out directories.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @extends \FilterIterator<string, \SplFileInfo>
|
||||
*
|
||||
* @implements \RecursiveIterator<string, \SplFileInfo>
|
||||
*/
|
||||
class ExcludeDirectoryFilterIterator extends \FilterIterator implements \RecursiveIterator
|
||||
{
|
||||
private $iterator;
|
||||
private $isRecursive;
|
||||
private $excludedDirs = [];
|
||||
private $excludedPattern;
|
||||
/**
|
||||
* @param \Iterator $iterator The Iterator to filter
|
||||
* @param string[] $directories An array of directories to exclude
|
||||
*/
|
||||
public function __construct(\Iterator $iterator, array $directories)
|
||||
{
|
||||
$this->iterator = $iterator;
|
||||
$this->isRecursive = $iterator instanceof \RecursiveIterator;
|
||||
$patterns = [];
|
||||
foreach ($directories as $directory) {
|
||||
$directory = rtrim($directory, '/');
|
||||
if (!$this->isRecursive || str_contains($directory, '/')) {
|
||||
$patterns[] = preg_quote($directory, '#');
|
||||
} else {
|
||||
$this->excludedDirs[$directory] = \true;
|
||||
}
|
||||
}
|
||||
if ($patterns) {
|
||||
$this->excludedPattern = '#(?:^|/)(?:' . implode('|', $patterns) . ')(?:/|$)#';
|
||||
}
|
||||
parent::__construct($iterator);
|
||||
}
|
||||
/**
|
||||
* Filters the iterator values.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function accept()
|
||||
{
|
||||
if ($this->isRecursive && isset($this->excludedDirs[$this->getFilename()]) && $this->isDir()) {
|
||||
return \false;
|
||||
}
|
||||
if ($this->excludedPattern) {
|
||||
$path = $this->isDir() ? $this->current()->getRelativePathname() : $this->current()->getRelativePath();
|
||||
$path = str_replace('\\', '/', $path);
|
||||
return !preg_match($this->excludedPattern, $path);
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function hasChildren()
|
||||
{
|
||||
return $this->isRecursive && $this->iterator->hasChildren();
|
||||
}
|
||||
/**
|
||||
* @return self
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getChildren()
|
||||
{
|
||||
$children = new self($this->iterator->getChildren(), []);
|
||||
$children->excludedDirs = $this->excludedDirs;
|
||||
$children->excludedPattern = $this->excludedPattern;
|
||||
return $children;
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder\Iterator;
|
||||
|
||||
/**
|
||||
* FileTypeFilterIterator only keeps files, directories, or both.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @extends \FilterIterator<string, \SplFileInfo>
|
||||
*/
|
||||
class FileTypeFilterIterator extends \FilterIterator
|
||||
{
|
||||
public const ONLY_FILES = 1;
|
||||
public const ONLY_DIRECTORIES = 2;
|
||||
private $mode;
|
||||
/**
|
||||
* @param \Iterator $iterator The Iterator to filter
|
||||
* @param int $mode The mode (self::ONLY_FILES or self::ONLY_DIRECTORIES)
|
||||
*/
|
||||
public function __construct(\Iterator $iterator, int $mode)
|
||||
{
|
||||
$this->mode = $mode;
|
||||
parent::__construct($iterator);
|
||||
}
|
||||
/**
|
||||
* Filters the iterator values.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function accept()
|
||||
{
|
||||
$fileinfo = $this->current();
|
||||
if (self::ONLY_DIRECTORIES === (self::ONLY_DIRECTORIES & $this->mode) && $fileinfo->isFile()) {
|
||||
return \false;
|
||||
} elseif (self::ONLY_FILES === (self::ONLY_FILES & $this->mode) && $fileinfo->isDir()) {
|
||||
return \false;
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
Vendored
+55
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder\Iterator;
|
||||
|
||||
/**
|
||||
* FilecontentFilterIterator filters files by their contents using patterns (regexps or strings).
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Włodzimierz Gajda <gajdaw@gajdaw.pl>
|
||||
*
|
||||
* @extends MultiplePcreFilterIterator<string, \SplFileInfo>
|
||||
*/
|
||||
class FilecontentFilterIterator extends MultiplePcreFilterIterator
|
||||
{
|
||||
/**
|
||||
* Filters the iterator values.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function accept()
|
||||
{
|
||||
if (!$this->matchRegexps && !$this->noMatchRegexps) {
|
||||
return \true;
|
||||
}
|
||||
$fileinfo = $this->current();
|
||||
if ($fileinfo->isDir() || !$fileinfo->isReadable()) {
|
||||
return \false;
|
||||
}
|
||||
$content = $fileinfo->getContents();
|
||||
if (!$content) {
|
||||
return \false;
|
||||
}
|
||||
return $this->isAccepted($content);
|
||||
}
|
||||
/**
|
||||
* Converts string to regexp if necessary.
|
||||
*
|
||||
* @param string $str Pattern: string or regexp
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function toRegex(string $str)
|
||||
{
|
||||
return $this->isRegex($str) ? $str : '/' . preg_quote($str, '/') . '/';
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder\Iterator;
|
||||
|
||||
use JooosiFonDeps\Symfony\Component\Finder\Glob;
|
||||
/**
|
||||
* FilenameFilterIterator filters files by patterns (a regexp, a glob, or a string).
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @extends MultiplePcreFilterIterator<string, \SplFileInfo>
|
||||
*/
|
||||
class FilenameFilterIterator extends MultiplePcreFilterIterator
|
||||
{
|
||||
/**
|
||||
* Filters the iterator values.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function accept()
|
||||
{
|
||||
return $this->isAccepted($this->current()->getFilename());
|
||||
}
|
||||
/**
|
||||
* Converts glob to regexp.
|
||||
*
|
||||
* PCRE patterns are left unchanged.
|
||||
* Glob strings are transformed with Glob::toRegex().
|
||||
*
|
||||
* @param string $str Pattern: glob or regexp
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function toRegex(string $str)
|
||||
{
|
||||
return $this->isRegex($str) ? $str : Glob::toRegex($str);
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder\Iterator;
|
||||
|
||||
/**
|
||||
* @author Jérémy Derussé <jeremy@derusse.com>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class LazyIterator implements \IteratorAggregate
|
||||
{
|
||||
private $iteratorFactory;
|
||||
public function __construct(callable $iteratorFactory)
|
||||
{
|
||||
$this->iteratorFactory = $iteratorFactory;
|
||||
}
|
||||
public function getIterator(): \Traversable
|
||||
{
|
||||
yield from ($this->iteratorFactory)();
|
||||
}
|
||||
}
|
||||
Vendored
+102
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder\Iterator;
|
||||
|
||||
/**
|
||||
* MultiplePcreFilterIterator filters files using patterns (regexps, globs or strings).
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @template-covariant TKey
|
||||
* @template-covariant TValue
|
||||
*
|
||||
* @extends \FilterIterator<TKey, TValue>
|
||||
*/
|
||||
abstract class MultiplePcreFilterIterator extends \FilterIterator
|
||||
{
|
||||
protected $matchRegexps = [];
|
||||
protected $noMatchRegexps = [];
|
||||
/**
|
||||
* @param \Iterator $iterator The Iterator to filter
|
||||
* @param string[] $matchPatterns An array of patterns that need to match
|
||||
* @param string[] $noMatchPatterns An array of patterns that need to not match
|
||||
*/
|
||||
public function __construct(\Iterator $iterator, array $matchPatterns, array $noMatchPatterns)
|
||||
{
|
||||
foreach ($matchPatterns as $pattern) {
|
||||
$this->matchRegexps[] = $this->toRegex($pattern);
|
||||
}
|
||||
foreach ($noMatchPatterns as $pattern) {
|
||||
$this->noMatchRegexps[] = $this->toRegex($pattern);
|
||||
}
|
||||
parent::__construct($iterator);
|
||||
}
|
||||
/**
|
||||
* Checks whether the string is accepted by the regex filters.
|
||||
*
|
||||
* If there is no regexps defined in the class, this method will accept the string.
|
||||
* Such case can be handled by child classes before calling the method if they want to
|
||||
* apply a different behavior.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isAccepted(string $string)
|
||||
{
|
||||
// should at least not match one rule to exclude
|
||||
foreach ($this->noMatchRegexps as $regex) {
|
||||
if (preg_match($regex, $string)) {
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
// should at least match one rule
|
||||
if ($this->matchRegexps) {
|
||||
foreach ($this->matchRegexps as $regex) {
|
||||
if (preg_match($regex, $string)) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
// If there is no match rules, the file is accepted
|
||||
return \true;
|
||||
}
|
||||
/**
|
||||
* Checks whether the string is a regex.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isRegex(string $str)
|
||||
{
|
||||
$availableModifiers = 'imsxuADU';
|
||||
if (\PHP_VERSION_ID >= 80200) {
|
||||
$availableModifiers .= 'n';
|
||||
}
|
||||
if (preg_match('/^(.{3,}?)[' . $availableModifiers . ']*$/', $str, $m)) {
|
||||
$start = substr($m[1], 0, 1);
|
||||
$end = substr($m[1], -1);
|
||||
if ($start === $end) {
|
||||
return !preg_match('/[*?[:alnum:] \\\\]/', $start);
|
||||
}
|
||||
foreach ([['{', '}'], ['(', ')'], ['[', ']'], ['<', '>']] as $delimiters) {
|
||||
if ($start === $delimiters[0] && $end === $delimiters[1]) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
/**
|
||||
* Converts string into regexp.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function toRegex(string $str);
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder\Iterator;
|
||||
|
||||
/**
|
||||
* PathFilterIterator filters files by path patterns (e.g. some/special/dir).
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Włodzimierz Gajda <gajdaw@gajdaw.pl>
|
||||
*
|
||||
* @extends MultiplePcreFilterIterator<string, \SplFileInfo>
|
||||
*/
|
||||
class PathFilterIterator extends MultiplePcreFilterIterator
|
||||
{
|
||||
/**
|
||||
* Filters the iterator values.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function accept()
|
||||
{
|
||||
$filename = $this->current()->getRelativePathname();
|
||||
if ('\\' === \DIRECTORY_SEPARATOR) {
|
||||
$filename = str_replace('\\', '/', $filename);
|
||||
}
|
||||
return $this->isAccepted($filename);
|
||||
}
|
||||
/**
|
||||
* Converts strings to regexp.
|
||||
*
|
||||
* PCRE patterns are left unchanged.
|
||||
*
|
||||
* Default conversion:
|
||||
* 'lorem/ipsum/dolor' ==> 'lorem\/ipsum\/dolor/'
|
||||
*
|
||||
* Use only / as directory separator (on Windows also).
|
||||
*
|
||||
* @param string $str Pattern: regexp or dirname
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function toRegex(string $str)
|
||||
{
|
||||
return $this->isRegex($str) ? $str : '/' . preg_quote($str, '/') . '/';
|
||||
}
|
||||
}
|
||||
Vendored
+135
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder\Iterator;
|
||||
|
||||
use JooosiFonDeps\Symfony\Component\Finder\Exception\AccessDeniedException;
|
||||
use JooosiFonDeps\Symfony\Component\Finder\SplFileInfo;
|
||||
/**
|
||||
* Extends the \RecursiveDirectoryIterator to support relative paths.
|
||||
*
|
||||
* @author Victor Berchet <victor@suumit.com>
|
||||
*/
|
||||
class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $ignoreUnreadableDirs;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $ignoreFirstRewind = \true;
|
||||
// these 3 properties take part of the performance optimization to avoid redoing the same work in all iterations
|
||||
private $rootPath;
|
||||
private $subPath;
|
||||
private $directorySeparator = '/';
|
||||
/**
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function __construct(string $path, int $flags, bool $ignoreUnreadableDirs = \false)
|
||||
{
|
||||
if ($flags & (self::CURRENT_AS_PATHNAME | self::CURRENT_AS_SELF)) {
|
||||
throw new \RuntimeException('This iterator only support returning current as fileinfo.');
|
||||
}
|
||||
parent::__construct($path, $flags);
|
||||
$this->ignoreUnreadableDirs = $ignoreUnreadableDirs;
|
||||
$this->rootPath = $path;
|
||||
if ('/' !== \DIRECTORY_SEPARATOR && !($flags & self::UNIX_PATHS)) {
|
||||
$this->directorySeparator = \DIRECTORY_SEPARATOR;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Return an instance of SplFileInfo with support for relative paths.
|
||||
*
|
||||
* @return SplFileInfo
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function current()
|
||||
{
|
||||
// the logic here avoids redoing the same work in all iterations
|
||||
if (null === $subPathname = $this->subPath) {
|
||||
$subPathname = $this->subPath = $this->getSubPath();
|
||||
}
|
||||
if ('' !== $subPathname) {
|
||||
$subPathname .= $this->directorySeparator;
|
||||
}
|
||||
$subPathname .= $this->getFilename();
|
||||
$basePath = $this->rootPath;
|
||||
if ('/' !== $basePath && !str_ends_with($basePath, $this->directorySeparator) && !str_ends_with($basePath, '/')) {
|
||||
$basePath .= $this->directorySeparator;
|
||||
}
|
||||
return new SplFileInfo($basePath . $subPathname, $this->subPath, $subPathname);
|
||||
}
|
||||
/**
|
||||
* @param bool $allowLinks
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function hasChildren($allowLinks = \false)
|
||||
{
|
||||
$hasChildren = parent::hasChildren($allowLinks);
|
||||
if (!$hasChildren || !$this->ignoreUnreadableDirs) {
|
||||
return $hasChildren;
|
||||
}
|
||||
try {
|
||||
parent::getChildren();
|
||||
return \true;
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
// If directory is unreadable and finder is set to ignore it, skip children
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return \RecursiveDirectoryIterator
|
||||
*
|
||||
* @throws AccessDeniedException
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getChildren()
|
||||
{
|
||||
try {
|
||||
$children = parent::getChildren();
|
||||
if ($children instanceof self) {
|
||||
// parent method will call the constructor with default arguments, so unreadable dirs won't be ignored anymore
|
||||
$children->ignoreUnreadableDirs = $this->ignoreUnreadableDirs;
|
||||
// performance optimization to avoid redoing the same work in all children
|
||||
$children->rootPath = $this->rootPath;
|
||||
}
|
||||
return $children;
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function next()
|
||||
{
|
||||
$this->ignoreFirstRewind = \false;
|
||||
parent::next();
|
||||
}
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function rewind()
|
||||
{
|
||||
// some streams like FTP are not rewindable, ignore the first rewind after creation,
|
||||
// as newly created DirectoryIterator does not need to be rewound
|
||||
if ($this->ignoreFirstRewind) {
|
||||
$this->ignoreFirstRewind = \false;
|
||||
return;
|
||||
}
|
||||
parent::rewind();
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder\Iterator;
|
||||
|
||||
use JooosiFonDeps\Symfony\Component\Finder\Comparator\NumberComparator;
|
||||
/**
|
||||
* SizeRangeFilterIterator filters out files that are not in the given size range.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @extends \FilterIterator<string, \SplFileInfo>
|
||||
*/
|
||||
class SizeRangeFilterIterator extends \FilterIterator
|
||||
{
|
||||
private $comparators = [];
|
||||
/**
|
||||
* @param \Iterator<string, \SplFileInfo> $iterator
|
||||
* @param NumberComparator[] $comparators
|
||||
*/
|
||||
public function __construct(\Iterator $iterator, array $comparators)
|
||||
{
|
||||
$this->comparators = $comparators;
|
||||
parent::__construct($iterator);
|
||||
}
|
||||
/**
|
||||
* Filters the iterator values.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function accept()
|
||||
{
|
||||
$fileinfo = $this->current();
|
||||
if (!$fileinfo->isFile()) {
|
||||
return \true;
|
||||
}
|
||||
$filesize = $fileinfo->getSize();
|
||||
foreach ($this->comparators as $compare) {
|
||||
if (!$compare->test($filesize)) {
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder\Iterator;
|
||||
|
||||
/**
|
||||
* SortableIterator applies a sort on a given Iterator.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @implements \IteratorAggregate<string, \SplFileInfo>
|
||||
*/
|
||||
class SortableIterator implements \IteratorAggregate
|
||||
{
|
||||
public const SORT_BY_NONE = 0;
|
||||
public const SORT_BY_NAME = 1;
|
||||
public const SORT_BY_TYPE = 2;
|
||||
public const SORT_BY_ACCESSED_TIME = 3;
|
||||
public const SORT_BY_CHANGED_TIME = 4;
|
||||
public const SORT_BY_MODIFIED_TIME = 5;
|
||||
public const SORT_BY_NAME_NATURAL = 6;
|
||||
private $iterator;
|
||||
private $sort;
|
||||
/**
|
||||
* @param \Traversable<string, \SplFileInfo> $iterator
|
||||
* @param int|callable $sort The sort type (SORT_BY_NAME, SORT_BY_TYPE, or a PHP callback)
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct(\Traversable $iterator, $sort, bool $reverseOrder = \false)
|
||||
{
|
||||
$this->iterator = $iterator;
|
||||
$order = $reverseOrder ? -1 : 1;
|
||||
if (self::SORT_BY_NAME === $sort) {
|
||||
$this->sort = static function (\SplFileInfo $a, \SplFileInfo $b) use ($order) {
|
||||
return $order * strcmp($a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname());
|
||||
};
|
||||
} elseif (self::SORT_BY_NAME_NATURAL === $sort) {
|
||||
$this->sort = static function (\SplFileInfo $a, \SplFileInfo $b) use ($order) {
|
||||
return $order * strnatcmp($a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname());
|
||||
};
|
||||
} elseif (self::SORT_BY_TYPE === $sort) {
|
||||
$this->sort = static function (\SplFileInfo $a, \SplFileInfo $b) use ($order) {
|
||||
if ($a->isDir() && $b->isFile()) {
|
||||
return -$order;
|
||||
} elseif ($a->isFile() && $b->isDir()) {
|
||||
return $order;
|
||||
}
|
||||
return $order * strcmp($a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname());
|
||||
};
|
||||
} elseif (self::SORT_BY_ACCESSED_TIME === $sort) {
|
||||
$this->sort = static function (\SplFileInfo $a, \SplFileInfo $b) use ($order) {
|
||||
return $order * ($a->getATime() - $b->getATime());
|
||||
};
|
||||
} elseif (self::SORT_BY_CHANGED_TIME === $sort) {
|
||||
$this->sort = static function (\SplFileInfo $a, \SplFileInfo $b) use ($order) {
|
||||
return $order * ($a->getCTime() - $b->getCTime());
|
||||
};
|
||||
} elseif (self::SORT_BY_MODIFIED_TIME === $sort) {
|
||||
$this->sort = static function (\SplFileInfo $a, \SplFileInfo $b) use ($order) {
|
||||
return $order * ($a->getMTime() - $b->getMTime());
|
||||
};
|
||||
} elseif (self::SORT_BY_NONE === $sort) {
|
||||
$this->sort = $order;
|
||||
} elseif (\is_callable($sort)) {
|
||||
$this->sort = $reverseOrder ? static function (\SplFileInfo $a, \SplFileInfo $b) use ($sort) {
|
||||
return -$sort($a, $b);
|
||||
} : $sort;
|
||||
} else {
|
||||
throw new \InvalidArgumentException('The SortableIterator takes a PHP callable or a valid built-in sort algorithm as an argument.');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return \Traversable<string, \SplFileInfo>
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
if (1 === $this->sort) {
|
||||
return $this->iterator;
|
||||
}
|
||||
$array = iterator_to_array($this->iterator, \true);
|
||||
if (-1 === $this->sort) {
|
||||
$array = array_reverse($array);
|
||||
} else {
|
||||
uasort($array, $this->sort);
|
||||
}
|
||||
return new \ArrayIterator($array);
|
||||
}
|
||||
}
|
||||
Vendored
+113
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder\Iterator;
|
||||
|
||||
use JooosiFonDeps\Symfony\Component\Finder\Gitignore;
|
||||
final class VcsIgnoredFilterIterator extends \FilterIterator
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $baseDir;
|
||||
/**
|
||||
* @var array<string, array{0: string, 1: string}|null>
|
||||
*/
|
||||
private $gitignoreFilesCache = [];
|
||||
/**
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
private $ignoredPathsCache = [];
|
||||
public function __construct(\Iterator $iterator, string $baseDir)
|
||||
{
|
||||
$this->baseDir = $this->normalizePath($baseDir);
|
||||
parent::__construct($iterator);
|
||||
}
|
||||
public function accept(): bool
|
||||
{
|
||||
$file = $this->current();
|
||||
$fileRealPath = $this->normalizePath($file->getRealPath());
|
||||
return !$this->isIgnored($fileRealPath);
|
||||
}
|
||||
private function isIgnored(string $fileRealPath): bool
|
||||
{
|
||||
if (is_dir($fileRealPath) && !str_ends_with($fileRealPath, '/')) {
|
||||
$fileRealPath .= '/';
|
||||
}
|
||||
if (isset($this->ignoredPathsCache[$fileRealPath])) {
|
||||
return $this->ignoredPathsCache[$fileRealPath];
|
||||
}
|
||||
$ignored = \false;
|
||||
foreach ($this->parentsDirectoryDownward($fileRealPath) as $parentDirectory) {
|
||||
if ($this->isIgnored($parentDirectory)) {
|
||||
// rules in ignored directories are ignored, no need to check further.
|
||||
break;
|
||||
}
|
||||
$fileRelativePath = substr($fileRealPath, \strlen($parentDirectory) + 1);
|
||||
if (null === $regexps = $this->readGitignoreFile("{$parentDirectory}/.gitignore")) {
|
||||
continue;
|
||||
}
|
||||
[$exclusionRegex, $inclusionRegex] = $regexps;
|
||||
if (preg_match($exclusionRegex, $fileRelativePath)) {
|
||||
$ignored = \true;
|
||||
continue;
|
||||
}
|
||||
if (preg_match($inclusionRegex, $fileRelativePath)) {
|
||||
$ignored = \false;
|
||||
}
|
||||
}
|
||||
return $this->ignoredPathsCache[$fileRealPath] = $ignored;
|
||||
}
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
private function parentsDirectoryDownward(string $fileRealPath): array
|
||||
{
|
||||
$parentDirectories = [];
|
||||
$parentDirectory = $fileRealPath;
|
||||
while (\true) {
|
||||
$newParentDirectory = \dirname($parentDirectory);
|
||||
// dirname('/') = '/'
|
||||
if ($newParentDirectory === $parentDirectory) {
|
||||
break;
|
||||
}
|
||||
$parentDirectory = $newParentDirectory;
|
||||
if (0 !== strpos($parentDirectory, $this->baseDir)) {
|
||||
break;
|
||||
}
|
||||
$parentDirectories[] = $parentDirectory;
|
||||
}
|
||||
return array_reverse($parentDirectories);
|
||||
}
|
||||
/**
|
||||
* @return array{0: string, 1: string}|null
|
||||
*/
|
||||
private function readGitignoreFile(string $path): ?array
|
||||
{
|
||||
if (\array_key_exists($path, $this->gitignoreFilesCache)) {
|
||||
return $this->gitignoreFilesCache[$path];
|
||||
}
|
||||
if (!file_exists($path)) {
|
||||
return $this->gitignoreFilesCache[$path] = null;
|
||||
}
|
||||
if (!is_file($path) || !is_readable($path)) {
|
||||
throw new \RuntimeException("The \"ignoreVCSIgnored\" option cannot be used by the Finder as the \"{$path}\" file is not readable.");
|
||||
}
|
||||
$gitignoreFileContent = file_get_contents($path);
|
||||
return $this->gitignoreFilesCache[$path] = [Gitignore::toRegex($gitignoreFileContent), Gitignore::toRegexMatchingNegatedPatterns($gitignoreFileContent)];
|
||||
}
|
||||
private function normalizePath(string $path): string
|
||||
{
|
||||
if ('\\' === \DIRECTORY_SEPARATOR) {
|
||||
return str_replace('\\', '/', $path);
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2004-present Fabien Potencier
|
||||
|
||||
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:
|
||||
|
||||
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,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -0,0 +1,14 @@
|
||||
Finder Component
|
||||
================
|
||||
|
||||
The Finder component finds files and directories via an intuitive fluent
|
||||
interface.
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
||||
* [Documentation](https://symfony.com/doc/current/components/finder.html)
|
||||
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
|
||||
* [Report issues](https://github.com/symfony/symfony/issues) and
|
||||
[send Pull Requests](https://github.com/symfony/symfony/pulls)
|
||||
in the [main Symfony repository](https://github.com/symfony/symfony)
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\Finder;
|
||||
|
||||
/**
|
||||
* Extends \SplFileInfo to support relative paths.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class SplFileInfo extends \SplFileInfo
|
||||
{
|
||||
private $relativePath;
|
||||
private $relativePathname;
|
||||
/**
|
||||
* @param string $file The file name
|
||||
* @param string $relativePath The relative path
|
||||
* @param string $relativePathname The relative path name
|
||||
*/
|
||||
public function __construct(string $file, string $relativePath, string $relativePathname)
|
||||
{
|
||||
parent::__construct($file);
|
||||
$this->relativePath = $relativePath;
|
||||
$this->relativePathname = $relativePathname;
|
||||
}
|
||||
/**
|
||||
* Returns the relative path.
|
||||
*
|
||||
* This path does not contain the file name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRelativePath()
|
||||
{
|
||||
return $this->relativePath;
|
||||
}
|
||||
/**
|
||||
* Returns the relative path name.
|
||||
*
|
||||
* This path contains the file name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRelativePathname()
|
||||
{
|
||||
return $this->relativePathname;
|
||||
}
|
||||
public function getFilenameWithoutExtension(): string
|
||||
{
|
||||
$filename = $this->getFilename();
|
||||
return pathinfo($filename, \PATHINFO_FILENAME);
|
||||
}
|
||||
/**
|
||||
* Returns the contents of the file.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function getContents()
|
||||
{
|
||||
set_error_handler(function ($type, $msg) use (&$error) {
|
||||
$error = $msg;
|
||||
});
|
||||
try {
|
||||
$content = file_get_contents($this->getPathname());
|
||||
} finally {
|
||||
restore_error_handler();
|
||||
}
|
||||
if (\false === $content) {
|
||||
throw new \RuntimeException($error);
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "symfony\/finder",
|
||||
"type": "library",
|
||||
"description": "Finds files and directories via an intuitive fluent interface",
|
||||
"keywords": [],
|
||||
"homepage": "https:\/\/symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https:\/\/symfony.com\/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.2.5",
|
||||
"symfony\/deprecation-contracts": "^2.1|^3",
|
||||
"symfony\/polyfill-php80": "^1.16"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"JooosiFonDeps\\Symfony\\Component\\Finder\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"\/Tests\/"
|
||||
]
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Symfony\Polyfill\Ctype;
|
||||
|
||||
/**
|
||||
* Ctype implementation through regex.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @author Gert de Pagter <BackEndTea@gmail.com>
|
||||
*/
|
||||
final class Ctype
|
||||
{
|
||||
/**
|
||||
* Returns TRUE if every character in text is either a letter or a digit, FALSE otherwise.
|
||||
*
|
||||
* @see https://php.net/ctype-alnum
|
||||
*
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ctype_alnum($text)
|
||||
{
|
||||
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||
return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text);
|
||||
}
|
||||
/**
|
||||
* Returns TRUE if every character in text is a letter, FALSE otherwise.
|
||||
*
|
||||
* @see https://php.net/ctype-alpha
|
||||
*
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ctype_alpha($text)
|
||||
{
|
||||
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||
return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z]/', $text);
|
||||
}
|
||||
/**
|
||||
* Returns TRUE if every character in text is a control character from the current locale, FALSE otherwise.
|
||||
*
|
||||
* @see https://php.net/ctype-cntrl
|
||||
*
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ctype_cntrl($text)
|
||||
{
|
||||
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||
return \is_string($text) && '' !== $text && !preg_match('/[^\x00-\x1f\x7f]/', $text);
|
||||
}
|
||||
/**
|
||||
* Returns TRUE if every character in the string text is a decimal digit, FALSE otherwise.
|
||||
*
|
||||
* @see https://php.net/ctype-digit
|
||||
*
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ctype_digit($text)
|
||||
{
|
||||
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||
return \is_string($text) && '' !== $text && !preg_match('/[^0-9]/', $text);
|
||||
}
|
||||
/**
|
||||
* Returns TRUE if every character in text is printable and actually creates visible output (no white space), FALSE otherwise.
|
||||
*
|
||||
* @see https://php.net/ctype-graph
|
||||
*
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ctype_graph($text)
|
||||
{
|
||||
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||
return \is_string($text) && '' !== $text && !preg_match('/[^!-~]/', $text);
|
||||
}
|
||||
/**
|
||||
* Returns TRUE if every character in text is a lowercase letter.
|
||||
*
|
||||
* @see https://php.net/ctype-lower
|
||||
*
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ctype_lower($text)
|
||||
{
|
||||
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||
return \is_string($text) && '' !== $text && !preg_match('/[^a-z]/', $text);
|
||||
}
|
||||
/**
|
||||
* Returns TRUE if every character in text will actually create output (including blanks). Returns FALSE if text contains control characters or characters that do not have any output or control function at all.
|
||||
*
|
||||
* @see https://php.net/ctype-print
|
||||
*
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ctype_print($text)
|
||||
{
|
||||
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||
return \is_string($text) && '' !== $text && !preg_match('/[^ -~]/', $text);
|
||||
}
|
||||
/**
|
||||
* Returns TRUE if every character in text is printable, but neither letter, digit or blank, FALSE otherwise.
|
||||
*
|
||||
* @see https://php.net/ctype-punct
|
||||
*
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ctype_punct($text)
|
||||
{
|
||||
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||
return \is_string($text) && '' !== $text && !preg_match('/[^!-\/\:-@\[-`\{-~]/', $text);
|
||||
}
|
||||
/**
|
||||
* Returns TRUE if every character in text creates some sort of white space, FALSE otherwise. Besides the blank character this also includes tab, vertical tab, line feed, carriage return and form feed characters.
|
||||
*
|
||||
* @see https://php.net/ctype-space
|
||||
*
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ctype_space($text)
|
||||
{
|
||||
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||
return \is_string($text) && '' !== $text && !preg_match('/[^\s]/', $text);
|
||||
}
|
||||
/**
|
||||
* Returns TRUE if every character in text is an uppercase letter.
|
||||
*
|
||||
* @see https://php.net/ctype-upper
|
||||
*
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ctype_upper($text)
|
||||
{
|
||||
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||
return \is_string($text) && '' !== $text && !preg_match('/[^A-Z]/', $text);
|
||||
}
|
||||
/**
|
||||
* Returns TRUE if every character in text is a hexadecimal 'digit', that is a decimal digit or a character from [A-Fa-f] , FALSE otherwise.
|
||||
*
|
||||
* @see https://php.net/ctype-xdigit
|
||||
*
|
||||
* @param mixed $text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function ctype_xdigit($text)
|
||||
{
|
||||
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
|
||||
return \is_string($text) && '' !== $text && !preg_match('/[^A-Fa-f0-9]/', $text);
|
||||
}
|
||||
/**
|
||||
* Converts integers to their char versions according to normal ctype behaviour, if needed.
|
||||
*
|
||||
* If an integer between -128 and 255 inclusive is provided,
|
||||
* it is interpreted as the ASCII value of a single character
|
||||
* (negative values have 256 added in order to allow characters in the Extended ASCII range).
|
||||
* Any other integer is interpreted as a string containing the decimal digits of the integer.
|
||||
*
|
||||
* @param mixed $int
|
||||
* @param string $function
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private static function convert_int_to_char_for_ctype($int, $function)
|
||||
{
|
||||
if (!\is_int($int)) {
|
||||
return $int;
|
||||
}
|
||||
if ($int < -128 || $int > 255) {
|
||||
return (string) $int;
|
||||
}
|
||||
if (\PHP_VERSION_ID >= 80100) {
|
||||
@trigger_error($function . '(): Argument of type int will be interpreted as string in the future', \E_USER_DEPRECATED);
|
||||
}
|
||||
if ($int < 0) {
|
||||
$int += 256;
|
||||
}
|
||||
return \chr($int);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2018-present Fabien Potencier
|
||||
|
||||
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:
|
||||
|
||||
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,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -0,0 +1,12 @@
|
||||
Symfony Polyfill / Ctype
|
||||
========================
|
||||
|
||||
This component provides `ctype_*` functions to users who run php versions without the ctype extension.
|
||||
|
||||
More information can be found in the
|
||||
[main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md).
|
||||
|
||||
License
|
||||
=======
|
||||
|
||||
This library is released under the [MIT license](LICENSE).
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Symfony\Polyfill\Ctype as p;
|
||||
|
||||
if (\PHP_VERSION_ID >= 80000) {
|
||||
return require __DIR__.'/bootstrap80.php';
|
||||
}
|
||||
|
||||
if (!function_exists('ctype_alnum')) {
|
||||
function ctype_alnum($text) { return p\Ctype::ctype_alnum($text); }
|
||||
}
|
||||
if (!function_exists('ctype_alpha')) {
|
||||
function ctype_alpha($text) { return p\Ctype::ctype_alpha($text); }
|
||||
}
|
||||
if (!function_exists('ctype_cntrl')) {
|
||||
function ctype_cntrl($text) { return p\Ctype::ctype_cntrl($text); }
|
||||
}
|
||||
if (!function_exists('ctype_digit')) {
|
||||
function ctype_digit($text) { return p\Ctype::ctype_digit($text); }
|
||||
}
|
||||
if (!function_exists('ctype_graph')) {
|
||||
function ctype_graph($text) { return p\Ctype::ctype_graph($text); }
|
||||
}
|
||||
if (!function_exists('ctype_lower')) {
|
||||
function ctype_lower($text) { return p\Ctype::ctype_lower($text); }
|
||||
}
|
||||
if (!function_exists('ctype_print')) {
|
||||
function ctype_print($text) { return p\Ctype::ctype_print($text); }
|
||||
}
|
||||
if (!function_exists('ctype_punct')) {
|
||||
function ctype_punct($text) { return p\Ctype::ctype_punct($text); }
|
||||
}
|
||||
if (!function_exists('ctype_space')) {
|
||||
function ctype_space($text) { return p\Ctype::ctype_space($text); }
|
||||
}
|
||||
if (!function_exists('ctype_upper')) {
|
||||
function ctype_upper($text) { return p\Ctype::ctype_upper($text); }
|
||||
}
|
||||
if (!function_exists('ctype_xdigit')) {
|
||||
function ctype_xdigit($text) { return p\Ctype::ctype_xdigit($text); }
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Symfony\Polyfill\Ctype as p;
|
||||
|
||||
if (!function_exists('ctype_alnum')) {
|
||||
function ctype_alnum(mixed $text): bool { return p\Ctype::ctype_alnum($text); }
|
||||
}
|
||||
if (!function_exists('ctype_alpha')) {
|
||||
function ctype_alpha(mixed $text): bool { return p\Ctype::ctype_alpha($text); }
|
||||
}
|
||||
if (!function_exists('ctype_cntrl')) {
|
||||
function ctype_cntrl(mixed $text): bool { return p\Ctype::ctype_cntrl($text); }
|
||||
}
|
||||
if (!function_exists('ctype_digit')) {
|
||||
function ctype_digit(mixed $text): bool { return p\Ctype::ctype_digit($text); }
|
||||
}
|
||||
if (!function_exists('ctype_graph')) {
|
||||
function ctype_graph(mixed $text): bool { return p\Ctype::ctype_graph($text); }
|
||||
}
|
||||
if (!function_exists('ctype_lower')) {
|
||||
function ctype_lower(mixed $text): bool { return p\Ctype::ctype_lower($text); }
|
||||
}
|
||||
if (!function_exists('ctype_print')) {
|
||||
function ctype_print(mixed $text): bool { return p\Ctype::ctype_print($text); }
|
||||
}
|
||||
if (!function_exists('ctype_punct')) {
|
||||
function ctype_punct(mixed $text): bool { return p\Ctype::ctype_punct($text); }
|
||||
}
|
||||
if (!function_exists('ctype_space')) {
|
||||
function ctype_space(mixed $text): bool { return p\Ctype::ctype_space($text); }
|
||||
}
|
||||
if (!function_exists('ctype_upper')) {
|
||||
function ctype_upper(mixed $text): bool { return p\Ctype::ctype_upper($text); }
|
||||
}
|
||||
if (!function_exists('ctype_xdigit')) {
|
||||
function ctype_xdigit(mixed $text): bool { return p\Ctype::ctype_xdigit($text); }
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "symfony\/polyfill-ctype",
|
||||
"type": "library",
|
||||
"description": "Symfony polyfill for ctype functions",
|
||||
"keywords": [
|
||||
"polyfill",
|
||||
"compatibility",
|
||||
"portable",
|
||||
"ctype"
|
||||
],
|
||||
"homepage": "https:\/\/symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Gert de Pagter",
|
||||
"email": "BackEndTea@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https:\/\/symfony.com\/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.2"
|
||||
},
|
||||
"provide": {
|
||||
"ext-ctype": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Ctype\\": ""
|
||||
},
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
]
|
||||
},
|
||||
"suggest": {
|
||||
"ext-ctype": "For best performance"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"name": "symfony\/polyfill",
|
||||
"url": "https:\/\/github.com\/symfony\/polyfill"
|
||||
}
|
||||
}
|
||||
}
|
||||
+210
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Symfony\Polyfill\Intl\Grapheme;
|
||||
|
||||
\define('SYMFONY_GRAPHEME_CLUSTER_RX', ((float) \PCRE_VERSION < 10 ? (float) \PCRE_VERSION >= 8.32 : (float) \PCRE_VERSION >= 10.39) ? '\X' : \Symfony\Polyfill\Intl\Grapheme\Grapheme::GRAPHEME_CLUSTER_RX);
|
||||
/**
|
||||
* Partial intl implementation in pure PHP.
|
||||
*
|
||||
* Implemented:
|
||||
* - grapheme_extract - Extract a sequence of grapheme clusters from a text buffer, which must be encoded in UTF-8
|
||||
* - grapheme_stripos - Find position (in grapheme units) of first occurrence of a case-insensitive string
|
||||
* - grapheme_stristr - Returns part of haystack string from the first occurrence of case-insensitive needle to the end of haystack
|
||||
* - grapheme_strlen - Get string length in grapheme units
|
||||
* - grapheme_strpos - Find position (in grapheme units) of first occurrence of a string
|
||||
* - grapheme_strripos - Find position (in grapheme units) of last occurrence of a case-insensitive string
|
||||
* - grapheme_strrpos - Find position (in grapheme units) of last occurrence of a string
|
||||
* - grapheme_strstr - Returns part of haystack string from the first occurrence of needle to the end of haystack
|
||||
* - grapheme_substr - Return part of a string
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class Grapheme
|
||||
{
|
||||
// (CRLF|([ZWNJ-ZWJ]|T+|L*(LV?V+|LV|LVT)T*|L+|[^Control])[Extend]*|[Control])
|
||||
// This regular expression is a work around for http://bugs.exim.org/1279
|
||||
public const GRAPHEME_CLUSTER_RX = '(?:\r\n|(?:[ -~\x{200C}\x{200D}]|[ᆨ-ᇹ]+|[ᄀ-ᅟ]*(?:[가개갸걔거게겨계고과괘괴교구궈궤귀규그긔기까깨꺄꺠꺼께껴꼐꼬꽈꽤꾀꾜꾸꿔꿰뀌뀨끄끠끼나내냐냬너네녀녜노놔놰뇌뇨누눠눼뉘뉴느늬니다대댜댸더데뎌뎨도돠돼되됴두둬뒈뒤듀드듸디따때땨떄떠떼뗘뗴또똬뙈뙤뚀뚜뚸뛔뛰뜌뜨띄띠라래랴럐러레려례로롸뢔뢰료루뤄뤠뤼류르릐리마매먀먜머메며몌모뫄뫠뫼묘무뭐뭬뮈뮤므믜미바배뱌뱨버베벼볘보봐봬뵈뵤부붜붸뷔뷰브븨비빠빼뺘뺴뻐뻬뼈뼤뽀뽜뽸뾔뾰뿌뿨쀄쀠쀼쁘쁴삐사새샤섀서세셔셰소솨쇄쇠쇼수숴쉐쉬슈스싀시싸쌔쌰썌써쎄쎠쎼쏘쏴쐐쐬쑈쑤쒀쒜쒸쓔쓰씌씨아애야얘어에여예오와왜외요우워웨위유으의이자재쟈쟤저제져졔조좌좨죄죠주줘줴쥐쥬즈즤지짜째쨔쨰쩌쩨쪄쪠쪼쫘쫴쬐쬬쭈쭤쮀쮜쮸쯔쯰찌차채챠챼처체쳐쳬초촤쵀최쵸추춰췌취츄츠츼치카캐캬컈커케켜켸코콰쾌쾨쿄쿠쿼퀘퀴큐크킈키타태탸턔터테텨톄토톼퇘퇴툐투퉈퉤튀튜트틔티파패퍄퍠퍼페펴폐포퐈퐤푀표푸풔풰퓌퓨프픠피하해햐햬허헤혀혜호화홰회효후훠훼휘휴흐희히]?[ᅠ-ᆢ]+|[가-힣])[ᆨ-ᇹ]*|[ᄀ-ᅟ]+|[^\p{Cc}\p{Cf}\p{Zl}\p{Zp}])[\p{Mn}\p{Me}\x{09BE}\x{09D7}\x{0B3E}\x{0B57}\x{0BBE}\x{0BD7}\x{0CC2}\x{0CD5}\x{0CD6}\x{0D3E}\x{0D57}\x{0DCF}\x{0DDF}\x{200C}\x{200D}\x{1D165}\x{1D16E}-\x{1D172}]*|[\p{Cc}\p{Cf}\p{Zl}\p{Zp}])';
|
||||
private const CASE_FOLD = [['µ', 'ſ', "ͅ", 'ς', "ϐ", "ϑ", "ϕ", "ϖ", "ϰ", "ϱ", "ϵ", "ẛ", "ι"], ['μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "ṡ", 'ι']];
|
||||
public static function grapheme_extract($s, $size, $type = \GRAPHEME_EXTR_COUNT, $start = 0, &$next = 0)
|
||||
{
|
||||
if (0 > $start) {
|
||||
$start = \strlen($s) + $start;
|
||||
}
|
||||
if (!\is_scalar($s)) {
|
||||
$hasError = \false;
|
||||
set_error_handler(function () use (&$hasError) {
|
||||
$hasError = \true;
|
||||
});
|
||||
$next = substr($s, $start);
|
||||
restore_error_handler();
|
||||
if ($hasError) {
|
||||
substr($s, $start);
|
||||
$s = '';
|
||||
} else {
|
||||
$s = $next;
|
||||
}
|
||||
} else {
|
||||
$s = substr($s, $start);
|
||||
}
|
||||
$size = (int) $size;
|
||||
$type = (int) $type;
|
||||
$start = (int) $start;
|
||||
if (\GRAPHEME_EXTR_COUNT !== $type && \GRAPHEME_EXTR_MAXBYTES !== $type && \GRAPHEME_EXTR_MAXCHARS !== $type) {
|
||||
if (80000 > \PHP_VERSION_ID) {
|
||||
return \false;
|
||||
}
|
||||
throw new \ValueError('grapheme_extract(): Argument #3 ($type) must be one of GRAPHEME_EXTR_COUNT, GRAPHEME_EXTR_MAXBYTES, or GRAPHEME_EXTR_MAXCHARS');
|
||||
}
|
||||
if (!isset($s[0]) || 0 > $size || 0 > $start) {
|
||||
return \false;
|
||||
}
|
||||
if (0 === $size) {
|
||||
return '';
|
||||
}
|
||||
$next = $start;
|
||||
$s = preg_split('/(' . \SYMFONY_GRAPHEME_CLUSTER_RX . ')/u', "\r\n" . $s, $size + 1, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE);
|
||||
if (!isset($s[1])) {
|
||||
return \false;
|
||||
}
|
||||
$i = 1;
|
||||
$ret = '';
|
||||
do {
|
||||
if (\GRAPHEME_EXTR_COUNT === $type) {
|
||||
--$size;
|
||||
} elseif (\GRAPHEME_EXTR_MAXBYTES === $type) {
|
||||
$size -= \strlen($s[$i]);
|
||||
} else {
|
||||
$size -= iconv_strlen($s[$i], 'UTF-8//IGNORE');
|
||||
}
|
||||
if ($size >= 0) {
|
||||
$ret .= $s[$i];
|
||||
}
|
||||
} while (isset($s[++$i]) && $size > 0);
|
||||
$next += \strlen($ret);
|
||||
return $ret;
|
||||
}
|
||||
public static function grapheme_strlen($s)
|
||||
{
|
||||
preg_replace('/' . \SYMFONY_GRAPHEME_CLUSTER_RX . '/u', '', $s, -1, $len);
|
||||
return 0 === $len && '' !== $s ? null : $len;
|
||||
}
|
||||
public static function grapheme_substr($s, $start, $len = null)
|
||||
{
|
||||
if (null === $len) {
|
||||
$len = 2147483647;
|
||||
}
|
||||
preg_match_all('/' . \SYMFONY_GRAPHEME_CLUSTER_RX . '/u', $s, $s);
|
||||
$slen = \count($s[0]);
|
||||
$start = (int) $start;
|
||||
if (0 > $start) {
|
||||
$start += $slen;
|
||||
}
|
||||
if (0 > $start) {
|
||||
if (\PHP_VERSION_ID < 80000) {
|
||||
return \false;
|
||||
}
|
||||
$start = 0;
|
||||
}
|
||||
if ($start >= $slen) {
|
||||
return \PHP_VERSION_ID >= 80000 ? '' : \false;
|
||||
}
|
||||
$rem = $slen - $start;
|
||||
if (0 > $len) {
|
||||
$len += $rem;
|
||||
}
|
||||
if (0 === $len) {
|
||||
return '';
|
||||
}
|
||||
if (0 > $len) {
|
||||
return \PHP_VERSION_ID >= 80000 ? '' : \false;
|
||||
}
|
||||
if ($len > $rem) {
|
||||
$len = $rem;
|
||||
}
|
||||
return implode('', \array_slice($s[0], $start, $len));
|
||||
}
|
||||
public static function grapheme_strpos($s, $needle, $offset = 0)
|
||||
{
|
||||
return self::grapheme_position($s, $needle, $offset, 0);
|
||||
}
|
||||
public static function grapheme_stripos($s, $needle, $offset = 0)
|
||||
{
|
||||
return self::grapheme_position($s, $needle, $offset, 1);
|
||||
}
|
||||
public static function grapheme_strrpos($s, $needle, $offset = 0)
|
||||
{
|
||||
return self::grapheme_position($s, $needle, $offset, 2);
|
||||
}
|
||||
public static function grapheme_strripos($s, $needle, $offset = 0)
|
||||
{
|
||||
return self::grapheme_position($s, $needle, $offset, 3);
|
||||
}
|
||||
public static function grapheme_stristr($s, $needle, $beforeNeedle = \false)
|
||||
{
|
||||
return mb_stristr($s, $needle, $beforeNeedle, 'UTF-8');
|
||||
}
|
||||
public static function grapheme_strstr($s, $needle, $beforeNeedle = \false)
|
||||
{
|
||||
return mb_strstr($s, $needle, $beforeNeedle, 'UTF-8');
|
||||
}
|
||||
private static function grapheme_position($s, $needle, $offset, $mode)
|
||||
{
|
||||
$needle = (string) $needle;
|
||||
if (80000 > \PHP_VERSION_ID && !preg_match('/./us', $needle)) {
|
||||
return \false;
|
||||
}
|
||||
$s = (string) $s;
|
||||
if (!preg_match('/./us', $s)) {
|
||||
return \false;
|
||||
}
|
||||
if ($offset > 0) {
|
||||
$s = self::grapheme_substr($s, $offset);
|
||||
} elseif ($offset < 0) {
|
||||
if (2 > $mode) {
|
||||
$offset += self::grapheme_strlen($s);
|
||||
$s = self::grapheme_substr($s, $offset);
|
||||
if (0 > $offset) {
|
||||
$offset = 0;
|
||||
}
|
||||
} elseif (0 > $offset += self::grapheme_strlen($needle)) {
|
||||
$s = self::grapheme_substr($s, 0, $offset);
|
||||
$offset = 0;
|
||||
} else {
|
||||
$offset = 0;
|
||||
}
|
||||
}
|
||||
// As UTF-8 is self-synchronizing, and we have ensured the strings are valid UTF-8,
|
||||
// we can use normal binary string functions here. For case-insensitive searches,
|
||||
// case fold the strings first.
|
||||
$caseInsensitive = $mode & 1;
|
||||
$reverse = $mode & 2;
|
||||
if ($caseInsensitive) {
|
||||
// Use the same case folding mode as mbstring does for mb_stripos().
|
||||
// Stick to SIMPLE case folding to avoid changing the length of the string, which
|
||||
// might result in offsets being shifted.
|
||||
$mode = \defined('MB_CASE_FOLD_SIMPLE') ? \MB_CASE_FOLD_SIMPLE : \MB_CASE_LOWER;
|
||||
$s = mb_convert_case($s, $mode, 'UTF-8');
|
||||
$needle = mb_convert_case($needle, $mode, 'UTF-8');
|
||||
if (!\defined('MB_CASE_FOLD_SIMPLE')) {
|
||||
$s = str_replace(self::CASE_FOLD[0], self::CASE_FOLD[1], $s);
|
||||
$needle = str_replace(self::CASE_FOLD[0], self::CASE_FOLD[1], $needle);
|
||||
}
|
||||
}
|
||||
if ($reverse) {
|
||||
$needlePos = strrpos($s, $needle);
|
||||
} else {
|
||||
$needlePos = strpos($s, $needle);
|
||||
}
|
||||
return \false !== $needlePos ? self::grapheme_strlen(substr($s, 0, $needlePos)) + $offset : \false;
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2015-present Fabien Potencier
|
||||
|
||||
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:
|
||||
|
||||
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,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
Symfony Polyfill / Intl: Grapheme
|
||||
=================================
|
||||
|
||||
This component provides a partial, native PHP implementation of the
|
||||
[Grapheme functions](https://php.net/intl.grapheme) from the
|
||||
[Intl](https://php.net/intl) extension.
|
||||
|
||||
- [`grapheme_extract`](https://php.net/grapheme_extract): Extract a sequence of grapheme
|
||||
clusters from a text buffer, which must be encoded in UTF-8
|
||||
- [`grapheme_stripos`](https://php.net/grapheme_stripos): Find position (in grapheme units)
|
||||
of first occurrence of a case-insensitive string
|
||||
- [`grapheme_stristr`](https://php.net/grapheme_stristr): Returns part of haystack string
|
||||
from the first occurrence of case-insensitive needle to the end of haystack
|
||||
- [`grapheme_strlen`](https://php.net/grapheme_strlen): Get string length in grapheme units
|
||||
- [`grapheme_strpos`](https://php.net/grapheme_strpos): Find position (in grapheme units)
|
||||
of first occurrence of a string
|
||||
- [`grapheme_strripos`](https://php.net/grapheme_strripos): Find position (in grapheme units)
|
||||
of last occurrence of a case-insensitive string
|
||||
- [`grapheme_strrpos`](https://php.net/grapheme_strrpos): Find position (in grapheme units)
|
||||
of last occurrence of a string
|
||||
- [`grapheme_strstr`](https://php.net/grapheme_strstr): Returns part of haystack string from
|
||||
the first occurrence of needle to the end of haystack
|
||||
- [`grapheme_substr`](https://php.net/grapheme_substr): Return part of a string
|
||||
|
||||
More information can be found in the
|
||||
[main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md).
|
||||
|
||||
License
|
||||
=======
|
||||
|
||||
This library is released under the [MIT license](LICENSE).
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Symfony\Polyfill\Intl\Grapheme as p;
|
||||
|
||||
if (extension_loaded('intl')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (\PHP_VERSION_ID >= 80000) {
|
||||
return require __DIR__.'/bootstrap80.php';
|
||||
}
|
||||
|
||||
if (!defined('GRAPHEME_EXTR_COUNT')) {
|
||||
define('GRAPHEME_EXTR_COUNT', 0);
|
||||
}
|
||||
if (!defined('GRAPHEME_EXTR_MAXBYTES')) {
|
||||
define('GRAPHEME_EXTR_MAXBYTES', 1);
|
||||
}
|
||||
if (!defined('GRAPHEME_EXTR_MAXCHARS')) {
|
||||
define('GRAPHEME_EXTR_MAXCHARS', 2);
|
||||
}
|
||||
|
||||
if (!function_exists('grapheme_extract')) {
|
||||
function grapheme_extract($haystack, $size, $type = 0, $start = 0, &$next = 0) { return p\Grapheme::grapheme_extract($haystack, $size, $type, $start, $next); }
|
||||
}
|
||||
if (!function_exists('grapheme_stripos')) {
|
||||
function grapheme_stripos($haystack, $needle, $offset = 0) { return p\Grapheme::grapheme_stripos($haystack, $needle, $offset); }
|
||||
}
|
||||
if (!function_exists('grapheme_stristr')) {
|
||||
function grapheme_stristr($haystack, $needle, $beforeNeedle = false) { return p\Grapheme::grapheme_stristr($haystack, $needle, $beforeNeedle); }
|
||||
}
|
||||
if (!function_exists('grapheme_strlen')) {
|
||||
function grapheme_strlen($input) { return p\Grapheme::grapheme_strlen($input); }
|
||||
}
|
||||
if (!function_exists('grapheme_strpos')) {
|
||||
function grapheme_strpos($haystack, $needle, $offset = 0) { return p\Grapheme::grapheme_strpos($haystack, $needle, $offset); }
|
||||
}
|
||||
if (!function_exists('grapheme_strripos')) {
|
||||
function grapheme_strripos($haystack, $needle, $offset = 0) { return p\Grapheme::grapheme_strripos($haystack, $needle, $offset); }
|
||||
}
|
||||
if (!function_exists('grapheme_strrpos')) {
|
||||
function grapheme_strrpos($haystack, $needle, $offset = 0) { return p\Grapheme::grapheme_strrpos($haystack, $needle, $offset); }
|
||||
}
|
||||
if (!function_exists('grapheme_strstr')) {
|
||||
function grapheme_strstr($haystack, $needle, $beforeNeedle = false) { return p\Grapheme::grapheme_strstr($haystack, $needle, $beforeNeedle); }
|
||||
}
|
||||
if (!function_exists('grapheme_substr')) {
|
||||
function grapheme_substr($string, $offset, $length = null) { return p\Grapheme::grapheme_substr($string, $offset, $length); }
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Symfony\Polyfill\Intl\Grapheme as p;
|
||||
|
||||
if (!defined('GRAPHEME_EXTR_COUNT')) {
|
||||
define('GRAPHEME_EXTR_COUNT', 0);
|
||||
}
|
||||
if (!defined('GRAPHEME_EXTR_MAXBYTES')) {
|
||||
define('GRAPHEME_EXTR_MAXBYTES', 1);
|
||||
}
|
||||
if (!defined('GRAPHEME_EXTR_MAXCHARS')) {
|
||||
define('GRAPHEME_EXTR_MAXCHARS', 2);
|
||||
}
|
||||
|
||||
if (!function_exists('grapheme_extract')) {
|
||||
function grapheme_extract(?string $haystack, ?int $size, ?int $type = GRAPHEME_EXTR_COUNT, ?int $offset = 0, &$next = null): string|false { return p\Grapheme::grapheme_extract((string) $haystack, (int) $size, (int) $type, (int) $offset, $next); }
|
||||
}
|
||||
if (!function_exists('grapheme_stripos')) {
|
||||
function grapheme_stripos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_stripos((string) $haystack, (string) $needle, (int) $offset); }
|
||||
}
|
||||
if (!function_exists('grapheme_stristr')) {
|
||||
function grapheme_stristr(?string $haystack, ?string $needle, ?bool $beforeNeedle = false): string|false { return p\Grapheme::grapheme_stristr((string) $haystack, (string) $needle, (bool) $beforeNeedle); }
|
||||
}
|
||||
if (!function_exists('grapheme_strlen')) {
|
||||
function grapheme_strlen(?string $string): int|false|null { return p\Grapheme::grapheme_strlen((string) $string); }
|
||||
}
|
||||
if (!function_exists('grapheme_strpos')) {
|
||||
function grapheme_strpos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strpos((string) $haystack, (string) $needle, (int) $offset); }
|
||||
}
|
||||
if (!function_exists('grapheme_strripos')) {
|
||||
function grapheme_strripos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strripos((string) $haystack, (string) $needle, (int) $offset); }
|
||||
}
|
||||
if (!function_exists('grapheme_strrpos')) {
|
||||
function grapheme_strrpos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strrpos((string) $haystack, (string) $needle, (int) $offset); }
|
||||
}
|
||||
if (!function_exists('grapheme_strstr')) {
|
||||
function grapheme_strstr(?string $haystack, ?string $needle, ?bool $beforeNeedle = false): string|false { return p\Grapheme::grapheme_strstr((string) $haystack, (string) $needle, (bool) $beforeNeedle); }
|
||||
}
|
||||
if (!function_exists('grapheme_substr')) {
|
||||
function grapheme_substr(?string $string, ?int $offset, ?int $length = null): string|false { return p\Grapheme::grapheme_substr((string) $string, (int) $offset, $length); }
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "symfony\/polyfill-intl-grapheme",
|
||||
"type": "library",
|
||||
"description": "Symfony polyfill for intl's grapheme_* functions",
|
||||
"keywords": [
|
||||
"polyfill",
|
||||
"shim",
|
||||
"compatibility",
|
||||
"portable",
|
||||
"intl",
|
||||
"grapheme"
|
||||
],
|
||||
"homepage": "https:\/\/symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https:\/\/symfony.com\/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Intl\\Grapheme\\": ""
|
||||
},
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
]
|
||||
},
|
||||
"suggest": {
|
||||
"ext-intl": "For best performance"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"name": "symfony\/polyfill",
|
||||
"url": "https:\/\/github.com\/symfony\/polyfill"
|
||||
}
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2015-present Fabien Potencier
|
||||
|
||||
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:
|
||||
|
||||
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,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
+258
@@ -0,0 +1,258 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Symfony\Polyfill\Intl\Normalizer;
|
||||
|
||||
/**
|
||||
* Normalizer is a PHP fallback implementation of the Normalizer class provided by the intl extension.
|
||||
*
|
||||
* It has been validated with Unicode 6.3 Normalization Conformance Test.
|
||||
* See http://www.unicode.org/reports/tr15/ for detailed info about Unicode normalizations.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class Normalizer
|
||||
{
|
||||
public const FORM_D = \Normalizer::FORM_D;
|
||||
public const FORM_KD = \Normalizer::FORM_KD;
|
||||
public const FORM_C = \Normalizer::FORM_C;
|
||||
public const FORM_KC = \Normalizer::FORM_KC;
|
||||
public const NFD = \Normalizer::NFD;
|
||||
public const NFKD = \Normalizer::NFKD;
|
||||
public const NFC = \Normalizer::NFC;
|
||||
public const NFKC = \Normalizer::NFKC;
|
||||
private static $C;
|
||||
private static $D;
|
||||
private static $KD;
|
||||
private static $cC;
|
||||
private static $ulenMask = ["\xc0" => 2, "\xd0" => 2, "\xe0" => 3, "\xf0" => 4];
|
||||
private static $ASCII = " eiasntrolud][cmp'\ng|hv.fb,:=-q10C2*yx)(L9AS/P\"EjMIk3>5T<D4}B{8FwR67UGN;JzV#HOW_&!K?XQ%Y\\\tZ+~^\$@`\x00\x01\x02\x03\x04\x05\x06\x07\x08\v\f\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f";
|
||||
public static function isNormalized(string $s, int $form = self::FORM_C)
|
||||
{
|
||||
if (!\in_array($form, [self::NFD, self::NFKD, self::NFC, self::NFKC])) {
|
||||
return \false;
|
||||
}
|
||||
if (!isset($s[strspn($s, self::$ASCII)])) {
|
||||
return \true;
|
||||
}
|
||||
if (self::NFC == $form && preg_match('//u', $s) && !preg_match('/[^\x00-\x{2FF}]/u', $s)) {
|
||||
return \true;
|
||||
}
|
||||
return self::normalize($s, $form) === $s;
|
||||
}
|
||||
public static function normalize(string $s, int $form = self::FORM_C)
|
||||
{
|
||||
if (!preg_match('//u', $s)) {
|
||||
return \false;
|
||||
}
|
||||
switch ($form) {
|
||||
case self::NFC:
|
||||
$C = \true;
|
||||
$K = \false;
|
||||
break;
|
||||
case self::NFD:
|
||||
$C = \false;
|
||||
$K = \false;
|
||||
break;
|
||||
case self::NFKC:
|
||||
$C = \true;
|
||||
$K = \true;
|
||||
break;
|
||||
case self::NFKD:
|
||||
$C = \false;
|
||||
$K = \true;
|
||||
break;
|
||||
default:
|
||||
if (\defined('JooosiFonDeps\Normalizer::NONE') && \Normalizer::NONE == $form) {
|
||||
return $s;
|
||||
}
|
||||
if (80000 > \PHP_VERSION_ID) {
|
||||
return \false;
|
||||
}
|
||||
throw new \ValueError('normalizer_normalize(): Argument #2 ($form) must be a a valid normalization form');
|
||||
}
|
||||
if ('' === $s) {
|
||||
return '';
|
||||
}
|
||||
if ($K && null === self::$KD) {
|
||||
self::$KD = self::getData('compatibilityDecomposition');
|
||||
}
|
||||
if (null === self::$D) {
|
||||
self::$D = self::getData('canonicalDecomposition');
|
||||
self::$cC = self::getData('combiningClass');
|
||||
}
|
||||
if (null !== $mbEncoding = 2 & (int) \ini_get('mbstring.func_overload') ? mb_internal_encoding() : null) {
|
||||
mb_internal_encoding('8bit');
|
||||
}
|
||||
$r = self::decompose($s, $K);
|
||||
if ($C) {
|
||||
if (null === self::$C) {
|
||||
self::$C = self::getData('canonicalComposition');
|
||||
}
|
||||
$r = self::recompose($r);
|
||||
}
|
||||
if (null !== $mbEncoding) {
|
||||
mb_internal_encoding($mbEncoding);
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
private static function recompose($s)
|
||||
{
|
||||
$ASCII = self::$ASCII;
|
||||
$compMap = self::$C;
|
||||
$combClass = self::$cC;
|
||||
$ulenMask = self::$ulenMask;
|
||||
$result = $tail = '';
|
||||
$i = $s[0] < "\x80" ? 1 : $ulenMask[$s[0] & "\xf0"];
|
||||
$len = \strlen($s);
|
||||
$lastUchr = substr($s, 0, $i);
|
||||
$lastUcls = isset($combClass[$lastUchr]) ? 256 : 0;
|
||||
while ($i < $len) {
|
||||
if ($s[$i] < "\x80") {
|
||||
// ASCII chars
|
||||
if ($tail) {
|
||||
$lastUchr .= $tail;
|
||||
$tail = '';
|
||||
}
|
||||
if ($j = strspn($s, $ASCII, $i + 1)) {
|
||||
$lastUchr .= substr($s, $i, $j);
|
||||
$i += $j;
|
||||
}
|
||||
$result .= $lastUchr;
|
||||
$lastUchr = $s[$i];
|
||||
$lastUcls = 0;
|
||||
++$i;
|
||||
continue;
|
||||
}
|
||||
$ulen = $ulenMask[$s[$i] & "\xf0"];
|
||||
$uchr = substr($s, $i, $ulen);
|
||||
if ($lastUchr < "ᄀ" || "ᄒ" < $lastUchr || $uchr < "ᅡ" || "ᅵ" < $uchr || $lastUcls) {
|
||||
// Table lookup and combining chars composition
|
||||
$ucls = $combClass[$uchr] ?? 0;
|
||||
if (isset($compMap[$lastUchr . $uchr]) && (!$lastUcls || $lastUcls < $ucls)) {
|
||||
$lastUchr = $compMap[$lastUchr . $uchr];
|
||||
} elseif ($lastUcls = $ucls) {
|
||||
$tail .= $uchr;
|
||||
} else {
|
||||
if ($tail) {
|
||||
$lastUchr .= $tail;
|
||||
$tail = '';
|
||||
}
|
||||
$result .= $lastUchr;
|
||||
$lastUchr = $uchr;
|
||||
}
|
||||
} else {
|
||||
// Hangul chars
|
||||
$L = \ord($lastUchr[2]) - 0x80;
|
||||
$V = \ord($uchr[2]) - 0xa1;
|
||||
$T = 0;
|
||||
$uchr = substr($s, $i + $ulen, 3);
|
||||
if ("ᆧ" <= $uchr && $uchr <= "ᇂ") {
|
||||
$T = \ord($uchr[2]) - 0xa7;
|
||||
0 > $T && $T += 0x40;
|
||||
$ulen += 3;
|
||||
}
|
||||
$L = 0xac00 + ($L * 21 + $V) * 28 + $T;
|
||||
$lastUchr = \chr(0xe0 | $L >> 12) . \chr(0x80 | $L >> 6 & 0x3f) . \chr(0x80 | $L & 0x3f);
|
||||
}
|
||||
$i += $ulen;
|
||||
}
|
||||
return $result . $lastUchr . $tail;
|
||||
}
|
||||
private static function decompose($s, $c)
|
||||
{
|
||||
$result = '';
|
||||
$ASCII = self::$ASCII;
|
||||
$decompMap = self::$D;
|
||||
$combClass = self::$cC;
|
||||
$ulenMask = self::$ulenMask;
|
||||
if ($c) {
|
||||
$compatMap = self::$KD;
|
||||
}
|
||||
$c = [];
|
||||
$i = 0;
|
||||
$len = \strlen($s);
|
||||
while ($i < $len) {
|
||||
if ($s[$i] < "\x80") {
|
||||
// ASCII chars
|
||||
if ($c) {
|
||||
ksort($c);
|
||||
$result .= implode('', $c);
|
||||
$c = [];
|
||||
}
|
||||
$j = 1 + strspn($s, $ASCII, $i + 1);
|
||||
$result .= substr($s, $i, $j);
|
||||
$i += $j;
|
||||
continue;
|
||||
}
|
||||
$ulen = $ulenMask[$s[$i] & "\xf0"];
|
||||
$uchr = substr($s, $i, $ulen);
|
||||
$i += $ulen;
|
||||
if ($uchr < "가" || "힣" < $uchr) {
|
||||
// Table lookup
|
||||
if ($uchr !== $j = $compatMap[$uchr] ?? $decompMap[$uchr] ?? $uchr) {
|
||||
$uchr = $j;
|
||||
$j = \strlen($uchr);
|
||||
$ulen = $uchr[0] < "\x80" ? 1 : $ulenMask[$uchr[0] & "\xf0"];
|
||||
if ($ulen != $j) {
|
||||
// Put trailing chars in $s
|
||||
$j -= $ulen;
|
||||
$i -= $j;
|
||||
if (0 > $i) {
|
||||
$s = str_repeat(' ', -$i) . $s;
|
||||
$len -= $i;
|
||||
$i = 0;
|
||||
}
|
||||
while ($j--) {
|
||||
$s[$i + $j] = $uchr[$ulen + $j];
|
||||
}
|
||||
$uchr = substr($uchr, 0, $ulen);
|
||||
}
|
||||
}
|
||||
if (isset($combClass[$uchr])) {
|
||||
// Combining chars, for sorting
|
||||
if (!isset($c[$combClass[$uchr]])) {
|
||||
$c[$combClass[$uchr]] = '';
|
||||
}
|
||||
$c[$combClass[$uchr]] .= $uchr;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
// Hangul chars
|
||||
$uchr = unpack('C*', $uchr);
|
||||
$j = ($uchr[1] - 224 << 12) + ($uchr[2] - 128 << 6) + $uchr[3] - 0xac80;
|
||||
$uchr = "\xe1\x84" . \chr(0x80 + (int) ($j / 588)) . "\xe1\x85" . \chr(0xa1 + (int) ($j % 588 / 28));
|
||||
if ($j %= 28) {
|
||||
$uchr .= $j < 25 ? "\xe1\x86" . \chr(0xa7 + $j) : "\xe1\x87" . \chr(0x67 + $j);
|
||||
}
|
||||
}
|
||||
if ($c) {
|
||||
ksort($c);
|
||||
$result .= implode('', $c);
|
||||
$c = [];
|
||||
}
|
||||
$result .= $uchr;
|
||||
}
|
||||
if ($c) {
|
||||
ksort($c);
|
||||
$result .= implode('', $c);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
private static function getData($file)
|
||||
{
|
||||
if (file_exists($file = __DIR__ . '/Resources/unidata/' . $file . '.php')) {
|
||||
return require $file;
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
Symfony Polyfill / Intl: Normalizer
|
||||
===================================
|
||||
|
||||
This component provides a fallback implementation for the
|
||||
[`Normalizer`](https://php.net/Normalizer) class provided
|
||||
by the [Intl](https://php.net/intl) extension.
|
||||
|
||||
More information can be found in the
|
||||
[main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md).
|
||||
|
||||
License
|
||||
=======
|
||||
|
||||
This library is released under the [MIT license](LICENSE).
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
class Normalizer extends Symfony\Polyfill\Intl\Normalizer\Normalizer
|
||||
{
|
||||
/**
|
||||
* @deprecated since ICU 56 and removed in PHP 8
|
||||
*/
|
||||
public const NONE = 2;
|
||||
public const FORM_D = 4;
|
||||
public const FORM_KD = 8;
|
||||
public const FORM_C = 16;
|
||||
public const FORM_KC = 32;
|
||||
public const NFD = 4;
|
||||
public const NFKD = 8;
|
||||
public const NFC = 16;
|
||||
public const NFKC = 32;
|
||||
}
|
||||
+5
File diff suppressed because one or more lines are too long
+5
File diff suppressed because one or more lines are too long
+5
File diff suppressed because one or more lines are too long
+5
File diff suppressed because one or more lines are too long
+23
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Symfony\Polyfill\Intl\Normalizer as p;
|
||||
|
||||
if (\PHP_VERSION_ID >= 80000) {
|
||||
return require __DIR__.'/bootstrap80.php';
|
||||
}
|
||||
|
||||
if (!function_exists('normalizer_is_normalized')) {
|
||||
function normalizer_is_normalized($string, $form = p\Normalizer::FORM_C) { return p\Normalizer::isNormalized($string, $form); }
|
||||
}
|
||||
if (!function_exists('normalizer_normalize')) {
|
||||
function normalizer_normalize($string, $form = p\Normalizer::FORM_C) { return p\Normalizer::normalize($string, $form); }
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Symfony\Polyfill\Intl\Normalizer as p;
|
||||
|
||||
if (!function_exists('normalizer_is_normalized')) {
|
||||
function normalizer_is_normalized(?string $string, ?int $form = p\Normalizer::FORM_C): bool { return p\Normalizer::isNormalized((string) $string, (int) $form); }
|
||||
}
|
||||
if (!function_exists('normalizer_normalize')) {
|
||||
function normalizer_normalize(?string $string, ?int $form = p\Normalizer::FORM_C): string|false { return p\Normalizer::normalize((string) $string, (int) $form); }
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"name": "symfony\/polyfill-intl-normalizer",
|
||||
"type": "library",
|
||||
"description": "Symfony polyfill for intl's Normalizer class and related functions",
|
||||
"keywords": [
|
||||
"polyfill",
|
||||
"shim",
|
||||
"compatibility",
|
||||
"portable",
|
||||
"intl",
|
||||
"normalizer"
|
||||
],
|
||||
"homepage": "https:\/\/symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https:\/\/symfony.com\/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Intl\\Normalizer\\": ""
|
||||
},
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
],
|
||||
"classmap": [
|
||||
"Resources\/stubs"
|
||||
]
|
||||
},
|
||||
"suggest": {
|
||||
"ext-intl": "For best performance"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"name": "symfony\/polyfill",
|
||||
"url": "https:\/\/github.com\/symfony\/polyfill"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2015-present Fabien Potencier
|
||||
|
||||
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:
|
||||
|
||||
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,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
+835
@@ -0,0 +1,835 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Symfony\Polyfill\Mbstring;
|
||||
|
||||
/**
|
||||
* Partial mbstring implementation in PHP, iconv based, UTF-8 centric.
|
||||
*
|
||||
* Implemented:
|
||||
* - mb_chr - Returns a specific character from its Unicode code point
|
||||
* - mb_convert_encoding - Convert character encoding
|
||||
* - mb_convert_variables - Convert character code in variable(s)
|
||||
* - mb_decode_mimeheader - Decode string in MIME header field
|
||||
* - mb_encode_mimeheader - Encode string for MIME header XXX NATIVE IMPLEMENTATION IS REALLY BUGGED
|
||||
* - mb_decode_numericentity - Decode HTML numeric string reference to character
|
||||
* - mb_encode_numericentity - Encode character to HTML numeric string reference
|
||||
* - mb_convert_case - Perform case folding on a string
|
||||
* - mb_detect_encoding - Detect character encoding
|
||||
* - mb_get_info - Get internal settings of mbstring
|
||||
* - mb_http_input - Detect HTTP input character encoding
|
||||
* - mb_http_output - Set/Get HTTP output character encoding
|
||||
* - mb_internal_encoding - Set/Get internal character encoding
|
||||
* - mb_list_encodings - Returns an array of all supported encodings
|
||||
* - mb_ord - Returns the Unicode code point of a character
|
||||
* - mb_output_handler - Callback function converts character encoding in output buffer
|
||||
* - mb_scrub - Replaces ill-formed byte sequences with substitute characters
|
||||
* - mb_strlen - Get string length
|
||||
* - mb_strpos - Find position of first occurrence of string in a string
|
||||
* - mb_strrpos - Find position of last occurrence of a string in a string
|
||||
* - mb_str_split - Convert a string to an array
|
||||
* - mb_strtolower - Make a string lowercase
|
||||
* - mb_strtoupper - Make a string uppercase
|
||||
* - mb_substitute_character - Set/Get substitution character
|
||||
* - mb_substr - Get part of string
|
||||
* - mb_stripos - Finds position of first occurrence of a string within another, case insensitive
|
||||
* - mb_stristr - Finds first occurrence of a string within another, case insensitive
|
||||
* - mb_strrchr - Finds the last occurrence of a character in a string within another
|
||||
* - mb_strrichr - Finds the last occurrence of a character in a string within another, case insensitive
|
||||
* - mb_strripos - Finds position of last occurrence of a string within another, case insensitive
|
||||
* - mb_strstr - Finds first occurrence of a string within another
|
||||
* - mb_strwidth - Return width of string
|
||||
* - mb_substr_count - Count the number of substring occurrences
|
||||
* - mb_ucfirst - Make a string's first character uppercase
|
||||
* - mb_lcfirst - Make a string's first character lowercase
|
||||
* - mb_trim - Strip whitespace (or other characters) from the beginning and end of a string
|
||||
* - mb_ltrim - Strip whitespace (or other characters) from the beginning of a string
|
||||
* - mb_rtrim - Strip whitespace (or other characters) from the end of a string
|
||||
*
|
||||
* Not implemented:
|
||||
* - mb_convert_kana - Convert "kana" one from another ("zen-kaku", "han-kaku" and more)
|
||||
* - mb_ereg_* - Regular expression with multibyte support
|
||||
* - mb_parse_str - Parse GET/POST/COOKIE data and set global variable
|
||||
* - mb_preferred_mime_name - Get MIME charset string
|
||||
* - mb_regex_encoding - Returns current encoding for multibyte regex as string
|
||||
* - mb_regex_set_options - Set/Get the default options for mbregex functions
|
||||
* - mb_send_mail - Send encoded mail
|
||||
* - mb_split - Split multibyte string using regular expression
|
||||
* - mb_strcut - Get part of string
|
||||
* - mb_strimwidth - Get truncated string with specified width
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class Mbstring
|
||||
{
|
||||
public const MB_CASE_FOLD = \PHP_INT_MAX;
|
||||
private const SIMPLE_CASE_FOLD = [['µ', 'ſ', "ͅ", 'ς', "ϐ", "ϑ", "ϕ", "ϖ", "ϰ", "ϱ", "ϵ", "ẛ", "ι"], ['μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "ṡ", 'ι']];
|
||||
private static $encodingList = ['ASCII', 'UTF-8'];
|
||||
private static $language = 'neutral';
|
||||
private static $internalEncoding = 'UTF-8';
|
||||
public static function mb_convert_encoding($s, $toEncoding, $fromEncoding = null)
|
||||
{
|
||||
if (\is_array($s)) {
|
||||
$r = [];
|
||||
foreach ($s as $str) {
|
||||
$r[] = self::mb_convert_encoding($str, $toEncoding, $fromEncoding);
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
if (\is_array($fromEncoding) || null !== $fromEncoding && \false !== strpos($fromEncoding, ',')) {
|
||||
$fromEncoding = self::mb_detect_encoding($s, $fromEncoding);
|
||||
} else {
|
||||
$fromEncoding = self::getEncoding($fromEncoding);
|
||||
}
|
||||
$toEncoding = self::getEncoding($toEncoding);
|
||||
if ('BASE64' === $fromEncoding) {
|
||||
$s = base64_decode($s);
|
||||
$fromEncoding = $toEncoding;
|
||||
}
|
||||
if ('BASE64' === $toEncoding) {
|
||||
return base64_encode($s);
|
||||
}
|
||||
if ('HTML-ENTITIES' === $toEncoding || 'HTML' === $toEncoding) {
|
||||
if ('HTML-ENTITIES' === $fromEncoding || 'HTML' === $fromEncoding) {
|
||||
$fromEncoding = 'Windows-1252';
|
||||
}
|
||||
if ('UTF-8' !== $fromEncoding) {
|
||||
$s = iconv($fromEncoding, 'UTF-8//IGNORE', $s);
|
||||
}
|
||||
return preg_replace_callback('/[\x80-\xFF]+/', [__CLASS__, 'html_encoding_callback'], $s);
|
||||
}
|
||||
if ('HTML-ENTITIES' === $fromEncoding) {
|
||||
$s = html_entity_decode($s, \ENT_COMPAT, 'UTF-8');
|
||||
$fromEncoding = 'UTF-8';
|
||||
}
|
||||
return iconv($fromEncoding, $toEncoding . '//IGNORE', $s);
|
||||
}
|
||||
public static function mb_convert_variables($toEncoding, $fromEncoding, &...$vars)
|
||||
{
|
||||
$ok = \true;
|
||||
array_walk_recursive($vars, function (&$v) use (&$ok, $toEncoding, $fromEncoding) {
|
||||
if (\false === $v = self::mb_convert_encoding($v, $toEncoding, $fromEncoding)) {
|
||||
$ok = \false;
|
||||
}
|
||||
});
|
||||
return $ok ? $fromEncoding : \false;
|
||||
}
|
||||
public static function mb_decode_mimeheader($s)
|
||||
{
|
||||
return iconv_mime_decode($s, 2, self::$internalEncoding);
|
||||
}
|
||||
public static function mb_encode_mimeheader($s, $charset = null, $transferEncoding = null, $linefeed = null, $indent = null)
|
||||
{
|
||||
trigger_error('mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead', \E_USER_WARNING);
|
||||
}
|
||||
public static function mb_decode_numericentity($s, $convmap, $encoding = null)
|
||||
{
|
||||
if (null !== $s && !\is_scalar($s) && !(\is_object($s) && method_exists($s, '__toString'))) {
|
||||
trigger_error('mb_decode_numericentity() expects parameter 1 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
|
||||
return null;
|
||||
}
|
||||
if (!\is_array($convmap) || 80000 > \PHP_VERSION_ID && !$convmap) {
|
||||
return \false;
|
||||
}
|
||||
if (null !== $encoding && !\is_scalar($encoding)) {
|
||||
trigger_error('mb_decode_numericentity() expects parameter 3 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
|
||||
return '';
|
||||
// Instead of null (cf. mb_encode_numericentity).
|
||||
}
|
||||
$s = (string) $s;
|
||||
if ('' === $s) {
|
||||
return '';
|
||||
}
|
||||
$encoding = self::getEncoding($encoding);
|
||||
if ('UTF-8' === $encoding) {
|
||||
$encoding = null;
|
||||
if (!preg_match('//u', $s)) {
|
||||
$s = @iconv('UTF-8', 'UTF-8//IGNORE', $s);
|
||||
}
|
||||
} else {
|
||||
$s = iconv($encoding, 'UTF-8//IGNORE', $s);
|
||||
}
|
||||
$cnt = floor(\count($convmap) / 4) * 4;
|
||||
for ($i = 0; $i < $cnt; $i += 4) {
|
||||
// collector_decode_htmlnumericentity ignores $convmap[$i + 3]
|
||||
$convmap[$i] += $convmap[$i + 2];
|
||||
$convmap[$i + 1] += $convmap[$i + 2];
|
||||
}
|
||||
$s = preg_replace_callback('/&#(?:0*([0-9]+)|x0*([0-9a-fA-F]+))(?!&);?/', function (array $m) use ($cnt, $convmap) {
|
||||
$c = isset($m[2]) ? (int) hexdec($m[2]) : $m[1];
|
||||
for ($i = 0; $i < $cnt; $i += 4) {
|
||||
if ($c >= $convmap[$i] && $c <= $convmap[$i + 1]) {
|
||||
return self::mb_chr($c - $convmap[$i + 2]);
|
||||
}
|
||||
}
|
||||
return $m[0];
|
||||
}, $s);
|
||||
if (null === $encoding) {
|
||||
return $s;
|
||||
}
|
||||
return iconv('UTF-8', $encoding . '//IGNORE', $s);
|
||||
}
|
||||
public static function mb_encode_numericentity($s, $convmap, $encoding = null, $is_hex = \false)
|
||||
{
|
||||
if (null !== $s && !\is_scalar($s) && !(\is_object($s) && method_exists($s, '__toString'))) {
|
||||
trigger_error('mb_encode_numericentity() expects parameter 1 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
|
||||
return null;
|
||||
}
|
||||
if (!\is_array($convmap) || 80000 > \PHP_VERSION_ID && !$convmap) {
|
||||
return \false;
|
||||
}
|
||||
if (null !== $encoding && !\is_scalar($encoding)) {
|
||||
trigger_error('mb_encode_numericentity() expects parameter 3 to be string, ' . \gettype($s) . ' given', \E_USER_WARNING);
|
||||
return null;
|
||||
// Instead of '' (cf. mb_decode_numericentity).
|
||||
}
|
||||
if (null !== $is_hex && !\is_scalar($is_hex)) {
|
||||
trigger_error('mb_encode_numericentity() expects parameter 4 to be boolean, ' . \gettype($s) . ' given', \E_USER_WARNING);
|
||||
return null;
|
||||
}
|
||||
$s = (string) $s;
|
||||
if ('' === $s) {
|
||||
return '';
|
||||
}
|
||||
$encoding = self::getEncoding($encoding);
|
||||
if ('UTF-8' === $encoding) {
|
||||
$encoding = null;
|
||||
if (!preg_match('//u', $s)) {
|
||||
$s = @iconv('UTF-8', 'UTF-8//IGNORE', $s);
|
||||
}
|
||||
} else {
|
||||
$s = iconv($encoding, 'UTF-8//IGNORE', $s);
|
||||
}
|
||||
static $ulenMask = ["\xc0" => 2, "\xd0" => 2, "\xe0" => 3, "\xf0" => 4];
|
||||
$cnt = floor(\count($convmap) / 4) * 4;
|
||||
$i = 0;
|
||||
$len = \strlen($s);
|
||||
$result = '';
|
||||
while ($i < $len) {
|
||||
$ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xf0"];
|
||||
$uchr = substr($s, $i, $ulen);
|
||||
$i += $ulen;
|
||||
$c = self::mb_ord($uchr);
|
||||
for ($j = 0; $j < $cnt; $j += 4) {
|
||||
if ($c >= $convmap[$j] && $c <= $convmap[$j + 1]) {
|
||||
$cOffset = $c + $convmap[$j + 2] & $convmap[$j + 3];
|
||||
$result .= $is_hex ? sprintf('&#x%X;', $cOffset) : '&#' . $cOffset . ';';
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
$result .= $uchr;
|
||||
}
|
||||
if (null === $encoding) {
|
||||
return $result;
|
||||
}
|
||||
return iconv('UTF-8', $encoding . '//IGNORE', $result);
|
||||
}
|
||||
public static function mb_convert_case($s, $mode, $encoding = null)
|
||||
{
|
||||
$s = (string) $s;
|
||||
if ('' === $s) {
|
||||
return '';
|
||||
}
|
||||
$encoding = self::getEncoding($encoding);
|
||||
if ('UTF-8' === $encoding) {
|
||||
$encoding = null;
|
||||
if (!preg_match('//u', $s)) {
|
||||
$s = @iconv('UTF-8', 'UTF-8//IGNORE', $s);
|
||||
}
|
||||
} else {
|
||||
$s = iconv($encoding, 'UTF-8//IGNORE', $s);
|
||||
}
|
||||
if (\MB_CASE_TITLE == $mode) {
|
||||
static $titleRegexp = null;
|
||||
if (null === $titleRegexp) {
|
||||
$titleRegexp = self::getData('titleCaseRegexp');
|
||||
}
|
||||
$s = preg_replace_callback($titleRegexp, [__CLASS__, 'title_case'], $s);
|
||||
} else {
|
||||
if (\MB_CASE_UPPER == $mode) {
|
||||
static $upper = null;
|
||||
if (null === $upper) {
|
||||
$upper = self::getData('upperCase');
|
||||
}
|
||||
$map = $upper;
|
||||
} else {
|
||||
if (self::MB_CASE_FOLD === $mode) {
|
||||
static $caseFolding = null;
|
||||
if (null === $caseFolding) {
|
||||
$caseFolding = self::getData('caseFolding');
|
||||
}
|
||||
$s = strtr($s, $caseFolding);
|
||||
}
|
||||
static $lower = null;
|
||||
if (null === $lower) {
|
||||
$lower = self::getData('lowerCase');
|
||||
}
|
||||
$map = $lower;
|
||||
}
|
||||
static $ulenMask = ["\xc0" => 2, "\xd0" => 2, "\xe0" => 3, "\xf0" => 4];
|
||||
$i = 0;
|
||||
$len = \strlen($s);
|
||||
while ($i < $len) {
|
||||
$ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xf0"];
|
||||
$uchr = substr($s, $i, $ulen);
|
||||
$i += $ulen;
|
||||
if (isset($map[$uchr])) {
|
||||
$uchr = $map[$uchr];
|
||||
$nlen = \strlen($uchr);
|
||||
if ($nlen == $ulen) {
|
||||
$nlen = $i;
|
||||
do {
|
||||
$s[--$nlen] = $uchr[--$ulen];
|
||||
} while ($ulen);
|
||||
} else {
|
||||
$s = substr_replace($s, $uchr, $i - $ulen, $ulen);
|
||||
$len += $nlen - $ulen;
|
||||
$i += $nlen - $ulen;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (null === $encoding) {
|
||||
return $s;
|
||||
}
|
||||
return iconv('UTF-8', $encoding . '//IGNORE', $s);
|
||||
}
|
||||
public static function mb_internal_encoding($encoding = null)
|
||||
{
|
||||
if (null === $encoding) {
|
||||
return self::$internalEncoding;
|
||||
}
|
||||
$normalizedEncoding = self::getEncoding($encoding);
|
||||
if ('UTF-8' === $normalizedEncoding || \false !== @iconv($normalizedEncoding, $normalizedEncoding, ' ')) {
|
||||
self::$internalEncoding = $normalizedEncoding;
|
||||
return \true;
|
||||
}
|
||||
if (80000 > \PHP_VERSION_ID) {
|
||||
return \false;
|
||||
}
|
||||
throw new \ValueError(sprintf('Argument #1 ($encoding) must be a valid encoding, "%s" given', $encoding));
|
||||
}
|
||||
public static function mb_language($lang = null)
|
||||
{
|
||||
if (null === $lang) {
|
||||
return self::$language;
|
||||
}
|
||||
switch ($normalizedLang = strtolower($lang)) {
|
||||
case 'uni':
|
||||
case 'neutral':
|
||||
self::$language = $normalizedLang;
|
||||
return \true;
|
||||
}
|
||||
if (80000 > \PHP_VERSION_ID) {
|
||||
return \false;
|
||||
}
|
||||
throw new \ValueError(sprintf('Argument #1 ($language) must be a valid language, "%s" given', $lang));
|
||||
}
|
||||
public static function mb_list_encodings()
|
||||
{
|
||||
return ['UTF-8'];
|
||||
}
|
||||
public static function mb_encoding_aliases($encoding)
|
||||
{
|
||||
switch (strtoupper($encoding)) {
|
||||
case 'UTF8':
|
||||
case 'UTF-8':
|
||||
return ['utf8'];
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
public static function mb_check_encoding($var = null, $encoding = null)
|
||||
{
|
||||
if (null === $encoding) {
|
||||
if (null === $var) {
|
||||
return \false;
|
||||
}
|
||||
$encoding = self::$internalEncoding;
|
||||
}
|
||||
if (!\is_array($var)) {
|
||||
return self::mb_detect_encoding($var, [$encoding]) || \false !== @iconv($encoding, $encoding, $var);
|
||||
}
|
||||
foreach ($var as $key => $value) {
|
||||
if (!self::mb_check_encoding($key, $encoding)) {
|
||||
return \false;
|
||||
}
|
||||
if (!self::mb_check_encoding($value, $encoding)) {
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
public static function mb_detect_encoding($str, $encodingList = null, $strict = \false)
|
||||
{
|
||||
if (null === $encodingList) {
|
||||
$encodingList = self::$encodingList;
|
||||
} else {
|
||||
if (!\is_array($encodingList)) {
|
||||
$encodingList = array_map('trim', explode(',', $encodingList));
|
||||
}
|
||||
$encodingList = array_map('strtoupper', $encodingList);
|
||||
}
|
||||
foreach ($encodingList as $enc) {
|
||||
switch ($enc) {
|
||||
case 'ASCII':
|
||||
if (!preg_match('/[\x80-\xFF]/', $str)) {
|
||||
return $enc;
|
||||
}
|
||||
break;
|
||||
case 'UTF8':
|
||||
case 'UTF-8':
|
||||
if (preg_match('//u', $str)) {
|
||||
return 'UTF-8';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (0 === strncmp($enc, 'ISO-8859-', 9)) {
|
||||
return $enc;
|
||||
}
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
public static function mb_detect_order($encodingList = null)
|
||||
{
|
||||
if (null === $encodingList) {
|
||||
return self::$encodingList;
|
||||
}
|
||||
if (!\is_array($encodingList)) {
|
||||
$encodingList = array_map('trim', explode(',', $encodingList));
|
||||
}
|
||||
$encodingList = array_map('strtoupper', $encodingList);
|
||||
foreach ($encodingList as $enc) {
|
||||
switch ($enc) {
|
||||
default:
|
||||
if (strncmp($enc, 'ISO-8859-', 9)) {
|
||||
return \false;
|
||||
}
|
||||
// no break
|
||||
case 'ASCII':
|
||||
case 'UTF8':
|
||||
case 'UTF-8':
|
||||
}
|
||||
}
|
||||
self::$encodingList = $encodingList;
|
||||
return \true;
|
||||
}
|
||||
public static function mb_strlen($s, $encoding = null)
|
||||
{
|
||||
$encoding = self::getEncoding($encoding);
|
||||
if ('CP850' === $encoding || 'ASCII' === $encoding) {
|
||||
return \strlen($s);
|
||||
}
|
||||
return @iconv_strlen($s, $encoding);
|
||||
}
|
||||
public static function mb_strpos($haystack, $needle, $offset = 0, $encoding = null)
|
||||
{
|
||||
$encoding = self::getEncoding($encoding);
|
||||
if ('CP850' === $encoding || 'ASCII' === $encoding) {
|
||||
return strpos($haystack, $needle, $offset);
|
||||
}
|
||||
$needle = (string) $needle;
|
||||
if ('' === $needle) {
|
||||
if (80000 > \PHP_VERSION_ID) {
|
||||
trigger_error(__METHOD__ . ': Empty delimiter', \E_USER_WARNING);
|
||||
return \false;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return iconv_strpos($haystack, $needle, $offset, $encoding);
|
||||
}
|
||||
public static function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null)
|
||||
{
|
||||
$encoding = self::getEncoding($encoding);
|
||||
if ('CP850' === $encoding || 'ASCII' === $encoding) {
|
||||
return strrpos($haystack, $needle, $offset);
|
||||
}
|
||||
if ($offset != (int) $offset) {
|
||||
$offset = 0;
|
||||
} elseif ($offset = (int) $offset) {
|
||||
if ($offset < 0) {
|
||||
if (0 > $offset += self::mb_strlen($needle)) {
|
||||
$haystack = self::mb_substr($haystack, 0, $offset, $encoding);
|
||||
}
|
||||
$offset = 0;
|
||||
} else {
|
||||
$haystack = self::mb_substr($haystack, $offset, 2147483647, $encoding);
|
||||
}
|
||||
}
|
||||
$pos = '' !== $needle || 80000 > \PHP_VERSION_ID ? iconv_strrpos($haystack, $needle, $encoding) : self::mb_strlen($haystack, $encoding);
|
||||
return \false !== $pos ? $offset + $pos : \false;
|
||||
}
|
||||
public static function mb_str_split($string, $split_length = 1, $encoding = null)
|
||||
{
|
||||
if (null !== $string && !\is_scalar($string) && !(\is_object($string) && method_exists($string, '__toString'))) {
|
||||
trigger_error('mb_str_split() expects parameter 1 to be string, ' . \gettype($string) . ' given', \E_USER_WARNING);
|
||||
return null;
|
||||
}
|
||||
if (1 > $split_length = (int) $split_length) {
|
||||
if (80000 > \PHP_VERSION_ID) {
|
||||
trigger_error('The length of each segment must be greater than zero', \E_USER_WARNING);
|
||||
return \false;
|
||||
}
|
||||
throw new \ValueError('Argument #2 ($length) must be greater than 0');
|
||||
}
|
||||
if (null === $encoding) {
|
||||
$encoding = mb_internal_encoding();
|
||||
}
|
||||
if ('UTF-8' === $encoding = self::getEncoding($encoding)) {
|
||||
$rx = '/(';
|
||||
while (65535 < $split_length) {
|
||||
$rx .= '.{65535}';
|
||||
$split_length -= 65535;
|
||||
}
|
||||
$rx .= '.{' . $split_length . '})/us';
|
||||
return preg_split($rx, $string, -1, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY);
|
||||
}
|
||||
$result = [];
|
||||
$length = mb_strlen($string, $encoding);
|
||||
for ($i = 0; $i < $length; $i += $split_length) {
|
||||
$result[] = mb_substr($string, $i, $split_length, $encoding);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
public static function mb_strtolower($s, $encoding = null)
|
||||
{
|
||||
return self::mb_convert_case($s, \MB_CASE_LOWER, $encoding);
|
||||
}
|
||||
public static function mb_strtoupper($s, $encoding = null)
|
||||
{
|
||||
return self::mb_convert_case($s, \MB_CASE_UPPER, $encoding);
|
||||
}
|
||||
public static function mb_substitute_character($c = null)
|
||||
{
|
||||
if (null === $c) {
|
||||
return 'none';
|
||||
}
|
||||
if (0 === strcasecmp($c, 'none')) {
|
||||
return \true;
|
||||
}
|
||||
if (80000 > \PHP_VERSION_ID) {
|
||||
return \false;
|
||||
}
|
||||
if (\is_int($c) || 'long' === $c || 'entity' === $c) {
|
||||
return \false;
|
||||
}
|
||||
throw new \ValueError('Argument #1 ($substitute_character) must be "none", "long", "entity" or a valid codepoint');
|
||||
}
|
||||
public static function mb_substr($s, $start, $length = null, $encoding = null)
|
||||
{
|
||||
$encoding = self::getEncoding($encoding);
|
||||
if ('CP850' === $encoding || 'ASCII' === $encoding) {
|
||||
return (string) substr($s, $start, null === $length ? 2147483647 : $length);
|
||||
}
|
||||
if ($start < 0) {
|
||||
$start = iconv_strlen($s, $encoding) + $start;
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
}
|
||||
if (null === $length) {
|
||||
$length = 2147483647;
|
||||
} elseif ($length < 0) {
|
||||
$length = iconv_strlen($s, $encoding) + $length - $start;
|
||||
if ($length < 0) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
return (string) iconv_substr($s, $start, $length, $encoding);
|
||||
}
|
||||
public static function mb_stripos($haystack, $needle, $offset = 0, $encoding = null)
|
||||
{
|
||||
[$haystack, $needle] = str_replace(self::SIMPLE_CASE_FOLD[0], self::SIMPLE_CASE_FOLD[1], [self::mb_convert_case($haystack, \MB_CASE_LOWER, $encoding), self::mb_convert_case($needle, \MB_CASE_LOWER, $encoding)]);
|
||||
return self::mb_strpos($haystack, $needle, $offset, $encoding);
|
||||
}
|
||||
public static function mb_stristr($haystack, $needle, $part = \false, $encoding = null)
|
||||
{
|
||||
$pos = self::mb_stripos($haystack, $needle, 0, $encoding);
|
||||
return self::getSubpart($pos, $part, $haystack, $encoding);
|
||||
}
|
||||
public static function mb_strrchr($haystack, $needle, $part = \false, $encoding = null)
|
||||
{
|
||||
$encoding = self::getEncoding($encoding);
|
||||
if ('CP850' === $encoding || 'ASCII' === $encoding) {
|
||||
$pos = strrpos($haystack, $needle);
|
||||
} else {
|
||||
$needle = self::mb_substr($needle, 0, 1, $encoding);
|
||||
$pos = iconv_strrpos($haystack, $needle, $encoding);
|
||||
}
|
||||
return self::getSubpart($pos, $part, $haystack, $encoding);
|
||||
}
|
||||
public static function mb_strrichr($haystack, $needle, $part = \false, $encoding = null)
|
||||
{
|
||||
$needle = self::mb_substr($needle, 0, 1, $encoding);
|
||||
$pos = self::mb_strripos($haystack, $needle, $encoding);
|
||||
return self::getSubpart($pos, $part, $haystack, $encoding);
|
||||
}
|
||||
public static function mb_strripos($haystack, $needle, $offset = 0, $encoding = null)
|
||||
{
|
||||
$haystack = self::mb_convert_case($haystack, \MB_CASE_LOWER, $encoding);
|
||||
$needle = self::mb_convert_case($needle, \MB_CASE_LOWER, $encoding);
|
||||
$haystack = str_replace(self::SIMPLE_CASE_FOLD[0], self::SIMPLE_CASE_FOLD[1], $haystack);
|
||||
$needle = str_replace(self::SIMPLE_CASE_FOLD[0], self::SIMPLE_CASE_FOLD[1], $needle);
|
||||
return self::mb_strrpos($haystack, $needle, $offset, $encoding);
|
||||
}
|
||||
public static function mb_strstr($haystack, $needle, $part = \false, $encoding = null)
|
||||
{
|
||||
$pos = strpos($haystack, $needle);
|
||||
if (\false === $pos) {
|
||||
return \false;
|
||||
}
|
||||
if ($part) {
|
||||
return substr($haystack, 0, $pos);
|
||||
}
|
||||
return substr($haystack, $pos);
|
||||
}
|
||||
public static function mb_get_info($type = 'all')
|
||||
{
|
||||
$info = ['internal_encoding' => self::$internalEncoding, 'http_output' => 'pass', 'http_output_conv_mimetypes' => '^(text/|application/xhtml\+xml)', 'func_overload' => 0, 'func_overload_list' => 'no overload', 'mail_charset' => 'UTF-8', 'mail_header_encoding' => 'BASE64', 'mail_body_encoding' => 'BASE64', 'illegal_chars' => 0, 'encoding_translation' => 'Off', 'language' => self::$language, 'detect_order' => self::$encodingList, 'substitute_character' => 'none', 'strict_detection' => 'Off'];
|
||||
if ('all' === $type) {
|
||||
return $info;
|
||||
}
|
||||
if (isset($info[$type])) {
|
||||
return $info[$type];
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
public static function mb_http_input($type = '')
|
||||
{
|
||||
return \false;
|
||||
}
|
||||
public static function mb_http_output($encoding = null)
|
||||
{
|
||||
return null !== $encoding ? 'pass' === $encoding : 'pass';
|
||||
}
|
||||
public static function mb_strwidth($s, $encoding = null)
|
||||
{
|
||||
$encoding = self::getEncoding($encoding);
|
||||
if ('UTF-8' !== $encoding) {
|
||||
$s = iconv($encoding, 'UTF-8//IGNORE', $s);
|
||||
}
|
||||
$s = preg_replace('/[\x{1100}-\x{115F}\x{2329}\x{232A}\x{2E80}-\x{303E}\x{3040}-\x{A4CF}\x{AC00}-\x{D7A3}\x{F900}-\x{FAFF}\x{FE10}-\x{FE19}\x{FE30}-\x{FE6F}\x{FF00}-\x{FF60}\x{FFE0}-\x{FFE6}\x{20000}-\x{2FFFD}\x{30000}-\x{3FFFD}]/u', '', $s, -1, $wide);
|
||||
return ($wide << 1) + iconv_strlen($s, 'UTF-8');
|
||||
}
|
||||
public static function mb_substr_count($haystack, $needle, $encoding = null)
|
||||
{
|
||||
return substr_count($haystack, $needle);
|
||||
}
|
||||
public static function mb_output_handler($contents, $status)
|
||||
{
|
||||
return $contents;
|
||||
}
|
||||
public static function mb_chr($code, $encoding = null)
|
||||
{
|
||||
if (0x80 > $code %= 0x200000) {
|
||||
$s = \chr($code);
|
||||
} elseif (0x800 > $code) {
|
||||
$s = \chr(0xc0 | $code >> 6) . \chr(0x80 | $code & 0x3f);
|
||||
} elseif (0x10000 > $code) {
|
||||
$s = \chr(0xe0 | $code >> 12) . \chr(0x80 | $code >> 6 & 0x3f) . \chr(0x80 | $code & 0x3f);
|
||||
} else {
|
||||
$s = \chr(0xf0 | $code >> 18) . \chr(0x80 | $code >> 12 & 0x3f) . \chr(0x80 | $code >> 6 & 0x3f) . \chr(0x80 | $code & 0x3f);
|
||||
}
|
||||
if ('UTF-8' !== $encoding = self::getEncoding($encoding)) {
|
||||
$s = mb_convert_encoding($s, $encoding, 'UTF-8');
|
||||
}
|
||||
return $s;
|
||||
}
|
||||
public static function mb_ord($s, $encoding = null)
|
||||
{
|
||||
if ('UTF-8' !== $encoding = self::getEncoding($encoding)) {
|
||||
$s = mb_convert_encoding($s, 'UTF-8', $encoding);
|
||||
}
|
||||
if (1 === \strlen($s)) {
|
||||
return \ord($s);
|
||||
}
|
||||
$code = ($s = unpack('C*', substr($s, 0, 4))) ? $s[1] : 0;
|
||||
if (0xf0 <= $code) {
|
||||
return ($code - 0xf0 << 18) + ($s[2] - 0x80 << 12) + ($s[3] - 0x80 << 6) + $s[4] - 0x80;
|
||||
}
|
||||
if (0xe0 <= $code) {
|
||||
return ($code - 0xe0 << 12) + ($s[2] - 0x80 << 6) + $s[3] - 0x80;
|
||||
}
|
||||
if (0xc0 <= $code) {
|
||||
return ($code - 0xc0 << 6) + $s[2] - 0x80;
|
||||
}
|
||||
return $code;
|
||||
}
|
||||
public static function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = \STR_PAD_RIGHT, ?string $encoding = null): string
|
||||
{
|
||||
if (!\in_array($pad_type, [\STR_PAD_RIGHT, \STR_PAD_LEFT, \STR_PAD_BOTH], \true)) {
|
||||
throw new \ValueError('mb_str_pad(): Argument #4 ($pad_type) must be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH');
|
||||
}
|
||||
if (null === $encoding) {
|
||||
$encoding = self::mb_internal_encoding();
|
||||
} else {
|
||||
self::assertEncoding($encoding, 'mb_str_pad(): Argument #5 ($encoding) must be a valid encoding, "%s" given');
|
||||
}
|
||||
if (self::mb_strlen($pad_string, $encoding) <= 0) {
|
||||
throw new \ValueError('mb_str_pad(): Argument #3 ($pad_string) must be a non-empty string');
|
||||
}
|
||||
$paddingRequired = $length - self::mb_strlen($string, $encoding);
|
||||
if ($paddingRequired < 1) {
|
||||
return $string;
|
||||
}
|
||||
switch ($pad_type) {
|
||||
case \STR_PAD_LEFT:
|
||||
return self::mb_substr(str_repeat($pad_string, $paddingRequired), 0, $paddingRequired, $encoding) . $string;
|
||||
case \STR_PAD_RIGHT:
|
||||
return $string . self::mb_substr(str_repeat($pad_string, $paddingRequired), 0, $paddingRequired, $encoding);
|
||||
default:
|
||||
$leftPaddingLength = floor($paddingRequired / 2);
|
||||
$rightPaddingLength = $paddingRequired - $leftPaddingLength;
|
||||
return self::mb_substr(str_repeat($pad_string, $leftPaddingLength), 0, $leftPaddingLength, $encoding) . $string . self::mb_substr(str_repeat($pad_string, $rightPaddingLength), 0, $rightPaddingLength, $encoding);
|
||||
}
|
||||
}
|
||||
public static function mb_ucfirst(string $string, ?string $encoding = null): string
|
||||
{
|
||||
if (null === $encoding) {
|
||||
$encoding = self::mb_internal_encoding();
|
||||
} else {
|
||||
self::assertEncoding($encoding, 'mb_ucfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given');
|
||||
}
|
||||
$firstChar = mb_substr($string, 0, 1, $encoding);
|
||||
$firstChar = mb_convert_case($firstChar, \MB_CASE_TITLE, $encoding);
|
||||
return $firstChar . mb_substr($string, 1, null, $encoding);
|
||||
}
|
||||
public static function mb_lcfirst(string $string, ?string $encoding = null): string
|
||||
{
|
||||
if (null === $encoding) {
|
||||
$encoding = self::mb_internal_encoding();
|
||||
} else {
|
||||
self::assertEncoding($encoding, 'mb_lcfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given');
|
||||
}
|
||||
$firstChar = mb_substr($string, 0, 1, $encoding);
|
||||
$firstChar = mb_convert_case($firstChar, \MB_CASE_LOWER, $encoding);
|
||||
return $firstChar . mb_substr($string, 1, null, $encoding);
|
||||
}
|
||||
private static function getSubpart($pos, $part, $haystack, $encoding)
|
||||
{
|
||||
if (\false === $pos) {
|
||||
return \false;
|
||||
}
|
||||
if ($part) {
|
||||
return self::mb_substr($haystack, 0, $pos, $encoding);
|
||||
}
|
||||
return self::mb_substr($haystack, $pos, null, $encoding);
|
||||
}
|
||||
private static function html_encoding_callback(array $m)
|
||||
{
|
||||
$i = 1;
|
||||
$entities = '';
|
||||
$m = unpack('C*', htmlentities($m[0], \ENT_COMPAT, 'UTF-8'));
|
||||
while (isset($m[$i])) {
|
||||
if (0x80 > $m[$i]) {
|
||||
$entities .= \chr($m[$i++]);
|
||||
continue;
|
||||
}
|
||||
if (0xf0 <= $m[$i]) {
|
||||
$c = ($m[$i++] - 0xf0 << 18) + ($m[$i++] - 0x80 << 12) + ($m[$i++] - 0x80 << 6) + $m[$i++] - 0x80;
|
||||
} elseif (0xe0 <= $m[$i]) {
|
||||
$c = ($m[$i++] - 0xe0 << 12) + ($m[$i++] - 0x80 << 6) + $m[$i++] - 0x80;
|
||||
} else {
|
||||
$c = ($m[$i++] - 0xc0 << 6) + $m[$i++] - 0x80;
|
||||
}
|
||||
$entities .= '&#' . $c . ';';
|
||||
}
|
||||
return $entities;
|
||||
}
|
||||
private static function title_case(array $s)
|
||||
{
|
||||
return self::mb_convert_case($s[1], \MB_CASE_UPPER, 'UTF-8') . self::mb_convert_case($s[2], \MB_CASE_LOWER, 'UTF-8');
|
||||
}
|
||||
private static function getData($file)
|
||||
{
|
||||
if (file_exists($file = __DIR__ . '/Resources/unidata/' . $file . '.php')) {
|
||||
return require $file;
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
private static function getEncoding($encoding)
|
||||
{
|
||||
if (null === $encoding) {
|
||||
return self::$internalEncoding;
|
||||
}
|
||||
if ('UTF-8' === $encoding) {
|
||||
return 'UTF-8';
|
||||
}
|
||||
$encoding = strtoupper($encoding);
|
||||
if ('8BIT' === $encoding || 'BINARY' === $encoding) {
|
||||
return 'CP850';
|
||||
}
|
||||
if ('UTF8' === $encoding) {
|
||||
return 'UTF-8';
|
||||
}
|
||||
return $encoding;
|
||||
}
|
||||
public static function mb_trim(string $string, ?string $characters = null, ?string $encoding = null): string
|
||||
{
|
||||
return self::mb_internal_trim('{^[%s]+|[%1$s]+$}Du', $string, $characters, $encoding, __FUNCTION__);
|
||||
}
|
||||
public static function mb_ltrim(string $string, ?string $characters = null, ?string $encoding = null): string
|
||||
{
|
||||
return self::mb_internal_trim('{^[%s]+}Du', $string, $characters, $encoding, __FUNCTION__);
|
||||
}
|
||||
public static function mb_rtrim(string $string, ?string $characters = null, ?string $encoding = null): string
|
||||
{
|
||||
return self::mb_internal_trim('{[%s]+$}Du', $string, $characters, $encoding, __FUNCTION__);
|
||||
}
|
||||
private static function mb_internal_trim(string $regex, string $string, ?string $characters, ?string $encoding, string $function): string
|
||||
{
|
||||
if (null === $encoding) {
|
||||
$encoding = self::mb_internal_encoding();
|
||||
} else {
|
||||
self::assertEncoding($encoding, $function . '(): Argument #3 ($encoding) must be a valid encoding, "%s" given');
|
||||
}
|
||||
if ('' === $characters) {
|
||||
return null === $encoding ? $string : self::mb_convert_encoding($string, $encoding);
|
||||
}
|
||||
if ('UTF-8' === $encoding) {
|
||||
$encoding = null;
|
||||
if (!preg_match('//u', $string)) {
|
||||
$string = @iconv('UTF-8', 'UTF-8//IGNORE', $string);
|
||||
}
|
||||
if (null !== $characters && !preg_match('//u', $characters)) {
|
||||
$characters = @iconv('UTF-8', 'UTF-8//IGNORE', $characters);
|
||||
}
|
||||
} else {
|
||||
$string = iconv($encoding, 'UTF-8//IGNORE', $string);
|
||||
if (null !== $characters) {
|
||||
$characters = iconv($encoding, 'UTF-8//IGNORE', $characters);
|
||||
}
|
||||
}
|
||||
if (null === $characters) {
|
||||
$characters = "\\0 \f\n\r\t\v
";
|
||||
} else {
|
||||
$characters = preg_quote($characters);
|
||||
}
|
||||
$string = preg_replace(sprintf($regex, $characters), '', $string);
|
||||
if (null === $encoding) {
|
||||
return $string;
|
||||
}
|
||||
return iconv('UTF-8', $encoding . '//IGNORE', $string);
|
||||
}
|
||||
private static function assertEncoding(string $encoding, string $errorFormat): void
|
||||
{
|
||||
try {
|
||||
$validEncoding = @self::mb_check_encoding('', $encoding);
|
||||
} catch (\ValueError $e) {
|
||||
throw new \ValueError(sprintf($errorFormat, $encoding));
|
||||
}
|
||||
// BC for PHP 7.3 and lower
|
||||
if (!$validEncoding) {
|
||||
throw new \ValueError(sprintf($errorFormat, $encoding));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
Symfony Polyfill / Mbstring
|
||||
===========================
|
||||
|
||||
This component provides a partial, native PHP implementation for the
|
||||
[Mbstring](https://php.net/mbstring) extension.
|
||||
|
||||
More information can be found in the
|
||||
[main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md).
|
||||
|
||||
License
|
||||
=======
|
||||
|
||||
This library is released under the [MIT license](LICENSE).
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace JooosiFonDeps;
|
||||
|
||||
return ['İ' => 'i̇', 'µ' => 'μ', 'ſ' => 's', 'ͅ' => 'ι', 'ς' => 'σ', 'ϐ' => 'β', 'ϑ' => 'θ', 'ϕ' => 'φ', 'ϖ' => 'π', 'ϰ' => 'κ', 'ϱ' => 'ρ', 'ϵ' => 'ε', 'ẛ' => 'ṡ', 'ι' => 'ι', 'ß' => 'ss', 'ʼn' => 'ʼn', 'ǰ' => 'ǰ', 'ΐ' => 'ΐ', 'ΰ' => 'ΰ', 'և' => 'եւ', 'ẖ' => 'ẖ', 'ẗ' => 'ẗ', 'ẘ' => 'ẘ', 'ẙ' => 'ẙ', 'ẚ' => 'aʾ', 'ẞ' => 'ss', 'ὐ' => 'ὐ', 'ὒ' => 'ὒ', 'ὔ' => 'ὔ', 'ὖ' => 'ὖ', 'ᾀ' => 'ἀι', 'ᾁ' => 'ἁι', 'ᾂ' => 'ἂι', 'ᾃ' => 'ἃι', 'ᾄ' => 'ἄι', 'ᾅ' => 'ἅι', 'ᾆ' => 'ἆι', 'ᾇ' => 'ἇι', 'ᾈ' => 'ἀι', 'ᾉ' => 'ἁι', 'ᾊ' => 'ἂι', 'ᾋ' => 'ἃι', 'ᾌ' => 'ἄι', 'ᾍ' => 'ἅι', 'ᾎ' => 'ἆι', 'ᾏ' => 'ἇι', 'ᾐ' => 'ἠι', 'ᾑ' => 'ἡι', 'ᾒ' => 'ἢι', 'ᾓ' => 'ἣι', 'ᾔ' => 'ἤι', 'ᾕ' => 'ἥι', 'ᾖ' => 'ἦι', 'ᾗ' => 'ἧι', 'ᾘ' => 'ἠι', 'ᾙ' => 'ἡι', 'ᾚ' => 'ἢι', 'ᾛ' => 'ἣι', 'ᾜ' => 'ἤι', 'ᾝ' => 'ἥι', 'ᾞ' => 'ἦι', 'ᾟ' => 'ἧι', 'ᾠ' => 'ὠι', 'ᾡ' => 'ὡι', 'ᾢ' => 'ὢι', 'ᾣ' => 'ὣι', 'ᾤ' => 'ὤι', 'ᾥ' => 'ὥι', 'ᾦ' => 'ὦι', 'ᾧ' => 'ὧι', 'ᾨ' => 'ὠι', 'ᾩ' => 'ὡι', 'ᾪ' => 'ὢι', 'ᾫ' => 'ὣι', 'ᾬ' => 'ὤι', 'ᾭ' => 'ὥι', 'ᾮ' => 'ὦι', 'ᾯ' => 'ὧι', 'ᾲ' => 'ὰι', 'ᾳ' => 'αι', 'ᾴ' => 'άι', 'ᾶ' => 'ᾶ', 'ᾷ' => 'ᾶι', 'ᾼ' => 'αι', 'ῂ' => 'ὴι', 'ῃ' => 'ηι', 'ῄ' => 'ήι', 'ῆ' => 'ῆ', 'ῇ' => 'ῆι', 'ῌ' => 'ηι', 'ῒ' => 'ῒ', 'ῖ' => 'ῖ', 'ῗ' => 'ῗ', 'ῢ' => 'ῢ', 'ῤ' => 'ῤ', 'ῦ' => 'ῦ', 'ῧ' => 'ῧ', 'ῲ' => 'ὼι', 'ῳ' => 'ωι', 'ῴ' => 'ώι', 'ῶ' => 'ῶ', 'ῷ' => 'ῶι', 'ῼ' => 'ωι', 'ff' => 'ff', 'fi' => 'fi', 'fl' => 'fl', 'ffi' => 'ffi', 'ffl' => 'ffl', 'ſt' => 'st', 'st' => 'st', 'ﬓ' => 'մն', 'ﬔ' => 'մե', 'ﬕ' => 'մի', 'ﬖ' => 'վն', 'ﬗ' => 'մխ'];
|
||||
Vendored
+5
File diff suppressed because one or more lines are too long
+6
File diff suppressed because one or more lines are too long
Vendored
+5
File diff suppressed because one or more lines are too long
+172
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Symfony\Polyfill\Mbstring as p;
|
||||
|
||||
if (\PHP_VERSION_ID >= 80000) {
|
||||
return require __DIR__.'/bootstrap80.php';
|
||||
}
|
||||
|
||||
if (!function_exists('mb_convert_encoding')) {
|
||||
function mb_convert_encoding($string, $to_encoding, $from_encoding = null) { return p\Mbstring::mb_convert_encoding($string, $to_encoding, $from_encoding); }
|
||||
}
|
||||
if (!function_exists('mb_decode_mimeheader')) {
|
||||
function mb_decode_mimeheader($string) { return p\Mbstring::mb_decode_mimeheader($string); }
|
||||
}
|
||||
if (!function_exists('mb_encode_mimeheader')) {
|
||||
function mb_encode_mimeheader($string, $charset = null, $transfer_encoding = null, $newline = "\r\n", $indent = 0) { return p\Mbstring::mb_encode_mimeheader($string, $charset, $transfer_encoding, $newline, $indent); }
|
||||
}
|
||||
if (!function_exists('mb_decode_numericentity')) {
|
||||
function mb_decode_numericentity($string, $map, $encoding = null) { return p\Mbstring::mb_decode_numericentity($string, $map, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_encode_numericentity')) {
|
||||
function mb_encode_numericentity($string, $map, $encoding = null, $hex = false) { return p\Mbstring::mb_encode_numericentity($string, $map, $encoding, $hex); }
|
||||
}
|
||||
if (!function_exists('mb_convert_case')) {
|
||||
function mb_convert_case($string, $mode, $encoding = null) { return p\Mbstring::mb_convert_case($string, $mode, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_internal_encoding')) {
|
||||
function mb_internal_encoding($encoding = null) { return p\Mbstring::mb_internal_encoding($encoding); }
|
||||
}
|
||||
if (!function_exists('mb_language')) {
|
||||
function mb_language($language = null) { return p\Mbstring::mb_language($language); }
|
||||
}
|
||||
if (!function_exists('mb_list_encodings')) {
|
||||
function mb_list_encodings() { return p\Mbstring::mb_list_encodings(); }
|
||||
}
|
||||
if (!function_exists('mb_encoding_aliases')) {
|
||||
function mb_encoding_aliases($encoding) { return p\Mbstring::mb_encoding_aliases($encoding); }
|
||||
}
|
||||
if (!function_exists('mb_check_encoding')) {
|
||||
function mb_check_encoding($value = null, $encoding = null) { return p\Mbstring::mb_check_encoding($value, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_detect_encoding')) {
|
||||
function mb_detect_encoding($string, $encodings = null, $strict = false) { return p\Mbstring::mb_detect_encoding($string, $encodings, $strict); }
|
||||
}
|
||||
if (!function_exists('mb_detect_order')) {
|
||||
function mb_detect_order($encoding = null) { return p\Mbstring::mb_detect_order($encoding); }
|
||||
}
|
||||
if (!function_exists('mb_parse_str')) {
|
||||
function mb_parse_str($string, &$result = []) { parse_str($string, $result); return (bool) $result; }
|
||||
}
|
||||
if (!function_exists('mb_strlen')) {
|
||||
function mb_strlen($string, $encoding = null) { return p\Mbstring::mb_strlen($string, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strpos')) {
|
||||
function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strpos($haystack, $needle, $offset, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strtolower')) {
|
||||
function mb_strtolower($string, $encoding = null) { return p\Mbstring::mb_strtolower($string, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strtoupper')) {
|
||||
function mb_strtoupper($string, $encoding = null) { return p\Mbstring::mb_strtoupper($string, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_substitute_character')) {
|
||||
function mb_substitute_character($substitute_character = null) { return p\Mbstring::mb_substitute_character($substitute_character); }
|
||||
}
|
||||
if (!function_exists('mb_substr')) {
|
||||
function mb_substr($string, $start, $length = 2147483647, $encoding = null) { return p\Mbstring::mb_substr($string, $start, $length, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_stripos')) {
|
||||
function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_stripos($haystack, $needle, $offset, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_stristr')) {
|
||||
function mb_stristr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_stristr($haystack, $needle, $before_needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strrchr')) {
|
||||
function mb_strrchr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strrchr($haystack, $needle, $before_needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strrichr')) {
|
||||
function mb_strrichr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strrichr($haystack, $needle, $before_needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strripos')) {
|
||||
function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strripos($haystack, $needle, $offset, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strrpos')) {
|
||||
function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strrpos($haystack, $needle, $offset, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strstr')) {
|
||||
function mb_strstr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strstr($haystack, $needle, $before_needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_get_info')) {
|
||||
function mb_get_info($type = 'all') { return p\Mbstring::mb_get_info($type); }
|
||||
}
|
||||
if (!function_exists('mb_http_output')) {
|
||||
function mb_http_output($encoding = null) { return p\Mbstring::mb_http_output($encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strwidth')) {
|
||||
function mb_strwidth($string, $encoding = null) { return p\Mbstring::mb_strwidth($string, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_substr_count')) {
|
||||
function mb_substr_count($haystack, $needle, $encoding = null) { return p\Mbstring::mb_substr_count($haystack, $needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_output_handler')) {
|
||||
function mb_output_handler($string, $status) { return p\Mbstring::mb_output_handler($string, $status); }
|
||||
}
|
||||
if (!function_exists('mb_http_input')) {
|
||||
function mb_http_input($type = null) { return p\Mbstring::mb_http_input($type); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_convert_variables')) {
|
||||
function mb_convert_variables($to_encoding, $from_encoding, &...$vars) { return p\Mbstring::mb_convert_variables($to_encoding, $from_encoding, ...$vars); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_ord')) {
|
||||
function mb_ord($string, $encoding = null) { return p\Mbstring::mb_ord($string, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_chr')) {
|
||||
function mb_chr($codepoint, $encoding = null) { return p\Mbstring::mb_chr($codepoint, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_scrub')) {
|
||||
function mb_scrub($string, $encoding = null) { $encoding = null === $encoding ? mb_internal_encoding() : $encoding; return mb_convert_encoding($string, $encoding, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_str_split')) {
|
||||
function mb_str_split($string, $length = 1, $encoding = null) { return p\Mbstring::mb_str_split($string, $length, $encoding); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_str_pad')) {
|
||||
function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = STR_PAD_RIGHT, ?string $encoding = null): string { return p\Mbstring::mb_str_pad($string, $length, $pad_string, $pad_type, $encoding); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_ucfirst')) {
|
||||
function mb_ucfirst(string $string, ?string $encoding = null): string { return p\Mbstring::mb_ucfirst($string, $encoding); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_lcfirst')) {
|
||||
function mb_lcfirst(string $string, ?string $encoding = null): string { return p\Mbstring::mb_lcfirst($string, $encoding); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_trim')) {
|
||||
function mb_trim(string $string, ?string $characters = null, ?string $encoding = null): string { return p\Mbstring::mb_trim($string, $characters, $encoding); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_ltrim')) {
|
||||
function mb_ltrim(string $string, ?string $characters = null, ?string $encoding = null): string { return p\Mbstring::mb_ltrim($string, $characters, $encoding); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_rtrim')) {
|
||||
function mb_rtrim(string $string, ?string $characters = null, ?string $encoding = null): string { return p\Mbstring::mb_rtrim($string, $characters, $encoding); }
|
||||
}
|
||||
|
||||
|
||||
if (extension_loaded('mbstring')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!defined('MB_CASE_UPPER')) {
|
||||
define('MB_CASE_UPPER', 0);
|
||||
}
|
||||
if (!defined('MB_CASE_LOWER')) {
|
||||
define('MB_CASE_LOWER', 1);
|
||||
}
|
||||
if (!defined('MB_CASE_TITLE')) {
|
||||
define('MB_CASE_TITLE', 2);
|
||||
}
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Symfony\Polyfill\Mbstring as p;
|
||||
|
||||
if (!function_exists('mb_convert_encoding')) {
|
||||
function mb_convert_encoding(array|string|null $string, ?string $to_encoding, array|string|null $from_encoding = null): array|string|false { return p\Mbstring::mb_convert_encoding($string ?? '', (string) $to_encoding, $from_encoding); }
|
||||
}
|
||||
if (!function_exists('mb_decode_mimeheader')) {
|
||||
function mb_decode_mimeheader(?string $string): string { return p\Mbstring::mb_decode_mimeheader((string) $string); }
|
||||
}
|
||||
if (!function_exists('mb_encode_mimeheader')) {
|
||||
function mb_encode_mimeheader(?string $string, ?string $charset = null, ?string $transfer_encoding = null, ?string $newline = "\r\n", ?int $indent = 0): string { return p\Mbstring::mb_encode_mimeheader((string) $string, $charset, $transfer_encoding, (string) $newline, (int) $indent); }
|
||||
}
|
||||
if (!function_exists('mb_decode_numericentity')) {
|
||||
function mb_decode_numericentity(?string $string, array $map, ?string $encoding = null): string { return p\Mbstring::mb_decode_numericentity((string) $string, $map, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_encode_numericentity')) {
|
||||
function mb_encode_numericentity(?string $string, array $map, ?string $encoding = null, ?bool $hex = false): string { return p\Mbstring::mb_encode_numericentity((string) $string, $map, $encoding, (bool) $hex); }
|
||||
}
|
||||
if (!function_exists('mb_convert_case')) {
|
||||
function mb_convert_case(?string $string, ?int $mode, ?string $encoding = null): string { return p\Mbstring::mb_convert_case((string) $string, (int) $mode, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_internal_encoding')) {
|
||||
function mb_internal_encoding(?string $encoding = null): string|bool { return p\Mbstring::mb_internal_encoding($encoding); }
|
||||
}
|
||||
if (!function_exists('mb_language')) {
|
||||
function mb_language(?string $language = null): string|bool { return p\Mbstring::mb_language($language); }
|
||||
}
|
||||
if (!function_exists('mb_list_encodings')) {
|
||||
function mb_list_encodings(): array { return p\Mbstring::mb_list_encodings(); }
|
||||
}
|
||||
if (!function_exists('mb_encoding_aliases')) {
|
||||
function mb_encoding_aliases(?string $encoding): array { return p\Mbstring::mb_encoding_aliases((string) $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_check_encoding')) {
|
||||
function mb_check_encoding(array|string|null $value = null, ?string $encoding = null): bool { return p\Mbstring::mb_check_encoding($value, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_detect_encoding')) {
|
||||
function mb_detect_encoding(?string $string, array|string|null $encodings = null, ?bool $strict = false): string|false { return p\Mbstring::mb_detect_encoding((string) $string, $encodings, (bool) $strict); }
|
||||
}
|
||||
if (!function_exists('mb_detect_order')) {
|
||||
function mb_detect_order(array|string|null $encoding = null): array|bool { return p\Mbstring::mb_detect_order($encoding); }
|
||||
}
|
||||
if (!function_exists('mb_parse_str')) {
|
||||
function mb_parse_str(?string $string, &$result = []): bool { parse_str((string) $string, $result); return (bool) $result; }
|
||||
}
|
||||
if (!function_exists('mb_strlen')) {
|
||||
function mb_strlen(?string $string, ?string $encoding = null): int { return p\Mbstring::mb_strlen((string) $string, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strpos')) {
|
||||
function mb_strpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strpos((string) $haystack, (string) $needle, (int) $offset, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strtolower')) {
|
||||
function mb_strtolower(?string $string, ?string $encoding = null): string { return p\Mbstring::mb_strtolower((string) $string, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strtoupper')) {
|
||||
function mb_strtoupper(?string $string, ?string $encoding = null): string { return p\Mbstring::mb_strtoupper((string) $string, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_substitute_character')) {
|
||||
function mb_substitute_character(string|int|null $substitute_character = null): string|int|bool { return p\Mbstring::mb_substitute_character($substitute_character); }
|
||||
}
|
||||
if (!function_exists('mb_substr')) {
|
||||
function mb_substr(?string $string, ?int $start, ?int $length = null, ?string $encoding = null): string { return p\Mbstring::mb_substr((string) $string, (int) $start, $length, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_stripos')) {
|
||||
function mb_stripos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_stripos((string) $haystack, (string) $needle, (int) $offset, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_stristr')) {
|
||||
function mb_stristr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_stristr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strrchr')) {
|
||||
function mb_strrchr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strrchr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strrichr')) {
|
||||
function mb_strrichr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strrichr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strripos')) {
|
||||
function mb_strripos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strripos((string) $haystack, (string) $needle, (int) $offset, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strrpos')) {
|
||||
function mb_strrpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strrpos((string) $haystack, (string) $needle, (int) $offset, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strstr')) {
|
||||
function mb_strstr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strstr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_get_info')) {
|
||||
function mb_get_info(?string $type = 'all'): array|string|int|false|null { return p\Mbstring::mb_get_info((string) $type); }
|
||||
}
|
||||
if (!function_exists('mb_http_output')) {
|
||||
function mb_http_output(?string $encoding = null): string|bool { return p\Mbstring::mb_http_output($encoding); }
|
||||
}
|
||||
if (!function_exists('mb_strwidth')) {
|
||||
function mb_strwidth(?string $string, ?string $encoding = null): int { return p\Mbstring::mb_strwidth((string) $string, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_substr_count')) {
|
||||
function mb_substr_count(?string $haystack, ?string $needle, ?string $encoding = null): int { return p\Mbstring::mb_substr_count((string) $haystack, (string) $needle, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_output_handler')) {
|
||||
function mb_output_handler(?string $string, ?int $status): string { return p\Mbstring::mb_output_handler((string) $string, (int) $status); }
|
||||
}
|
||||
if (!function_exists('mb_http_input')) {
|
||||
function mb_http_input(?string $type = null): array|string|false { return p\Mbstring::mb_http_input($type); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_convert_variables')) {
|
||||
function mb_convert_variables(?string $to_encoding, array|string|null $from_encoding, mixed &$var, mixed &...$vars): string|false { return p\Mbstring::mb_convert_variables((string) $to_encoding, $from_encoding ?? '', $var, ...$vars); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_ord')) {
|
||||
function mb_ord(?string $string, ?string $encoding = null): int|false { return p\Mbstring::mb_ord((string) $string, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_chr')) {
|
||||
function mb_chr(?int $codepoint, ?string $encoding = null): string|false { return p\Mbstring::mb_chr((int) $codepoint, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_scrub')) {
|
||||
function mb_scrub(?string $string, ?string $encoding = null): string { $encoding ??= mb_internal_encoding(); return mb_convert_encoding((string) $string, $encoding, $encoding); }
|
||||
}
|
||||
if (!function_exists('mb_str_split')) {
|
||||
function mb_str_split(?string $string, ?int $length = 1, ?string $encoding = null): array { return p\Mbstring::mb_str_split((string) $string, (int) $length, $encoding); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_str_pad')) {
|
||||
function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = STR_PAD_RIGHT, ?string $encoding = null): string { return p\Mbstring::mb_str_pad($string, $length, $pad_string, $pad_type, $encoding); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_ucfirst')) {
|
||||
function mb_ucfirst(string $string, ?string $encoding = null): string { return p\Mbstring::mb_ucfirst($string, $encoding); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_lcfirst')) {
|
||||
function mb_lcfirst(string $string, ?string $encoding = null): string { return p\Mbstring::mb_lcfirst($string, $encoding); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_trim')) {
|
||||
function mb_trim(string $string, ?string $characters = null, ?string $encoding = null): string { return p\Mbstring::mb_trim($string, $characters, $encoding); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_ltrim')) {
|
||||
function mb_ltrim(string $string, ?string $characters = null, ?string $encoding = null): string { return p\Mbstring::mb_ltrim($string, $characters, $encoding); }
|
||||
}
|
||||
|
||||
if (!function_exists('mb_rtrim')) {
|
||||
function mb_rtrim(string $string, ?string $characters = null, ?string $encoding = null): string { return p\Mbstring::mb_rtrim($string, $characters, $encoding); }
|
||||
}
|
||||
|
||||
if (extension_loaded('mbstring')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!defined('MB_CASE_UPPER')) {
|
||||
define('MB_CASE_UPPER', 0);
|
||||
}
|
||||
if (!defined('MB_CASE_LOWER')) {
|
||||
define('MB_CASE_LOWER', 1);
|
||||
}
|
||||
if (!defined('MB_CASE_TITLE')) {
|
||||
define('MB_CASE_TITLE', 2);
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"name": "symfony\/polyfill-mbstring",
|
||||
"type": "library",
|
||||
"description": "Symfony polyfill for the Mbstring extension",
|
||||
"keywords": [
|
||||
"polyfill",
|
||||
"shim",
|
||||
"compatibility",
|
||||
"portable",
|
||||
"mbstring"
|
||||
],
|
||||
"homepage": "https:\/\/symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https:\/\/symfony.com\/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.2",
|
||||
"ext-iconv": "*"
|
||||
},
|
||||
"provide": {
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Mbstring\\": ""
|
||||
},
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
]
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "For best performance"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"name": "symfony\/polyfill",
|
||||
"url": "https:\/\/github.com\/symfony\/polyfill"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2020-present Fabien Potencier
|
||||
|
||||
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:
|
||||
|
||||
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,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Symfony\Polyfill\Php80;
|
||||
|
||||
/**
|
||||
* @author Ion Bazan <ion.bazan@gmail.com>
|
||||
* @author Nico Oelgart <nicoswd@gmail.com>
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class Php80
|
||||
{
|
||||
public static function fdiv(float $dividend, float $divisor): float
|
||||
{
|
||||
return @($dividend / $divisor);
|
||||
}
|
||||
public static function get_debug_type($value): string
|
||||
{
|
||||
switch (\true) {
|
||||
case null === $value:
|
||||
return 'null';
|
||||
case \is_bool($value):
|
||||
return 'bool';
|
||||
case \is_string($value):
|
||||
return 'string';
|
||||
case \is_array($value):
|
||||
return 'array';
|
||||
case \is_int($value):
|
||||
return 'int';
|
||||
case \is_float($value):
|
||||
return 'float';
|
||||
case \is_object($value):
|
||||
break;
|
||||
case $value instanceof \__PHP_Incomplete_Class:
|
||||
return '__PHP_Incomplete_Class';
|
||||
default:
|
||||
if (null === $type = @get_resource_type($value)) {
|
||||
return 'unknown';
|
||||
}
|
||||
if ('Unknown' === $type) {
|
||||
$type = 'closed';
|
||||
}
|
||||
return "resource ({$type})";
|
||||
}
|
||||
$class = \get_class($value);
|
||||
if (\false === strpos($class, '@')) {
|
||||
return $class;
|
||||
}
|
||||
return ((get_parent_class($class) ?: key(class_implements($class))) ?: 'class') . '@anonymous';
|
||||
}
|
||||
public static function get_resource_id($res): int
|
||||
{
|
||||
if (!\is_resource($res) && null === @get_resource_type($res)) {
|
||||
throw new \TypeError(sprintf('Argument 1 passed to get_resource_id() must be of the type resource, %s given', get_debug_type($res)));
|
||||
}
|
||||
return (int) $res;
|
||||
}
|
||||
public static function preg_last_error_msg(): string
|
||||
{
|
||||
switch (preg_last_error()) {
|
||||
case \PREG_INTERNAL_ERROR:
|
||||
return 'Internal error';
|
||||
case \PREG_BAD_UTF8_ERROR:
|
||||
return 'Malformed UTF-8 characters, possibly incorrectly encoded';
|
||||
case \PREG_BAD_UTF8_OFFSET_ERROR:
|
||||
return 'The offset did not correspond to the beginning of a valid UTF-8 code point';
|
||||
case \PREG_BACKTRACK_LIMIT_ERROR:
|
||||
return 'Backtrack limit exhausted';
|
||||
case \PREG_RECURSION_LIMIT_ERROR:
|
||||
return 'Recursion limit exhausted';
|
||||
case \PREG_JIT_STACKLIMIT_ERROR:
|
||||
return 'JIT stack limit exhausted';
|
||||
case \PREG_NO_ERROR:
|
||||
return 'No error';
|
||||
default:
|
||||
return 'Unknown error';
|
||||
}
|
||||
}
|
||||
public static function str_contains(string $haystack, string $needle): bool
|
||||
{
|
||||
return '' === $needle || \false !== strpos($haystack, $needle);
|
||||
}
|
||||
public static function str_starts_with(string $haystack, string $needle): bool
|
||||
{
|
||||
return 0 === strncmp($haystack, $needle, \strlen($needle));
|
||||
}
|
||||
public static function str_ends_with(string $haystack, string $needle): bool
|
||||
{
|
||||
if ('' === $needle || $needle === $haystack) {
|
||||
return \true;
|
||||
}
|
||||
if ('' === $haystack) {
|
||||
return \false;
|
||||
}
|
||||
$needleLength = \strlen($needle);
|
||||
return $needleLength <= \strlen($haystack) && 0 === substr_compare($haystack, $needle, -$needleLength);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Symfony\Polyfill\Php80;
|
||||
|
||||
/**
|
||||
* @author Fedonyuk Anton <info@ensostudio.ru>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class PhpToken implements \Stringable
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $text;
|
||||
/**
|
||||
* @var -1|positive-int
|
||||
*/
|
||||
public $line;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $pos;
|
||||
/**
|
||||
* @param -1|positive-int $line
|
||||
*/
|
||||
public function __construct(int $id, string $text, int $line = -1, int $position = -1)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->text = $text;
|
||||
$this->line = $line;
|
||||
$this->pos = $position;
|
||||
}
|
||||
public function getTokenName(): ?string
|
||||
{
|
||||
if ('UNKNOWN' === $name = token_name($this->id)) {
|
||||
$name = \strlen($this->text) > 1 || \ord($this->text) < 32 ? null : $this->text;
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
/**
|
||||
* @param int|string|array $kind
|
||||
*/
|
||||
public function is($kind): bool
|
||||
{
|
||||
foreach ((array) $kind as $value) {
|
||||
if (\in_array($value, [$this->id, $this->text], \true)) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
public function isIgnorable(): bool
|
||||
{
|
||||
return \in_array($this->id, [\T_WHITESPACE, \T_COMMENT, \T_DOC_COMMENT, \T_OPEN_TAG], \true);
|
||||
}
|
||||
public function __toString(): string
|
||||
{
|
||||
return (string) $this->text;
|
||||
}
|
||||
/**
|
||||
* @return list<static>
|
||||
*/
|
||||
public static function tokenize(string $code, int $flags = 0): array
|
||||
{
|
||||
$line = 1;
|
||||
$position = 0;
|
||||
$tokens = token_get_all($code, $flags);
|
||||
foreach ($tokens as $index => $token) {
|
||||
if (\is_string($token)) {
|
||||
$id = \ord($token);
|
||||
$text = $token;
|
||||
} else {
|
||||
[$id, $text, $line] = $token;
|
||||
}
|
||||
$tokens[$index] = new static($id, $text, $line, $position);
|
||||
$position += \strlen($text);
|
||||
}
|
||||
return $tokens;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
Symfony Polyfill / Php80
|
||||
========================
|
||||
|
||||
This component provides features added to PHP 8.0 core:
|
||||
|
||||
- [`Stringable`](https://php.net/stringable) interface
|
||||
- [`fdiv`](https://php.net/fdiv)
|
||||
- [`ValueError`](https://php.net/valueerror) class
|
||||
- [`UnhandledMatchError`](https://php.net/unhandledmatcherror) class
|
||||
- `FILTER_VALIDATE_BOOL` constant
|
||||
- [`get_debug_type`](https://php.net/get_debug_type)
|
||||
- [`PhpToken`](https://php.net/phptoken) class
|
||||
- [`preg_last_error_msg`](https://php.net/preg_last_error_msg)
|
||||
- [`str_contains`](https://php.net/str_contains)
|
||||
- [`str_starts_with`](https://php.net/str_starts_with)
|
||||
- [`str_ends_with`](https://php.net/str_ends_with)
|
||||
- [`get_resource_id`](https://php.net/get_resource_id)
|
||||
|
||||
More information can be found in the
|
||||
[main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md).
|
||||
|
||||
License
|
||||
=======
|
||||
|
||||
This library is released under the [MIT license](LICENSE).
|
||||
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
#[Attribute(Attribute::TARGET_CLASS)]
|
||||
final class Attribute
|
||||
{
|
||||
public const TARGET_CLASS = 1;
|
||||
public const TARGET_FUNCTION = 2;
|
||||
public const TARGET_METHOD = 4;
|
||||
public const TARGET_PROPERTY = 8;
|
||||
public const TARGET_CLASS_CONSTANT = 16;
|
||||
public const TARGET_PARAMETER = 32;
|
||||
public const TARGET_ALL = 63;
|
||||
public const IS_REPEATABLE = 64;
|
||||
|
||||
/** @var int */
|
||||
public $flags;
|
||||
|
||||
public function __construct(int $flags = self::TARGET_ALL)
|
||||
{
|
||||
$this->flags = $flags;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
if (\PHP_VERSION_ID < 80000 && extension_loaded('tokenizer')) {
|
||||
class PhpToken extends Symfony\Polyfill\Php80\PhpToken
|
||||
{
|
||||
}
|
||||
}
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
if (\PHP_VERSION_ID < 80000) {
|
||||
interface Stringable
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString();
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
if (\PHP_VERSION_ID < 80000) {
|
||||
class UnhandledMatchError extends Error
|
||||
{
|
||||
}
|
||||
}
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
if (\PHP_VERSION_ID < 80000) {
|
||||
class ValueError extends Error
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Symfony\Polyfill\Php80 as p;
|
||||
|
||||
if (\PHP_VERSION_ID >= 80000) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!defined('FILTER_VALIDATE_BOOL') && defined('FILTER_VALIDATE_BOOLEAN')) {
|
||||
define('FILTER_VALIDATE_BOOL', \FILTER_VALIDATE_BOOLEAN);
|
||||
}
|
||||
|
||||
if (!function_exists('fdiv')) {
|
||||
function fdiv(float $num1, float $num2): float { return p\Php80::fdiv($num1, $num2); }
|
||||
}
|
||||
if (!function_exists('preg_last_error_msg')) {
|
||||
function preg_last_error_msg(): string { return p\Php80::preg_last_error_msg(); }
|
||||
}
|
||||
if (!function_exists('str_contains')) {
|
||||
function str_contains(?string $haystack, ?string $needle): bool { return p\Php80::str_contains($haystack ?? '', $needle ?? ''); }
|
||||
}
|
||||
if (!function_exists('str_starts_with')) {
|
||||
function str_starts_with(?string $haystack, ?string $needle): bool { return p\Php80::str_starts_with($haystack ?? '', $needle ?? ''); }
|
||||
}
|
||||
if (!function_exists('str_ends_with')) {
|
||||
function str_ends_with(?string $haystack, ?string $needle): bool { return p\Php80::str_ends_with($haystack ?? '', $needle ?? ''); }
|
||||
}
|
||||
if (!function_exists('get_debug_type')) {
|
||||
function get_debug_type($value): string { return p\Php80::get_debug_type($value); }
|
||||
}
|
||||
if (!function_exists('get_resource_id')) {
|
||||
function get_resource_id($resource): int { return p\Php80::get_resource_id($resource); }
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "symfony\/polyfill-php80",
|
||||
"type": "library",
|
||||
"description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions",
|
||||
"keywords": [
|
||||
"polyfill",
|
||||
"shim",
|
||||
"compatibility",
|
||||
"portable"
|
||||
],
|
||||
"homepage": "https:\/\/symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ion Bazan",
|
||||
"email": "ion.bazan@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https:\/\/symfony.com\/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Php80\\": ""
|
||||
},
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
],
|
||||
"classmap": [
|
||||
"Resources\/stubs"
|
||||
]
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"name": "symfony\/polyfill",
|
||||
"url": "https:\/\/github.com\/symfony\/polyfill"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
5.3.0
|
||||
-----
|
||||
|
||||
* deprecate passing a boolean as the second argument of `PropertyAccessor::__construct()`, expecting a combination of bitwise flags instead
|
||||
|
||||
5.2.0
|
||||
-----
|
||||
|
||||
* deprecated passing a boolean as the first argument of `PropertyAccessor::__construct()`, expecting a combination of bitwise flags instead
|
||||
* added the ability to disable usage of the magic `__get` & `__set` methods
|
||||
|
||||
5.1.0
|
||||
-----
|
||||
|
||||
* Added an `UninitializedPropertyException`
|
||||
* Linking to PropertyInfo extractor to remove a lot of duplicate code
|
||||
|
||||
4.4.0
|
||||
-----
|
||||
|
||||
* deprecated passing `null` as `$defaultLifetime` 2nd argument of `PropertyAccessor::createCache()` method,
|
||||
pass `0` instead
|
||||
|
||||
4.3.0
|
||||
-----
|
||||
|
||||
* added a `$throwExceptionOnInvalidPropertyPath` argument to the PropertyAccessor constructor.
|
||||
* added `enableExceptionOnInvalidPropertyPath()`, `disableExceptionOnInvalidPropertyPath()` and
|
||||
`isExceptionOnInvalidPropertyPath()` methods to `PropertyAccessorBuilder`
|
||||
|
||||
4.0.0
|
||||
-----
|
||||
|
||||
* removed the `StringUtil` class, use `Symfony\Component\Inflector\Inflector`
|
||||
|
||||
3.1.0
|
||||
-----
|
||||
|
||||
* deprecated the `StringUtil` class, use `Symfony\Component\Inflector\Inflector`
|
||||
instead
|
||||
|
||||
2.7.0
|
||||
------
|
||||
|
||||
* `UnexpectedTypeException` now expects three constructor arguments: The invalid property value,
|
||||
the `PropertyPathInterface` object and the current index of the property path.
|
||||
|
||||
2.5.0
|
||||
------
|
||||
|
||||
* allowed non alpha numeric characters in second level and deeper object properties names
|
||||
* [BC BREAK] when accessing an index on an object that does not implement
|
||||
ArrayAccess, a NoSuchIndexException is now thrown instead of the
|
||||
semantically wrong NoSuchPropertyException
|
||||
* [BC BREAK] added isReadable() and isWritable() to PropertyAccessorInterface
|
||||
|
||||
2.3.0
|
||||
------
|
||||
|
||||
* added PropertyAccessorBuilder, to enable or disable the support of "__call"
|
||||
* added support for "__call" in the PropertyAccessor (disabled by default)
|
||||
* [BC BREAK] changed PropertyAccessor to continue its search for a property or
|
||||
method even if a non-public match was found. Before, a PropertyAccessDeniedException
|
||||
was thrown in this case. Class PropertyAccessDeniedException was removed
|
||||
now.
|
||||
* deprecated PropertyAccess::getPropertyAccessor
|
||||
* added PropertyAccess::createPropertyAccessor and PropertyAccess::createPropertyAccessorBuilder
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\PropertyAccess\Exception;
|
||||
|
||||
/**
|
||||
* Thrown when a property path is not available.
|
||||
*
|
||||
* @author Stéphane Escandell <stephane.escandell@gmail.com>
|
||||
*/
|
||||
class AccessException extends RuntimeException
|
||||
{
|
||||
}
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\PropertyAccess\Exception;
|
||||
|
||||
/**
|
||||
* Marker interface for the PropertyAccess component.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
interface ExceptionInterface extends \Throwable
|
||||
{
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\PropertyAccess\Exception;
|
||||
|
||||
/**
|
||||
* Base InvalidArgumentException for the PropertyAccess component.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\PropertyAccess\Exception;
|
||||
|
||||
/**
|
||||
* Thrown when a property path is malformed.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class InvalidPropertyPathException extends RuntimeException
|
||||
{
|
||||
}
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\PropertyAccess\Exception;
|
||||
|
||||
/**
|
||||
* Thrown when an index cannot be found.
|
||||
*
|
||||
* @author Stéphane Escandell <stephane.escandell@gmail.com>
|
||||
*/
|
||||
class NoSuchIndexException extends AccessException
|
||||
{
|
||||
}
|
||||
wp-content/plugins/yabe-webfont/vendor/symfony/property-access/Exception/NoSuchPropertyException.php
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\PropertyAccess\Exception;
|
||||
|
||||
/**
|
||||
* Thrown when a property cannot be found.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class NoSuchPropertyException extends AccessException
|
||||
{
|
||||
}
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\PropertyAccess\Exception;
|
||||
|
||||
/**
|
||||
* Base OutOfBoundsException for the PropertyAccess component.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class OutOfBoundsException extends \OutOfBoundsException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\PropertyAccess\Exception;
|
||||
|
||||
/**
|
||||
* Base RuntimeException for the PropertyAccess component.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class RuntimeException extends \RuntimeException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
wp-content/plugins/yabe-webfont/vendor/symfony/property-access/Exception/UnexpectedTypeException.php
Vendored
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\PropertyAccess\Exception;
|
||||
|
||||
use JooosiFonDeps\Symfony\Component\PropertyAccess\PropertyPathInterface;
|
||||
/**
|
||||
* Thrown when a value does not match an expected type.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class UnexpectedTypeException extends RuntimeException
|
||||
{
|
||||
/**
|
||||
* @param mixed $value The unexpected value found while traversing property path
|
||||
* @param int $pathIndex The property path index when the unexpected value was found
|
||||
*/
|
||||
public function __construct($value, PropertyPathInterface $path, int $pathIndex)
|
||||
{
|
||||
$message = sprintf('PropertyAccessor requires a graph of objects or arrays to operate on, ' . 'but it found type "%s" while trying to traverse path "%s" at property "%s".', \gettype($value), (string) $path, $path->getElement($pathIndex));
|
||||
parent::__construct($message);
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\PropertyAccess\Exception;
|
||||
|
||||
/**
|
||||
* Thrown when a property is not initialized.
|
||||
*
|
||||
* @author Jules Pietri <jules@heahprod.com>
|
||||
*/
|
||||
class UninitializedPropertyException extends AccessException
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2004-present Fabien Potencier
|
||||
|
||||
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:
|
||||
|
||||
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,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\PropertyAccess;
|
||||
|
||||
/**
|
||||
* Entry point of the PropertyAccess component.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
final class PropertyAccess
|
||||
{
|
||||
/**
|
||||
* Creates a property accessor with the default configuration.
|
||||
*/
|
||||
public static function createPropertyAccessor(): PropertyAccessor
|
||||
{
|
||||
return self::createPropertyAccessorBuilder()->getPropertyAccessor();
|
||||
}
|
||||
public static function createPropertyAccessorBuilder(): PropertyAccessorBuilder
|
||||
{
|
||||
return new PropertyAccessorBuilder();
|
||||
}
|
||||
/**
|
||||
* This class cannot be instantiated.
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
}
|
||||
+614
@@ -0,0 +1,614 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\PropertyAccess;
|
||||
|
||||
use JooosiFonDeps\Psr\Cache\CacheItemPoolInterface;
|
||||
use JooosiFonDeps\Psr\Log\LoggerInterface;
|
||||
use JooosiFonDeps\Psr\Log\NullLogger;
|
||||
use JooosiFonDeps\Symfony\Component\Cache\Adapter\AdapterInterface;
|
||||
use JooosiFonDeps\Symfony\Component\Cache\Adapter\ApcuAdapter;
|
||||
use JooosiFonDeps\Symfony\Component\Cache\Adapter\NullAdapter;
|
||||
use JooosiFonDeps\Symfony\Component\PropertyAccess\Exception\AccessException;
|
||||
use JooosiFonDeps\Symfony\Component\PropertyAccess\Exception\InvalidArgumentException;
|
||||
use JooosiFonDeps\Symfony\Component\PropertyAccess\Exception\NoSuchIndexException;
|
||||
use JooosiFonDeps\Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException;
|
||||
use JooosiFonDeps\Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException;
|
||||
use JooosiFonDeps\Symfony\Component\PropertyAccess\Exception\UninitializedPropertyException;
|
||||
use JooosiFonDeps\Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
|
||||
use JooosiFonDeps\Symfony\Component\PropertyInfo\PropertyReadInfo;
|
||||
use JooosiFonDeps\Symfony\Component\PropertyInfo\PropertyReadInfoExtractorInterface;
|
||||
use JooosiFonDeps\Symfony\Component\PropertyInfo\PropertyWriteInfo;
|
||||
use JooosiFonDeps\Symfony\Component\PropertyInfo\PropertyWriteInfoExtractorInterface;
|
||||
/**
|
||||
* Default implementation of {@link PropertyAccessorInterface}.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class PropertyAccessor implements PropertyAccessorInterface
|
||||
{
|
||||
/** @var int Allow none of the magic methods */
|
||||
public const DISALLOW_MAGIC_METHODS = ReflectionExtractor::DISALLOW_MAGIC_METHODS;
|
||||
/** @var int Allow magic __get methods */
|
||||
public const MAGIC_GET = ReflectionExtractor::ALLOW_MAGIC_GET;
|
||||
/** @var int Allow magic __set methods */
|
||||
public const MAGIC_SET = ReflectionExtractor::ALLOW_MAGIC_SET;
|
||||
/** @var int Allow magic __call methods */
|
||||
public const MAGIC_CALL = ReflectionExtractor::ALLOW_MAGIC_CALL;
|
||||
public const DO_NOT_THROW = 0;
|
||||
public const THROW_ON_INVALID_INDEX = 1;
|
||||
public const THROW_ON_INVALID_PROPERTY_PATH = 2;
|
||||
private const VALUE = 0;
|
||||
private const REF = 1;
|
||||
private const IS_REF_CHAINED = 2;
|
||||
private const CACHE_PREFIX_READ = 'r';
|
||||
private const CACHE_PREFIX_WRITE = 'w';
|
||||
private const CACHE_PREFIX_PROPERTY_PATH = 'p';
|
||||
private $magicMethodsFlags;
|
||||
private $ignoreInvalidIndices;
|
||||
private $ignoreInvalidProperty;
|
||||
/**
|
||||
* @var CacheItemPoolInterface
|
||||
*/
|
||||
private $cacheItemPool;
|
||||
private $propertyPathCache = [];
|
||||
/**
|
||||
* @var PropertyReadInfoExtractorInterface
|
||||
*/
|
||||
private $readInfoExtractor;
|
||||
/**
|
||||
* @var PropertyWriteInfoExtractorInterface
|
||||
*/
|
||||
private $writeInfoExtractor;
|
||||
private $readPropertyCache = [];
|
||||
private $writePropertyCache = [];
|
||||
private const RESULT_PROTO = [self::VALUE => null];
|
||||
/**
|
||||
* Should not be used by application code. Use
|
||||
* {@link PropertyAccess::createPropertyAccessor()} instead.
|
||||
*
|
||||
* @param int $magicMethods A bitwise combination of the MAGIC_* constants
|
||||
* to specify the allowed magic methods (__get, __set, __call)
|
||||
* or self::DISALLOW_MAGIC_METHODS for none
|
||||
* @param int $throw A bitwise combination of the THROW_* constants
|
||||
* to specify when exceptions should be thrown
|
||||
* @param PropertyReadInfoExtractorInterface $readInfoExtractor
|
||||
* @param PropertyWriteInfoExtractorInterface $writeInfoExtractor
|
||||
*/
|
||||
public function __construct($magicMethods = self::MAGIC_GET | self::MAGIC_SET, $throw = self::THROW_ON_INVALID_PROPERTY_PATH, ?CacheItemPoolInterface $cacheItemPool = null, $readInfoExtractor = null, $writeInfoExtractor = null)
|
||||
{
|
||||
if (\is_bool($magicMethods)) {
|
||||
trigger_deprecation('symfony/property-access', '5.2', 'Passing a boolean as the first argument to "%s()" is deprecated. Pass a combination of bitwise flags instead (i.e an integer).', __METHOD__);
|
||||
$magicMethods = ($magicMethods ? self::MAGIC_CALL : 0) | self::MAGIC_GET | self::MAGIC_SET;
|
||||
} elseif (!\is_int($magicMethods)) {
|
||||
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be an integer, "%s" given.', __METHOD__, get_debug_type($readInfoExtractor)));
|
||||
}
|
||||
if (\is_bool($throw)) {
|
||||
trigger_deprecation('symfony/property-access', '5.3', 'Passing a boolean as the second argument to "%s()" is deprecated. Pass a combination of bitwise flags instead (i.e an integer).', __METHOD__);
|
||||
$throw = $throw ? self::THROW_ON_INVALID_INDEX : self::DO_NOT_THROW;
|
||||
if (!\is_bool($readInfoExtractor)) {
|
||||
$throw |= self::THROW_ON_INVALID_PROPERTY_PATH;
|
||||
}
|
||||
}
|
||||
if (\is_bool($readInfoExtractor)) {
|
||||
trigger_deprecation('symfony/property-access', '5.3', 'Passing a boolean as the fourth argument to "%s()" is deprecated. Pass a combination of bitwise flags as the second argument instead (i.e an integer).', __METHOD__);
|
||||
if ($readInfoExtractor) {
|
||||
$throw |= self::THROW_ON_INVALID_PROPERTY_PATH;
|
||||
}
|
||||
$readInfoExtractor = $writeInfoExtractor;
|
||||
$writeInfoExtractor = 4 < \func_num_args() ? func_get_arg(4) : null;
|
||||
}
|
||||
if (null !== $readInfoExtractor && !$readInfoExtractor instanceof PropertyReadInfoExtractorInterface) {
|
||||
throw new \TypeError(sprintf('Argument 4 passed to "%s()" must be null or an instance of "%s", "%s" given.', __METHOD__, PropertyReadInfoExtractorInterface::class, get_debug_type($readInfoExtractor)));
|
||||
}
|
||||
if (null !== $writeInfoExtractor && !$writeInfoExtractor instanceof PropertyWriteInfoExtractorInterface) {
|
||||
throw new \TypeError(sprintf('Argument 5 passed to "%s()" must be null or an instance of "%s", "%s" given.', __METHOD__, PropertyWriteInfoExtractorInterface::class, get_debug_type($writeInfoExtractor)));
|
||||
}
|
||||
$this->magicMethodsFlags = $magicMethods;
|
||||
$this->ignoreInvalidIndices = 0 === ($throw & self::THROW_ON_INVALID_INDEX);
|
||||
$this->cacheItemPool = $cacheItemPool instanceof NullAdapter ? null : $cacheItemPool;
|
||||
// Replace the NullAdapter by the null value
|
||||
$this->ignoreInvalidProperty = 0 === ($throw & self::THROW_ON_INVALID_PROPERTY_PATH);
|
||||
$this->readInfoExtractor = $readInfoExtractor ?? new ReflectionExtractor([], null, null, \false);
|
||||
$this->writeInfoExtractor = $writeInfoExtractor ?? new ReflectionExtractor(['set'], null, null, \false);
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getValue($objectOrArray, $propertyPath)
|
||||
{
|
||||
$zval = [self::VALUE => $objectOrArray];
|
||||
if (\is_object($objectOrArray) && (\false === strpbrk((string) $propertyPath, '.[') || $objectOrArray instanceof \stdClass && property_exists($objectOrArray, $propertyPath))) {
|
||||
return $this->readProperty($zval, $propertyPath, $this->ignoreInvalidProperty)[self::VALUE];
|
||||
}
|
||||
$propertyPath = $this->getPropertyPath($propertyPath);
|
||||
$propertyValues = $this->readPropertiesUntil($zval, $propertyPath, $propertyPath->getLength(), $this->ignoreInvalidIndices);
|
||||
return $propertyValues[\count($propertyValues) - 1][self::VALUE];
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setValue(&$objectOrArray, $propertyPath, $value)
|
||||
{
|
||||
if (\is_object($objectOrArray) && (\false === strpbrk((string) $propertyPath, '.[') || $objectOrArray instanceof \stdClass && property_exists($objectOrArray, $propertyPath))) {
|
||||
$zval = [self::VALUE => $objectOrArray];
|
||||
try {
|
||||
$this->writeProperty($zval, $propertyPath, $value);
|
||||
return;
|
||||
} catch (\TypeError $e) {
|
||||
self::throwInvalidArgumentException($e->getMessage(), $e->getTrace(), 0, $propertyPath, $e);
|
||||
// It wasn't thrown in this class so rethrow it
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
$propertyPath = $this->getPropertyPath($propertyPath);
|
||||
$zval = [self::VALUE => $objectOrArray, self::REF => &$objectOrArray];
|
||||
$propertyValues = $this->readPropertiesUntil($zval, $propertyPath, $propertyPath->getLength() - 1);
|
||||
$overwrite = \true;
|
||||
try {
|
||||
for ($i = \count($propertyValues) - 1; 0 <= $i; --$i) {
|
||||
$zval = $propertyValues[$i];
|
||||
unset($propertyValues[$i]);
|
||||
// You only need set value for current element if:
|
||||
// 1. it's the parent of the last index element
|
||||
// OR
|
||||
// 2. its child is not passed by reference
|
||||
//
|
||||
// This may avoid unnecessary value setting process for array elements.
|
||||
// For example:
|
||||
// '[a][b][c]' => 'old-value'
|
||||
// If you want to change its value to 'new-value',
|
||||
// you only need set value for '[a][b][c]' and it's safe to ignore '[a][b]' and '[a]'
|
||||
if ($overwrite) {
|
||||
$property = $propertyPath->getElement($i);
|
||||
if ($propertyPath->isIndex($i)) {
|
||||
if ($overwrite = !isset($zval[self::REF])) {
|
||||
$ref =& $zval[self::REF];
|
||||
$ref = $zval[self::VALUE];
|
||||
}
|
||||
$this->writeIndex($zval, $property, $value);
|
||||
if ($overwrite) {
|
||||
$zval[self::VALUE] = $zval[self::REF];
|
||||
}
|
||||
} else {
|
||||
$this->writeProperty($zval, $property, $value);
|
||||
}
|
||||
// if current element is an object
|
||||
// OR
|
||||
// if current element's reference chain is not broken - current element
|
||||
// as well as all its ancients in the property path are all passed by reference,
|
||||
// then there is no need to continue the value setting process
|
||||
if (\is_object($zval[self::VALUE]) || isset($zval[self::IS_REF_CHAINED])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$value = $zval[self::VALUE];
|
||||
}
|
||||
} catch (\TypeError $e) {
|
||||
self::throwInvalidArgumentException($e->getMessage(), $e->getTrace(), 0, $propertyPath, $e);
|
||||
// It wasn't thrown in this class so rethrow it
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
private static function throwInvalidArgumentException(string $message, array $trace, int $i, string $propertyPath, ?\Throwable $previous = null): void
|
||||
{
|
||||
if (!isset($trace[$i]['file']) || __FILE__ !== $trace[$i]['file']) {
|
||||
return;
|
||||
}
|
||||
if (\PHP_VERSION_ID < 80000) {
|
||||
if (preg_match('/^Typed property \S+::\$\S+ must be (\S+), (\S+) used$/', $message, $matches)) {
|
||||
[, $expectedType, $actualType] = $matches;
|
||||
throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given at property path "%s".', $expectedType, 'NULL' === $actualType ? 'null' : $actualType, $propertyPath), 0, $previous);
|
||||
}
|
||||
if (!str_starts_with($message, 'Argument ')) {
|
||||
return;
|
||||
}
|
||||
$pos = strpos($message, $delim = 'must be of the type ') ?: (strpos($message, $delim = 'must be an instance of ') ?: strpos($message, $delim = 'must implement interface '));
|
||||
$pos += \strlen($delim);
|
||||
$j = strpos($message, ',', $pos);
|
||||
$type = substr($message, 2 + $j, strpos($message, ' given', $j) - $j - 2);
|
||||
$message = substr($message, $pos, $j - $pos);
|
||||
throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given at property path "%s".', $message, 'NULL' === $type ? 'null' : $type, $propertyPath), 0, $previous);
|
||||
}
|
||||
if (preg_match('/^\S+::\S+\(\): Argument #\d+ \(\$\S+\) must be of type (\S+), (\S+) given/', $message, $matches)) {
|
||||
[, $expectedType, $actualType] = $matches;
|
||||
throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given at property path "%s".', $expectedType, 'NULL' === $actualType ? 'null' : $actualType, $propertyPath), 0, $previous);
|
||||
}
|
||||
if (preg_match('/^Cannot assign (\S+) to property \S+::\$\S+ of type (\S+)$/', $message, $matches)) {
|
||||
[, $actualType, $expectedType] = $matches;
|
||||
throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given at property path "%s".', $expectedType, 'NULL' === $actualType ? 'null' : $actualType, $propertyPath), 0, $previous);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isReadable($objectOrArray, $propertyPath)
|
||||
{
|
||||
if (!$propertyPath instanceof PropertyPathInterface) {
|
||||
$propertyPath = new PropertyPath($propertyPath);
|
||||
}
|
||||
try {
|
||||
$zval = [self::VALUE => $objectOrArray];
|
||||
// handle stdClass with properties with a dot in the name
|
||||
if ($objectOrArray instanceof \stdClass && str_contains($propertyPath, '.') && property_exists($objectOrArray, $propertyPath)) {
|
||||
$this->readProperty($zval, $propertyPath, $this->ignoreInvalidProperty);
|
||||
} else {
|
||||
$this->readPropertiesUntil($zval, $propertyPath, $propertyPath->getLength(), $this->ignoreInvalidIndices);
|
||||
}
|
||||
return \true;
|
||||
} catch (AccessException $e) {
|
||||
return \false;
|
||||
} catch (UnexpectedTypeException $e) {
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isWritable($objectOrArray, $propertyPath)
|
||||
{
|
||||
$propertyPath = $this->getPropertyPath($propertyPath);
|
||||
try {
|
||||
$zval = [self::VALUE => $objectOrArray];
|
||||
// handle stdClass with properties with a dot in the name
|
||||
if ($objectOrArray instanceof \stdClass && str_contains($propertyPath, '.') && property_exists($objectOrArray, $propertyPath)) {
|
||||
$this->readProperty($zval, $propertyPath, $this->ignoreInvalidProperty);
|
||||
return \true;
|
||||
}
|
||||
$propertyValues = $this->readPropertiesUntil($zval, $propertyPath, $propertyPath->getLength() - 1);
|
||||
for ($i = \count($propertyValues) - 1; 0 <= $i; --$i) {
|
||||
$zval = $propertyValues[$i];
|
||||
unset($propertyValues[$i]);
|
||||
if ($propertyPath->isIndex($i)) {
|
||||
if (!$zval[self::VALUE] instanceof \ArrayAccess && !\is_array($zval[self::VALUE])) {
|
||||
return \false;
|
||||
}
|
||||
} elseif (!\is_object($zval[self::VALUE]) || !$this->isPropertyWritable($zval[self::VALUE], $propertyPath->getElement($i))) {
|
||||
return \false;
|
||||
}
|
||||
if (\is_object($zval[self::VALUE])) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \true;
|
||||
} catch (AccessException $e) {
|
||||
return \false;
|
||||
} catch (UnexpectedTypeException $e) {
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Reads the path from an object up to a given path index.
|
||||
*
|
||||
* @throws UnexpectedTypeException if a value within the path is neither object nor array
|
||||
* @throws NoSuchIndexException If a non-existing index is accessed
|
||||
*/
|
||||
private function readPropertiesUntil(array $zval, PropertyPathInterface $propertyPath, int $lastIndex, bool $ignoreInvalidIndices = \true): array
|
||||
{
|
||||
if (!\is_object($zval[self::VALUE]) && !\is_array($zval[self::VALUE])) {
|
||||
throw new UnexpectedTypeException($zval[self::VALUE], $propertyPath, 0);
|
||||
}
|
||||
// Add the root object to the list
|
||||
$propertyValues = [$zval];
|
||||
for ($i = 0; $i < $lastIndex; ++$i) {
|
||||
$property = $propertyPath->getElement($i);
|
||||
$isIndex = $propertyPath->isIndex($i);
|
||||
if ($isIndex) {
|
||||
// Create missing nested arrays on demand
|
||||
if ($zval[self::VALUE] instanceof \ArrayAccess && !$zval[self::VALUE]->offsetExists($property) || \is_array($zval[self::VALUE]) && !isset($zval[self::VALUE][$property]) && !\array_key_exists($property, $zval[self::VALUE])) {
|
||||
if (!$ignoreInvalidIndices) {
|
||||
if (!\is_array($zval[self::VALUE])) {
|
||||
if (!$zval[self::VALUE] instanceof \Traversable) {
|
||||
throw new NoSuchIndexException(sprintf('Cannot read index "%s" while trying to traverse path "%s".', $property, (string) $propertyPath));
|
||||
}
|
||||
$zval[self::VALUE] = iterator_to_array($zval[self::VALUE]);
|
||||
}
|
||||
throw new NoSuchIndexException(sprintf('Cannot read index "%s" while trying to traverse path "%s". Available indices are "%s".', $property, (string) $propertyPath, print_r(array_keys($zval[self::VALUE]), \true)));
|
||||
}
|
||||
if ($i + 1 < $propertyPath->getLength()) {
|
||||
if (isset($zval[self::REF])) {
|
||||
$zval[self::VALUE][$property] = [];
|
||||
$zval[self::REF] = $zval[self::VALUE];
|
||||
} else {
|
||||
$zval[self::VALUE] = [$property => []];
|
||||
}
|
||||
}
|
||||
}
|
||||
$zval = $this->readIndex($zval, $property);
|
||||
} else {
|
||||
$zval = $this->readProperty($zval, $property, $this->ignoreInvalidProperty);
|
||||
}
|
||||
// the final value of the path must not be validated
|
||||
if ($i + 1 < $propertyPath->getLength() && !\is_object($zval[self::VALUE]) && !\is_array($zval[self::VALUE])) {
|
||||
throw new UnexpectedTypeException($zval[self::VALUE], $propertyPath, $i + 1);
|
||||
}
|
||||
if (isset($zval[self::REF]) && (0 === $i || isset($propertyValues[$i - 1][self::IS_REF_CHAINED]))) {
|
||||
// Set the IS_REF_CHAINED flag to true if:
|
||||
// current property is passed by reference and
|
||||
// it is the first element in the property path or
|
||||
// the IS_REF_CHAINED flag of its parent element is true
|
||||
// Basically, this flag is true only when the reference chain from the top element to current element is not broken
|
||||
$zval[self::IS_REF_CHAINED] = \true;
|
||||
}
|
||||
$propertyValues[] = $zval;
|
||||
}
|
||||
return $propertyValues;
|
||||
}
|
||||
/**
|
||||
* Reads a key from an array-like structure.
|
||||
*
|
||||
* @param string|int $index The key to read
|
||||
*
|
||||
* @throws NoSuchIndexException If the array does not implement \ArrayAccess or it is not an array
|
||||
*/
|
||||
private function readIndex(array $zval, $index): array
|
||||
{
|
||||
if (!$zval[self::VALUE] instanceof \ArrayAccess && !\is_array($zval[self::VALUE])) {
|
||||
throw new NoSuchIndexException(sprintf('Cannot read index "%s" from object of type "%s" because it doesn\'t implement \ArrayAccess.', $index, get_debug_type($zval[self::VALUE])));
|
||||
}
|
||||
$result = self::RESULT_PROTO;
|
||||
if (isset($zval[self::VALUE][$index])) {
|
||||
$result[self::VALUE] = $zval[self::VALUE][$index];
|
||||
if (!isset($zval[self::REF])) {
|
||||
// Save creating references when doing read-only lookups
|
||||
} elseif (\is_array($zval[self::VALUE])) {
|
||||
$result[self::REF] =& $zval[self::REF][$index];
|
||||
} elseif (\is_object($result[self::VALUE])) {
|
||||
$result[self::REF] = $result[self::VALUE];
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
/**
|
||||
* Reads the value of a property from an object.
|
||||
*
|
||||
* @throws NoSuchPropertyException If $ignoreInvalidProperty is false and the property does not exist or is not public
|
||||
*/
|
||||
private function readProperty(array $zval, string $property, bool $ignoreInvalidProperty = \false): array
|
||||
{
|
||||
if (!\is_object($zval[self::VALUE])) {
|
||||
throw new NoSuchPropertyException(sprintf('Cannot read property "%s" from an array. Maybe you intended to write the property path as "[%1$s]" instead.', $property));
|
||||
}
|
||||
$result = self::RESULT_PROTO;
|
||||
$object = $zval[self::VALUE];
|
||||
$class = \get_class($object);
|
||||
$access = $this->getReadInfo($class, $property);
|
||||
if (null !== $access) {
|
||||
$name = $access->getName();
|
||||
$type = $access->getType();
|
||||
try {
|
||||
if (PropertyReadInfo::TYPE_METHOD === $type) {
|
||||
try {
|
||||
$result[self::VALUE] = $object->{$name}();
|
||||
} catch (\TypeError $e) {
|
||||
[$trace] = $e->getTrace();
|
||||
// handle uninitialized properties in PHP >= 7
|
||||
if (__FILE__ === ($trace['file'] ?? null) && $name === $trace['function'] && $object instanceof $trace['class'] && preg_match('/Return value (?:of .*::\w+\(\) )?must be of (?:the )?type (\w+), null returned$/', $e->getMessage(), $matches)) {
|
||||
throw new UninitializedPropertyException(sprintf('The method "%s::%s()" returned "null", but expected type "%3$s". Did you forget to initialize a property or to make the return type nullable using "?%3$s"?', get_debug_type($object), $name, $matches[1]), 0, $e);
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
} elseif (PropertyReadInfo::TYPE_PROPERTY === $type) {
|
||||
if ($access->canBeReference() && !isset($object->{$name}) && !\array_key_exists($name, (array) $object) && (\PHP_VERSION_ID < 70400 || !(new \ReflectionProperty($class, $name))->hasType())) {
|
||||
throw new UninitializedPropertyException(sprintf('The property "%s::$%s" is not initialized.', $class, $name));
|
||||
}
|
||||
$result[self::VALUE] = $object->{$name};
|
||||
if (isset($zval[self::REF]) && $access->canBeReference()) {
|
||||
$result[self::REF] =& $object->{$name};
|
||||
}
|
||||
}
|
||||
} catch (\Error $e) {
|
||||
// handle uninitialized properties in PHP >= 7.4
|
||||
if (\PHP_VERSION_ID >= 70400 && preg_match('/^Typed property ([\w\\\\@]+)::\$(\w+) must not be accessed before initialization$/', $e->getMessage(), $matches)) {
|
||||
$r = new \ReflectionProperty(str_contains($matches[1], '@anonymous') ? $class : $matches[1], $matches[2]);
|
||||
$type = ($type = $r->getType()) instanceof \ReflectionNamedType ? $type->getName() : (string) $type;
|
||||
throw new UninitializedPropertyException(sprintf('The property "%s::$%s" is not readable because it is typed "%s". You should initialize it or declare a default value instead.', $matches[1], $r->getName(), $type), 0, $e);
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
} elseif (property_exists($object, $property) && \array_key_exists($property, (array) $object)) {
|
||||
$result[self::VALUE] = $object->{$property};
|
||||
if (isset($zval[self::REF])) {
|
||||
$result[self::REF] =& $object->{$property};
|
||||
}
|
||||
} elseif (!$ignoreInvalidProperty) {
|
||||
throw new NoSuchPropertyException(sprintf('Can\'t get a way to read the property "%s" in class "%s".', $property, $class));
|
||||
}
|
||||
// Objects are always passed around by reference
|
||||
if (isset($zval[self::REF]) && \is_object($result[self::VALUE])) {
|
||||
$result[self::REF] = $result[self::VALUE];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
/**
|
||||
* Guesses how to read the property value.
|
||||
*/
|
||||
private function getReadInfo(string $class, string $property): ?PropertyReadInfo
|
||||
{
|
||||
$key = str_replace('\\', '.', $class) . '..' . $property;
|
||||
if (isset($this->readPropertyCache[$key])) {
|
||||
return $this->readPropertyCache[$key];
|
||||
}
|
||||
if ($this->cacheItemPool) {
|
||||
$item = $this->cacheItemPool->getItem(self::CACHE_PREFIX_READ . rawurlencode($key));
|
||||
if ($item->isHit()) {
|
||||
return $this->readPropertyCache[$key] = $item->get();
|
||||
}
|
||||
}
|
||||
$accessor = $this->readInfoExtractor->getReadInfo($class, $property, ['enable_getter_setter_extraction' => \true, 'enable_magic_methods_extraction' => $this->magicMethodsFlags, 'enable_constructor_extraction' => \false]);
|
||||
if (isset($item)) {
|
||||
$this->cacheItemPool->save($item->set($accessor));
|
||||
}
|
||||
return $this->readPropertyCache[$key] = $accessor;
|
||||
}
|
||||
/**
|
||||
* Sets the value of an index in a given array-accessible value.
|
||||
*
|
||||
* @param string|int $index The index to write at
|
||||
* @param mixed $value The value to write
|
||||
*
|
||||
* @throws NoSuchIndexException If the array does not implement \ArrayAccess or it is not an array
|
||||
*/
|
||||
private function writeIndex(array $zval, $index, $value)
|
||||
{
|
||||
if (!$zval[self::VALUE] instanceof \ArrayAccess && !\is_array($zval[self::VALUE])) {
|
||||
throw new NoSuchIndexException(sprintf('Cannot modify index "%s" in object of type "%s" because it doesn\'t implement \ArrayAccess.', $index, get_debug_type($zval[self::VALUE])));
|
||||
}
|
||||
$zval[self::REF][$index] = $value;
|
||||
}
|
||||
/**
|
||||
* Sets the value of a property in the given object.
|
||||
*
|
||||
* @param mixed $value The value to write
|
||||
*
|
||||
* @throws NoSuchPropertyException if the property does not exist or is not public
|
||||
*/
|
||||
private function writeProperty(array $zval, string $property, $value)
|
||||
{
|
||||
if (!\is_object($zval[self::VALUE])) {
|
||||
throw new NoSuchPropertyException(sprintf('Cannot write property "%s" to an array. Maybe you should write the property path as "[%1$s]" instead?', $property));
|
||||
}
|
||||
$object = $zval[self::VALUE];
|
||||
$class = \get_class($object);
|
||||
$mutator = $this->getWriteInfo($class, $property, $value);
|
||||
if (PropertyWriteInfo::TYPE_NONE !== $mutator->getType()) {
|
||||
$type = $mutator->getType();
|
||||
if (PropertyWriteInfo::TYPE_METHOD === $type) {
|
||||
$object->{$mutator->getName()}($value);
|
||||
} elseif (PropertyWriteInfo::TYPE_PROPERTY === $type) {
|
||||
$object->{$mutator->getName()} = $value;
|
||||
} elseif (PropertyWriteInfo::TYPE_ADDER_AND_REMOVER === $type) {
|
||||
$this->writeCollection($zval, $property, $value, $mutator->getAdderInfo(), $mutator->getRemoverInfo());
|
||||
}
|
||||
} elseif ($object instanceof \stdClass && property_exists($object, $property)) {
|
||||
$object->{$property} = $value;
|
||||
} elseif (!$this->ignoreInvalidProperty) {
|
||||
if ($mutator->hasErrors()) {
|
||||
throw new NoSuchPropertyException(implode('. ', $mutator->getErrors()) . '.');
|
||||
}
|
||||
throw new NoSuchPropertyException(sprintf('Could not determine access type for property "%s" in class "%s".', $property, get_debug_type($object)));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Adjusts a collection-valued property by calling add*() and remove*() methods.
|
||||
*/
|
||||
private function writeCollection(array $zval, string $property, iterable $collection, PropertyWriteInfo $addMethod, PropertyWriteInfo $removeMethod)
|
||||
{
|
||||
// At this point the add and remove methods have been found
|
||||
$previousValue = $this->readProperty($zval, $property);
|
||||
$previousValue = $previousValue[self::VALUE];
|
||||
$removeMethodName = $removeMethod->getName();
|
||||
$addMethodName = $addMethod->getName();
|
||||
if ($previousValue instanceof \Traversable) {
|
||||
$previousValue = iterator_to_array($previousValue);
|
||||
}
|
||||
if ($previousValue && \is_array($previousValue)) {
|
||||
if (\is_object($collection)) {
|
||||
$collection = iterator_to_array($collection);
|
||||
}
|
||||
foreach ($previousValue as $key => $item) {
|
||||
if (!\in_array($item, $collection, \true)) {
|
||||
unset($previousValue[$key]);
|
||||
$zval[self::VALUE]->{$removeMethodName}($item);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$previousValue = \false;
|
||||
}
|
||||
foreach ($collection as $item) {
|
||||
if (!$previousValue || !\in_array($item, $previousValue, \true)) {
|
||||
$zval[self::VALUE]->{$addMethodName}($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
private function getWriteInfo(string $class, string $property, $value): PropertyWriteInfo
|
||||
{
|
||||
$useAdderAndRemover = is_iterable($value);
|
||||
$key = str_replace('\\', '.', $class) . '..' . $property . '..' . (int) $useAdderAndRemover;
|
||||
if (isset($this->writePropertyCache[$key])) {
|
||||
return $this->writePropertyCache[$key];
|
||||
}
|
||||
if ($this->cacheItemPool) {
|
||||
$item = $this->cacheItemPool->getItem(self::CACHE_PREFIX_WRITE . rawurlencode($key));
|
||||
if ($item->isHit()) {
|
||||
return $this->writePropertyCache[$key] = $item->get();
|
||||
}
|
||||
}
|
||||
$mutator = $this->writeInfoExtractor->getWriteInfo($class, $property, ['enable_getter_setter_extraction' => \true, 'enable_magic_methods_extraction' => $this->magicMethodsFlags, 'enable_constructor_extraction' => \false, 'enable_adder_remover_extraction' => $useAdderAndRemover]);
|
||||
if (isset($item)) {
|
||||
$this->cacheItemPool->save($item->set($mutator));
|
||||
}
|
||||
return $this->writePropertyCache[$key] = $mutator;
|
||||
}
|
||||
/**
|
||||
* Returns whether a property is writable in the given object.
|
||||
*/
|
||||
private function isPropertyWritable(object $object, string $property): bool
|
||||
{
|
||||
$mutatorForArray = $this->getWriteInfo(\get_class($object), $property, []);
|
||||
if (PropertyWriteInfo::TYPE_NONE !== $mutatorForArray->getType() || $object instanceof \stdClass && property_exists($object, $property)) {
|
||||
return \true;
|
||||
}
|
||||
$mutator = $this->getWriteInfo(\get_class($object), $property, '');
|
||||
return PropertyWriteInfo::TYPE_NONE !== $mutator->getType() || $object instanceof \stdClass && property_exists($object, $property);
|
||||
}
|
||||
/**
|
||||
* Gets a PropertyPath instance and caches it.
|
||||
*
|
||||
* @param string|PropertyPath $propertyPath
|
||||
*/
|
||||
private function getPropertyPath($propertyPath): PropertyPath
|
||||
{
|
||||
if ($propertyPath instanceof PropertyPathInterface) {
|
||||
// Don't call the copy constructor has it is not needed here
|
||||
return $propertyPath;
|
||||
}
|
||||
if (isset($this->propertyPathCache[$propertyPath])) {
|
||||
return $this->propertyPathCache[$propertyPath];
|
||||
}
|
||||
if ($this->cacheItemPool) {
|
||||
$item = $this->cacheItemPool->getItem(self::CACHE_PREFIX_PROPERTY_PATH . rawurlencode($propertyPath));
|
||||
if ($item->isHit()) {
|
||||
return $this->propertyPathCache[$propertyPath] = $item->get();
|
||||
}
|
||||
}
|
||||
$propertyPathInstance = new PropertyPath($propertyPath);
|
||||
if (isset($item)) {
|
||||
$item->set($propertyPathInstance);
|
||||
$this->cacheItemPool->save($item);
|
||||
}
|
||||
return $this->propertyPathCache[$propertyPath] = $propertyPathInstance;
|
||||
}
|
||||
/**
|
||||
* Creates the APCu adapter if applicable.
|
||||
*
|
||||
* @return AdapterInterface
|
||||
*
|
||||
* @throws \LogicException When the Cache Component isn't available
|
||||
*/
|
||||
public static function createCache(string $namespace, int $defaultLifetime, string $version, ?LoggerInterface $logger = null)
|
||||
{
|
||||
if (!class_exists(ApcuAdapter::class)) {
|
||||
throw new \LogicException(sprintf('The Symfony Cache component must be installed to use "%s()".', __METHOD__));
|
||||
}
|
||||
if (!ApcuAdapter::isSupported()) {
|
||||
return new NullAdapter();
|
||||
}
|
||||
$apcu = new ApcuAdapter($namespace, $defaultLifetime / 5, $version);
|
||||
if ('cli' === \PHP_SAPI && !filter_var(\ini_get('apc.enable_cli'), \FILTER_VALIDATE_BOOLEAN)) {
|
||||
$apcu->setLogger(new NullLogger());
|
||||
} elseif (null !== $logger) {
|
||||
$apcu->setLogger($logger);
|
||||
}
|
||||
return $apcu;
|
||||
}
|
||||
}
|
||||
+261
@@ -0,0 +1,261 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\PropertyAccess;
|
||||
|
||||
use JooosiFonDeps\Psr\Cache\CacheItemPoolInterface;
|
||||
use JooosiFonDeps\Symfony\Component\PropertyInfo\PropertyReadInfoExtractorInterface;
|
||||
use JooosiFonDeps\Symfony\Component\PropertyInfo\PropertyWriteInfoExtractorInterface;
|
||||
/**
|
||||
* A configurable builder to create a PropertyAccessor.
|
||||
*
|
||||
* @author Jérémie Augustin <jeremie.augustin@pixel-cookers.com>
|
||||
*/
|
||||
class PropertyAccessorBuilder
|
||||
{
|
||||
/** @var int */
|
||||
private $magicMethods = PropertyAccessor::MAGIC_GET | PropertyAccessor::MAGIC_SET;
|
||||
private $throwExceptionOnInvalidIndex = \false;
|
||||
private $throwExceptionOnInvalidPropertyPath = \true;
|
||||
/**
|
||||
* @var CacheItemPoolInterface|null
|
||||
*/
|
||||
private $cacheItemPool;
|
||||
/**
|
||||
* @var PropertyReadInfoExtractorInterface|null
|
||||
*/
|
||||
private $readInfoExtractor;
|
||||
/**
|
||||
* @var PropertyWriteInfoExtractorInterface|null
|
||||
*/
|
||||
private $writeInfoExtractor;
|
||||
/**
|
||||
* Enables the use of all magic methods by the PropertyAccessor.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function enableMagicMethods(): self
|
||||
{
|
||||
$this->magicMethods = PropertyAccessor::MAGIC_GET | PropertyAccessor::MAGIC_SET | PropertyAccessor::MAGIC_CALL;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Disable the use of all magic methods by the PropertyAccessor.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function disableMagicMethods(): self
|
||||
{
|
||||
$this->magicMethods = PropertyAccessor::DISALLOW_MAGIC_METHODS;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Enables the use of "__call" by the PropertyAccessor.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function enableMagicCall()
|
||||
{
|
||||
$this->magicMethods |= PropertyAccessor::MAGIC_CALL;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Enables the use of "__get" by the PropertyAccessor.
|
||||
*/
|
||||
public function enableMagicGet(): self
|
||||
{
|
||||
$this->magicMethods |= PropertyAccessor::MAGIC_GET;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Enables the use of "__set" by the PropertyAccessor.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function enableMagicSet(): self
|
||||
{
|
||||
$this->magicMethods |= PropertyAccessor::MAGIC_SET;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Disables the use of "__call" by the PropertyAccessor.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function disableMagicCall()
|
||||
{
|
||||
$this->magicMethods &= ~PropertyAccessor::MAGIC_CALL;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Disables the use of "__get" by the PropertyAccessor.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function disableMagicGet(): self
|
||||
{
|
||||
$this->magicMethods &= ~PropertyAccessor::MAGIC_GET;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Disables the use of "__set" by the PropertyAccessor.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function disableMagicSet(): self
|
||||
{
|
||||
$this->magicMethods &= ~PropertyAccessor::MAGIC_SET;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @return bool whether the use of "__call" by the PropertyAccessor is enabled
|
||||
*/
|
||||
public function isMagicCallEnabled()
|
||||
{
|
||||
return (bool) ($this->magicMethods & PropertyAccessor::MAGIC_CALL);
|
||||
}
|
||||
/**
|
||||
* @return bool whether the use of "__get" by the PropertyAccessor is enabled
|
||||
*/
|
||||
public function isMagicGetEnabled(): bool
|
||||
{
|
||||
return $this->magicMethods & PropertyAccessor::MAGIC_GET;
|
||||
}
|
||||
/**
|
||||
* @return bool whether the use of "__set" by the PropertyAccessor is enabled
|
||||
*/
|
||||
public function isMagicSetEnabled(): bool
|
||||
{
|
||||
return $this->magicMethods & PropertyAccessor::MAGIC_SET;
|
||||
}
|
||||
/**
|
||||
* Enables exceptions when reading a non-existing index.
|
||||
*
|
||||
* This has no influence on writing non-existing indices with PropertyAccessorInterface::setValue()
|
||||
* which are always created on-the-fly.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function enableExceptionOnInvalidIndex()
|
||||
{
|
||||
$this->throwExceptionOnInvalidIndex = \true;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Disables exceptions when reading a non-existing index.
|
||||
*
|
||||
* Instead, null is returned when calling PropertyAccessorInterface::getValue() on a non-existing index.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function disableExceptionOnInvalidIndex()
|
||||
{
|
||||
$this->throwExceptionOnInvalidIndex = \false;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @return bool whether an exception is thrown or null is returned when reading a non-existing index
|
||||
*/
|
||||
public function isExceptionOnInvalidIndexEnabled()
|
||||
{
|
||||
return $this->throwExceptionOnInvalidIndex;
|
||||
}
|
||||
/**
|
||||
* Enables exceptions when reading a non-existing property.
|
||||
*
|
||||
* This has no influence on writing non-existing indices with PropertyAccessorInterface::setValue()
|
||||
* which are always created on-the-fly.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function enableExceptionOnInvalidPropertyPath()
|
||||
{
|
||||
$this->throwExceptionOnInvalidPropertyPath = \true;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Disables exceptions when reading a non-existing index.
|
||||
*
|
||||
* Instead, null is returned when calling PropertyAccessorInterface::getValue() on a non-existing index.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function disableExceptionOnInvalidPropertyPath()
|
||||
{
|
||||
$this->throwExceptionOnInvalidPropertyPath = \false;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @return bool whether an exception is thrown or null is returned when reading a non-existing property
|
||||
*/
|
||||
public function isExceptionOnInvalidPropertyPath()
|
||||
{
|
||||
return $this->throwExceptionOnInvalidPropertyPath;
|
||||
}
|
||||
/**
|
||||
* Sets a cache system.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCacheItemPool(?CacheItemPoolInterface $cacheItemPool = null)
|
||||
{
|
||||
$this->cacheItemPool = $cacheItemPool;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Gets the used cache system.
|
||||
*
|
||||
* @return CacheItemPoolInterface|null
|
||||
*/
|
||||
public function getCacheItemPool()
|
||||
{
|
||||
return $this->cacheItemPool;
|
||||
}
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setReadInfoExtractor(?PropertyReadInfoExtractorInterface $readInfoExtractor)
|
||||
{
|
||||
$this->readInfoExtractor = $readInfoExtractor;
|
||||
return $this;
|
||||
}
|
||||
public function getReadInfoExtractor(): ?PropertyReadInfoExtractorInterface
|
||||
{
|
||||
return $this->readInfoExtractor;
|
||||
}
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setWriteInfoExtractor(?PropertyWriteInfoExtractorInterface $writeInfoExtractor)
|
||||
{
|
||||
$this->writeInfoExtractor = $writeInfoExtractor;
|
||||
return $this;
|
||||
}
|
||||
public function getWriteInfoExtractor(): ?PropertyWriteInfoExtractorInterface
|
||||
{
|
||||
return $this->writeInfoExtractor;
|
||||
}
|
||||
/**
|
||||
* Builds and returns a new PropertyAccessor object.
|
||||
*
|
||||
* @return PropertyAccessorInterface
|
||||
*/
|
||||
public function getPropertyAccessor()
|
||||
{
|
||||
$throw = PropertyAccessor::DO_NOT_THROW;
|
||||
if ($this->throwExceptionOnInvalidIndex) {
|
||||
$throw |= PropertyAccessor::THROW_ON_INVALID_INDEX;
|
||||
}
|
||||
if ($this->throwExceptionOnInvalidPropertyPath) {
|
||||
$throw |= PropertyAccessor::THROW_ON_INVALID_PROPERTY_PATH;
|
||||
}
|
||||
return new PropertyAccessor($this->magicMethods, $throw, $this->cacheItemPool, $this->readInfoExtractor, $this->writeInfoExtractor);
|
||||
}
|
||||
}
|
||||
Vendored
+110
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\PropertyAccess;
|
||||
|
||||
/**
|
||||
* Writes and reads values to/from an object/array graph.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
interface PropertyAccessorInterface
|
||||
{
|
||||
/**
|
||||
* Sets the value at the end of the property path of the object graph.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* use Symfony\Component\PropertyAccess\PropertyAccess;
|
||||
*
|
||||
* $propertyAccessor = PropertyAccess::createPropertyAccessor();
|
||||
*
|
||||
* echo $propertyAccessor->setValue($object, 'child.name', 'Fabien');
|
||||
* // equals echo $object->getChild()->setName('Fabien');
|
||||
*
|
||||
* This method first tries to find a public setter for each property in the
|
||||
* path. The name of the setter must be the camel-cased property name
|
||||
* prefixed with "set".
|
||||
*
|
||||
* If the setter does not exist, this method tries to find a public
|
||||
* property. The value of the property is then changed.
|
||||
*
|
||||
* If neither is found, an exception is thrown.
|
||||
*
|
||||
* @param object|array $objectOrArray The object or array to modify
|
||||
* @param string|PropertyPathInterface $propertyPath The property path to modify
|
||||
* @param mixed $value The value to set at the end of the property path
|
||||
*
|
||||
* @throws Exception\InvalidArgumentException If the property path is invalid
|
||||
* @throws Exception\AccessException If a property/index does not exist or is not public
|
||||
* @throws Exception\UnexpectedTypeException If a value within the path is neither object nor array
|
||||
*/
|
||||
public function setValue(&$objectOrArray, $propertyPath, $value);
|
||||
/**
|
||||
* Returns the value at the end of the property path of the object graph.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* use Symfony\Component\PropertyAccess\PropertyAccess;
|
||||
*
|
||||
* $propertyAccessor = PropertyAccess::createPropertyAccessor();
|
||||
*
|
||||
* echo $propertyAccessor->getValue($object, 'child.name');
|
||||
* // equals echo $object->getChild()->getName();
|
||||
*
|
||||
* This method first tries to find a public getter for each property in the
|
||||
* path. The name of the getter must be the camel-cased property name
|
||||
* prefixed with "get", "is", or "has".
|
||||
*
|
||||
* If the getter does not exist, this method tries to find a public
|
||||
* property. The value of the property is then returned.
|
||||
*
|
||||
* If none of them are found, an exception is thrown.
|
||||
*
|
||||
* @param object|array $objectOrArray The object or array to traverse
|
||||
* @param string|PropertyPathInterface $propertyPath The property path to read
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws Exception\InvalidArgumentException If the property path is invalid
|
||||
* @throws Exception\AccessException If a property/index does not exist or is not public
|
||||
* @throws Exception\UnexpectedTypeException If a value within the path is neither object
|
||||
* nor array
|
||||
*/
|
||||
public function getValue($objectOrArray, $propertyPath);
|
||||
/**
|
||||
* Returns whether a value can be written at a given property path.
|
||||
*
|
||||
* Whenever this method returns true, {@link setValue()} is guaranteed not
|
||||
* to throw an exception when called with the same arguments.
|
||||
*
|
||||
* @param object|array $objectOrArray The object or array to check
|
||||
* @param string|PropertyPathInterface $propertyPath The property path to check
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Exception\InvalidArgumentException If the property path is invalid
|
||||
*/
|
||||
public function isWritable($objectOrArray, $propertyPath);
|
||||
/**
|
||||
* Returns whether a property path can be read from an object graph.
|
||||
*
|
||||
* Whenever this method returns true, {@link getValue()} is guaranteed not
|
||||
* to throw an exception when called with the same arguments.
|
||||
*
|
||||
* @param object|array $objectOrArray The object or array to check
|
||||
* @param string|PropertyPathInterface $propertyPath The property path to check
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Exception\InvalidArgumentException If the property path is invalid
|
||||
*/
|
||||
public function isReadable($objectOrArray, $propertyPath);
|
||||
}
|
||||
+178
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\PropertyAccess;
|
||||
|
||||
use JooosiFonDeps\Symfony\Component\PropertyAccess\Exception\InvalidArgumentException;
|
||||
use JooosiFonDeps\Symfony\Component\PropertyAccess\Exception\InvalidPropertyPathException;
|
||||
use JooosiFonDeps\Symfony\Component\PropertyAccess\Exception\OutOfBoundsException;
|
||||
/**
|
||||
* Default implementation of {@link PropertyPathInterface}.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @implements \IteratorAggregate<int, string>
|
||||
*/
|
||||
class PropertyPath implements \IteratorAggregate, PropertyPathInterface
|
||||
{
|
||||
/**
|
||||
* Character used for separating between plural and singular of an element.
|
||||
*/
|
||||
public const SINGULAR_SEPARATOR = '|';
|
||||
/**
|
||||
* The elements of the property path.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
private $elements = [];
|
||||
/**
|
||||
* The number of elements in the property path.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $length;
|
||||
/**
|
||||
* Contains a Boolean for each property in $elements denoting whether this
|
||||
* element is an index. It is a property otherwise.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $isIndex = [];
|
||||
/**
|
||||
* String representation of the path.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $pathAsString;
|
||||
/**
|
||||
* Constructs a property path from a string.
|
||||
*
|
||||
* @param PropertyPath|string $propertyPath The property path as string or instance
|
||||
*
|
||||
* @throws InvalidArgumentException If the given path is not a string
|
||||
* @throws InvalidPropertyPathException If the syntax of the property path is not valid
|
||||
*/
|
||||
public function __construct($propertyPath)
|
||||
{
|
||||
// Can be used as copy constructor
|
||||
if ($propertyPath instanceof self) {
|
||||
/* @var PropertyPath $propertyPath */
|
||||
$this->elements = $propertyPath->elements;
|
||||
$this->length = $propertyPath->length;
|
||||
$this->isIndex = $propertyPath->isIndex;
|
||||
$this->pathAsString = $propertyPath->pathAsString;
|
||||
return;
|
||||
}
|
||||
if (!\is_string($propertyPath)) {
|
||||
throw new InvalidArgumentException(sprintf('The property path constructor needs a string or an instance of "Symfony\Component\PropertyAccess\PropertyPath". Got: "%s".', get_debug_type($propertyPath)));
|
||||
}
|
||||
if ('' === $propertyPath) {
|
||||
throw new InvalidPropertyPathException('The property path should not be empty.');
|
||||
}
|
||||
$this->pathAsString = $propertyPath;
|
||||
$position = 0;
|
||||
$remaining = $propertyPath;
|
||||
// first element is evaluated differently - no leading dot for properties
|
||||
$pattern = '/^(([^\.\[]++)|\[([^\]]++)\])(.*)/';
|
||||
while (preg_match($pattern, $remaining, $matches)) {
|
||||
if ('' !== $matches[2]) {
|
||||
$element = $matches[2];
|
||||
$this->isIndex[] = \false;
|
||||
} else {
|
||||
$element = $matches[3];
|
||||
$this->isIndex[] = \true;
|
||||
}
|
||||
$this->elements[] = $element;
|
||||
$position += \strlen($matches[1]);
|
||||
$remaining = $matches[4];
|
||||
$pattern = '/^(\.([^\.|\[]++)|\[([^\]]++)\])(.*)/';
|
||||
}
|
||||
if ('' !== $remaining) {
|
||||
throw new InvalidPropertyPathException(sprintf('Could not parse property path "%s". Unexpected token "%s" at position %d.', $propertyPath, $remaining[0], $position));
|
||||
}
|
||||
$this->length = \count($this->elements);
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->pathAsString;
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getLength()
|
||||
{
|
||||
return $this->length;
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
if ($this->length <= 1) {
|
||||
return null;
|
||||
}
|
||||
$parent = clone $this;
|
||||
--$parent->length;
|
||||
$parent->pathAsString = substr($parent->pathAsString, 0, max(strrpos($parent->pathAsString, '.'), strrpos($parent->pathAsString, '[')));
|
||||
array_pop($parent->elements);
|
||||
array_pop($parent->isIndex);
|
||||
return $parent;
|
||||
}
|
||||
/**
|
||||
* Returns a new iterator for this path.
|
||||
*
|
||||
* @return PropertyPathIteratorInterface
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
return new PropertyPathIterator($this);
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getElements()
|
||||
{
|
||||
return $this->elements;
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getElement(int $index)
|
||||
{
|
||||
if (!isset($this->elements[$index])) {
|
||||
throw new OutOfBoundsException(sprintf('The index "%s" is not within the property path.', $index));
|
||||
}
|
||||
return $this->elements[$index];
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isProperty(int $index)
|
||||
{
|
||||
if (!isset($this->isIndex[$index])) {
|
||||
throw new OutOfBoundsException(sprintf('The index "%s" is not within the property path.', $index));
|
||||
}
|
||||
return !$this->isIndex[$index];
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isIndex(int $index)
|
||||
{
|
||||
if (!isset($this->isIndex[$index])) {
|
||||
throw new OutOfBoundsException(sprintf('The index "%s" is not within the property path.', $index));
|
||||
}
|
||||
return $this->isIndex[$index];
|
||||
}
|
||||
}
|
||||
+243
@@ -0,0 +1,243 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\PropertyAccess;
|
||||
|
||||
use JooosiFonDeps\Symfony\Component\PropertyAccess\Exception\OutOfBoundsException;
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class PropertyPathBuilder
|
||||
{
|
||||
private $elements = [];
|
||||
private $isIndex = [];
|
||||
/**
|
||||
* Creates a new property path builder.
|
||||
*
|
||||
* @param PropertyPathInterface|string|null $path The path to initially store
|
||||
* in the builder. Optional.
|
||||
*/
|
||||
public function __construct($path = null)
|
||||
{
|
||||
if (null !== $path) {
|
||||
$this->append($path);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Appends a (sub-) path to the current path.
|
||||
*
|
||||
* @param PropertyPathInterface|string $path The path to append
|
||||
* @param int $offset The offset where the appended
|
||||
* piece starts in $path
|
||||
* @param int $length The length of the appended piece
|
||||
* If 0, the full path is appended
|
||||
*/
|
||||
public function append($path, int $offset = 0, int $length = 0)
|
||||
{
|
||||
if (\is_string($path)) {
|
||||
$path = new PropertyPath($path);
|
||||
}
|
||||
if (0 === $length) {
|
||||
$end = $path->getLength();
|
||||
} else {
|
||||
$end = $offset + $length;
|
||||
}
|
||||
for (; $offset < $end; ++$offset) {
|
||||
$this->elements[] = $path->getElement($offset);
|
||||
$this->isIndex[] = $path->isIndex($offset);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Appends an index element to the current path.
|
||||
*/
|
||||
public function appendIndex(string $name)
|
||||
{
|
||||
$this->elements[] = $name;
|
||||
$this->isIndex[] = \true;
|
||||
}
|
||||
/**
|
||||
* Appends a property element to the current path.
|
||||
*/
|
||||
public function appendProperty(string $name)
|
||||
{
|
||||
$this->elements[] = $name;
|
||||
$this->isIndex[] = \false;
|
||||
}
|
||||
/**
|
||||
* Removes elements from the current path.
|
||||
*
|
||||
* @throws OutOfBoundsException if offset is invalid
|
||||
*/
|
||||
public function remove(int $offset, int $length = 1)
|
||||
{
|
||||
if (!isset($this->elements[$offset])) {
|
||||
throw new OutOfBoundsException(sprintf('The offset "%s" is not within the property path.', $offset));
|
||||
}
|
||||
$this->resize($offset, $length, 0);
|
||||
}
|
||||
/**
|
||||
* Replaces a sub-path by a different (sub-) path.
|
||||
*
|
||||
* @param int $offset The offset at which to replace
|
||||
* @param int $length The length of the piece to replace
|
||||
* @param PropertyPathInterface|string $path The path to insert
|
||||
* @param int $pathOffset The offset where the inserted piece
|
||||
* starts in $path
|
||||
* @param int $pathLength The length of the inserted piece
|
||||
* If 0, the full path is inserted
|
||||
*
|
||||
* @throws OutOfBoundsException If the offset is invalid
|
||||
*/
|
||||
public function replace(int $offset, int $length, $path, int $pathOffset = 0, int $pathLength = 0)
|
||||
{
|
||||
if (\is_string($path)) {
|
||||
$path = new PropertyPath($path);
|
||||
}
|
||||
if ($offset < 0 && abs($offset) <= $this->getLength()) {
|
||||
$offset = $this->getLength() + $offset;
|
||||
} elseif (!isset($this->elements[$offset])) {
|
||||
throw new OutOfBoundsException('The offset ' . $offset . ' is not within the property path');
|
||||
}
|
||||
if (0 === $pathLength) {
|
||||
$pathLength = $path->getLength() - $pathOffset;
|
||||
}
|
||||
$this->resize($offset, $length, $pathLength);
|
||||
for ($i = 0; $i < $pathLength; ++$i) {
|
||||
$this->elements[$offset + $i] = $path->getElement($pathOffset + $i);
|
||||
$this->isIndex[$offset + $i] = $path->isIndex($pathOffset + $i);
|
||||
}
|
||||
ksort($this->elements);
|
||||
}
|
||||
/**
|
||||
* Replaces a property element by an index element.
|
||||
*
|
||||
* @throws OutOfBoundsException If the offset is invalid
|
||||
*/
|
||||
public function replaceByIndex(int $offset, ?string $name = null)
|
||||
{
|
||||
if (!isset($this->elements[$offset])) {
|
||||
throw new OutOfBoundsException(sprintf('The offset "%s" is not within the property path.', $offset));
|
||||
}
|
||||
if (null !== $name) {
|
||||
$this->elements[$offset] = $name;
|
||||
}
|
||||
$this->isIndex[$offset] = \true;
|
||||
}
|
||||
/**
|
||||
* Replaces an index element by a property element.
|
||||
*
|
||||
* @throws OutOfBoundsException If the offset is invalid
|
||||
*/
|
||||
public function replaceByProperty(int $offset, ?string $name = null)
|
||||
{
|
||||
if (!isset($this->elements[$offset])) {
|
||||
throw new OutOfBoundsException(sprintf('The offset "%s" is not within the property path.', $offset));
|
||||
}
|
||||
if (null !== $name) {
|
||||
$this->elements[$offset] = $name;
|
||||
}
|
||||
$this->isIndex[$offset] = \false;
|
||||
}
|
||||
/**
|
||||
* Returns the length of the current path.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLength()
|
||||
{
|
||||
return \count($this->elements);
|
||||
}
|
||||
/**
|
||||
* Returns the current property path.
|
||||
*
|
||||
* @return PropertyPathInterface|null
|
||||
*/
|
||||
public function getPropertyPath()
|
||||
{
|
||||
$pathAsString = $this->__toString();
|
||||
return '' !== $pathAsString ? new PropertyPath($pathAsString) : null;
|
||||
}
|
||||
/**
|
||||
* Returns the current property path as string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$string = '';
|
||||
foreach ($this->elements as $offset => $element) {
|
||||
if ($this->isIndex[$offset]) {
|
||||
$element = '[' . $element . ']';
|
||||
} elseif ('' !== $string) {
|
||||
$string .= '.';
|
||||
}
|
||||
$string .= $element;
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
/**
|
||||
* Resizes the path so that a chunk of length $cutLength is
|
||||
* removed at $offset and another chunk of length $insertionLength
|
||||
* can be inserted.
|
||||
*/
|
||||
private function resize(int $offset, int $cutLength, int $insertionLength)
|
||||
{
|
||||
// Nothing else to do in this case
|
||||
if ($insertionLength === $cutLength) {
|
||||
return;
|
||||
}
|
||||
$length = \count($this->elements);
|
||||
if ($cutLength > $insertionLength) {
|
||||
// More elements should be removed than inserted
|
||||
$diff = $cutLength - $insertionLength;
|
||||
$newLength = $length - $diff;
|
||||
// Shift elements to the left (left-to-right until the new end)
|
||||
// Max allowed offset to be shifted is such that
|
||||
// $offset + $diff < $length (otherwise invalid index access)
|
||||
// i.e. $offset < $length - $diff = $newLength
|
||||
for ($i = $offset; $i < $newLength; ++$i) {
|
||||
$this->elements[$i] = $this->elements[$i + $diff];
|
||||
$this->isIndex[$i] = $this->isIndex[$i + $diff];
|
||||
}
|
||||
// All remaining elements should be removed
|
||||
$this->elements = \array_slice($this->elements, 0, $i);
|
||||
$this->isIndex = \array_slice($this->isIndex, 0, $i);
|
||||
} else {
|
||||
$diff = $insertionLength - $cutLength;
|
||||
$newLength = $length + $diff;
|
||||
$indexAfterInsertion = $offset + $insertionLength;
|
||||
// $diff <= $insertionLength
|
||||
// $indexAfterInsertion >= $insertionLength
|
||||
// => $diff <= $indexAfterInsertion
|
||||
// In each of the following loops, $i >= $diff must hold,
|
||||
// otherwise ($i - $diff) becomes negative.
|
||||
// Shift old elements to the right to make up space for the
|
||||
// inserted elements. This needs to be done left-to-right in
|
||||
// order to preserve an ascending array index order
|
||||
// Since $i = max($length, $indexAfterInsertion) and $indexAfterInsertion >= $diff,
|
||||
// $i >= $diff is guaranteed.
|
||||
for ($i = max($length, $indexAfterInsertion); $i < $newLength; ++$i) {
|
||||
$this->elements[$i] = $this->elements[$i - $diff];
|
||||
$this->isIndex[$i] = $this->isIndex[$i - $diff];
|
||||
}
|
||||
// Shift remaining elements to the right. Do this right-to-left
|
||||
// so we don't overwrite elements before copying them
|
||||
// The last written index is the immediate index after the inserted
|
||||
// string, because the indices before that will be overwritten
|
||||
// anyway.
|
||||
// Since $i >= $indexAfterInsertion and $indexAfterInsertion >= $diff,
|
||||
// $i >= $diff is guaranteed.
|
||||
for ($i = $length - 1; $i >= $indexAfterInsertion; --$i) {
|
||||
$this->elements[$i] = $this->elements[$i - $diff];
|
||||
$this->isIndex[$i] = $this->isIndex[$i - $diff];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\PropertyAccess;
|
||||
|
||||
/**
|
||||
* A sequence of property names or array indices.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @extends \Traversable<int, string>
|
||||
*/
|
||||
interface PropertyPathInterface extends \Traversable
|
||||
{
|
||||
/**
|
||||
* Returns the string representation of the property path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString();
|
||||
/**
|
||||
* Returns the length of the property path, i.e. the number of elements.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLength();
|
||||
/**
|
||||
* Returns the parent property path.
|
||||
*
|
||||
* The parent property path is the one that contains the same items as
|
||||
* this one except for the last one.
|
||||
*
|
||||
* If this property path only contains one item, null is returned.
|
||||
*
|
||||
* @return self|null
|
||||
*/
|
||||
public function getParent();
|
||||
/**
|
||||
* Returns the elements of the property path as array.
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public function getElements();
|
||||
/**
|
||||
* Returns the element at the given index in the property path.
|
||||
*
|
||||
* @param int $index The index key
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws Exception\OutOfBoundsException If the offset is invalid
|
||||
*/
|
||||
public function getElement(int $index);
|
||||
/**
|
||||
* Returns whether the element at the given index is a property.
|
||||
*
|
||||
* @param int $index The index in the property path
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Exception\OutOfBoundsException If the offset is invalid
|
||||
*/
|
||||
public function isProperty(int $index);
|
||||
/**
|
||||
* Returns whether the element at the given index is an array index.
|
||||
*
|
||||
* @param int $index The index in the property path
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Exception\OutOfBoundsException If the offset is invalid
|
||||
*/
|
||||
public function isIndex(int $index);
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\PropertyAccess;
|
||||
|
||||
/**
|
||||
* Traverses a property path and provides additional methods to find out
|
||||
* information about the current element.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @extends \ArrayIterator<int, string>
|
||||
*/
|
||||
class PropertyPathIterator extends \ArrayIterator implements PropertyPathIteratorInterface
|
||||
{
|
||||
protected $path;
|
||||
public function __construct(PropertyPathInterface $path)
|
||||
{
|
||||
parent::__construct($path->getElements());
|
||||
$this->path = $path;
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isIndex()
|
||||
{
|
||||
return $this->path->isIndex($this->key());
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isProperty()
|
||||
{
|
||||
return $this->path->isProperty($this->key());
|
||||
}
|
||||
}
|
||||
Vendored
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace JooosiFonDeps\Symfony\Component\PropertyAccess;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @extends \SeekableIterator<int, string>
|
||||
*/
|
||||
interface PropertyPathIteratorInterface extends \SeekableIterator
|
||||
{
|
||||
/**
|
||||
* Returns whether the current element in the property path is an array
|
||||
* index.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isIndex();
|
||||
/**
|
||||
* Returns whether the current element in the property path is a property
|
||||
* name.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isProperty();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
PropertyAccess Component
|
||||
========================
|
||||
|
||||
The PropertyAccess component provides functions to read and write from/to an
|
||||
object or array using a simple string notation.
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
||||
* [Documentation](https://symfony.com/doc/current/components/property_access.html)
|
||||
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
|
||||
* [Report issues](https://github.com/symfony/symfony/issues) and
|
||||
[send Pull Requests](https://github.com/symfony/symfony/pulls)
|
||||
in the [main Symfony repository](https://github.com/symfony/symfony)
|
||||
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"name": "symfony\/property-access",
|
||||
"type": "library",
|
||||
"description": "Provides functions to read and write from\/to an object or array using a simple string notation",
|
||||
"keywords": [
|
||||
"property",
|
||||
"index",
|
||||
"access",
|
||||
"object",
|
||||
"array",
|
||||
"extraction",
|
||||
"injection",
|
||||
"reflection",
|
||||
"property-path"
|
||||
],
|
||||
"homepage": "https:\/\/symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https:\/\/symfony.com\/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.2.5",
|
||||
"symfony\/deprecation-contracts": "^2.1|^3",
|
||||
"symfony\/polyfill-php80": "^1.16",
|
||||
"symfony\/property-info": "^5.2|^6.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony\/cache": "^4.4|^5.0|^6.0"
|
||||
},
|
||||
"suggest": {
|
||||
"psr\/cache-implementation": "To cache access methods."
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"JooosiFonDeps\\Symfony\\Component\\PropertyAccess\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"\/Tests\/"
|
||||
]
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
5.4
|
||||
---
|
||||
|
||||
* Add PhpStanExtractor
|
||||
|
||||
5.3
|
||||
---
|
||||
|
||||
* Add support for multiple types for collection keys & values
|
||||
* Deprecate the `Type::getCollectionKeyType()` and `Type::getCollectionValueType()` methods, use `Type::getCollectionKeyTypes()` and `Type::getCollectionValueTypes()` instead
|
||||
|
||||
5.2.0
|
||||
-----
|
||||
|
||||
* deprecated the `enable_magic_call_extraction` context option in `ReflectionExtractor::getWriteInfo()` and `ReflectionExtractor::getReadInfo()` in favor of `enable_magic_methods_extraction`
|
||||
|
||||
5.1.0
|
||||
-----
|
||||
|
||||
* Add support for extracting accessor and mutator via PHP Reflection
|
||||
|
||||
4.3.0
|
||||
-----
|
||||
|
||||
* Added the ability to extract private and protected properties and methods on `ReflectionExtractor`
|
||||
* Added the ability to extract property type based on its initial value
|
||||
|
||||
4.2.0
|
||||
-----
|
||||
|
||||
* added `PropertyInitializableExtractorInterface` to test if a property can be initialized through the constructor (implemented by `ReflectionExtractor`)
|
||||
|
||||
3.3.0
|
||||
-----
|
||||
|
||||
* Added `PropertyInfoPass`
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user