init
This commit is contained in:
94
backend/vendor/symfony/property-access/CHANGELOG.md
vendored
Normal file
94
backend/vendor/symfony/property-access/CHANGELOG.md
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
7.0
|
||||
---
|
||||
|
||||
* Add method `isNullSafe()` to `PropertyPathInterface`
|
||||
* Require explicit argument when calling `PropertyAccessorBuilder::setCacheItemPool()`
|
||||
|
||||
6.3
|
||||
---
|
||||
|
||||
* Allow escaping `.` and `[` with `\` in `PropertyPath`
|
||||
|
||||
6.2
|
||||
---
|
||||
|
||||
* Deprecate calling `PropertyAccessorBuilder::setCacheItemPool()` without arguments
|
||||
* Added method `isNullSafe()` to `PropertyPathInterface`, implementing the interface without implementing this method
|
||||
is deprecated
|
||||
* Add support for the null-coalesce operator in property paths
|
||||
|
||||
6.0
|
||||
---
|
||||
|
||||
* make `PropertyAccessor::__construct()` accept a combination of bitwise flags as first and second arguments
|
||||
|
||||
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
|
||||
21
backend/vendor/symfony/property-access/Exception/AccessException.php
vendored
Normal file
21
backend/vendor/symfony/property-access/Exception/AccessException.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?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\Component\PropertyAccess\Exception;
|
||||
|
||||
/**
|
||||
* Thrown when a property path is not available.
|
||||
*
|
||||
* @author Stéphane Escandell <stephane.escandell@gmail.com>
|
||||
*/
|
||||
class AccessException extends RuntimeException
|
||||
{
|
||||
}
|
||||
21
backend/vendor/symfony/property-access/Exception/ExceptionInterface.php
vendored
Normal file
21
backend/vendor/symfony/property-access/Exception/ExceptionInterface.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?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\Component\PropertyAccess\Exception;
|
||||
|
||||
/**
|
||||
* Marker interface for the PropertyAccess component.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
interface ExceptionInterface extends \Throwable
|
||||
{
|
||||
}
|
||||
21
backend/vendor/symfony/property-access/Exception/InvalidArgumentException.php
vendored
Normal file
21
backend/vendor/symfony/property-access/Exception/InvalidArgumentException.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?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\Component\PropertyAccess\Exception;
|
||||
|
||||
/**
|
||||
* Base InvalidArgumentException for the PropertyAccess component.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
21
backend/vendor/symfony/property-access/Exception/InvalidPropertyPathException.php
vendored
Normal file
21
backend/vendor/symfony/property-access/Exception/InvalidPropertyPathException.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?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\Component\PropertyAccess\Exception;
|
||||
|
||||
/**
|
||||
* Thrown when a property path is malformed.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class InvalidPropertyPathException extends RuntimeException
|
||||
{
|
||||
}
|
||||
32
backend/vendor/symfony/property-access/Exception/InvalidTypeException.php
vendored
Normal file
32
backend/vendor/symfony/property-access/Exception/InvalidTypeException.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?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\Component\PropertyAccess\Exception;
|
||||
|
||||
/**
|
||||
* Thrown when a type of given value does not match an expected type.
|
||||
*
|
||||
* @author Farhad Safarov <farhad.safarov@gmail.com>
|
||||
*/
|
||||
class InvalidTypeException extends InvalidArgumentException
|
||||
{
|
||||
public function __construct(
|
||||
public readonly string $expectedType,
|
||||
public readonly string $actualType,
|
||||
public readonly string $propertyPath,
|
||||
?\Throwable $previous = null,
|
||||
) {
|
||||
parent::__construct(
|
||||
\sprintf('Expected argument of type "%s", "%s" given at property path "%s".', $expectedType, 'NULL' === $actualType ? 'null' : $actualType, $propertyPath),
|
||||
previous: $previous,
|
||||
);
|
||||
}
|
||||
}
|
||||
21
backend/vendor/symfony/property-access/Exception/NoSuchIndexException.php
vendored
Normal file
21
backend/vendor/symfony/property-access/Exception/NoSuchIndexException.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?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\Component\PropertyAccess\Exception;
|
||||
|
||||
/**
|
||||
* Thrown when an index cannot be found.
|
||||
*
|
||||
* @author Stéphane Escandell <stephane.escandell@gmail.com>
|
||||
*/
|
||||
class NoSuchIndexException extends AccessException
|
||||
{
|
||||
}
|
||||
21
backend/vendor/symfony/property-access/Exception/NoSuchPropertyException.php
vendored
Normal file
21
backend/vendor/symfony/property-access/Exception/NoSuchPropertyException.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?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\Component\PropertyAccess\Exception;
|
||||
|
||||
/**
|
||||
* Thrown when a property cannot be found.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class NoSuchPropertyException extends AccessException
|
||||
{
|
||||
}
|
||||
21
backend/vendor/symfony/property-access/Exception/OutOfBoundsException.php
vendored
Normal file
21
backend/vendor/symfony/property-access/Exception/OutOfBoundsException.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?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\Component\PropertyAccess\Exception;
|
||||
|
||||
/**
|
||||
* Base OutOfBoundsException for the PropertyAccess component.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class OutOfBoundsException extends \OutOfBoundsException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
21
backend/vendor/symfony/property-access/Exception/RuntimeException.php
vendored
Normal file
21
backend/vendor/symfony/property-access/Exception/RuntimeException.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?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\Component\PropertyAccess\Exception;
|
||||
|
||||
/**
|
||||
* Base RuntimeException for the PropertyAccess component.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class RuntimeException extends \RuntimeException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
39
backend/vendor/symfony/property-access/Exception/UnexpectedTypeException.php
vendored
Normal file
39
backend/vendor/symfony/property-access/Exception/UnexpectedTypeException.php
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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\Component\PropertyAccess\Exception;
|
||||
|
||||
use 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(mixed $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);
|
||||
}
|
||||
}
|
||||
21
backend/vendor/symfony/property-access/Exception/UninitializedPropertyException.php
vendored
Normal file
21
backend/vendor/symfony/property-access/Exception/UninitializedPropertyException.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?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\Component\PropertyAccess\Exception;
|
||||
|
||||
/**
|
||||
* Thrown when a property is not initialized.
|
||||
*
|
||||
* @author Jules Pietri <jules@heahprod.com>
|
||||
*/
|
||||
class UninitializedPropertyException extends AccessException
|
||||
{
|
||||
}
|
||||
19
backend/vendor/symfony/property-access/LICENSE
vendored
Normal file
19
backend/vendor/symfony/property-access/LICENSE
vendored
Normal file
@@ -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.
|
||||
40
backend/vendor/symfony/property-access/PropertyAccess.php
vendored
Normal file
40
backend/vendor/symfony/property-access/PropertyAccess.php
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<?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\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()
|
||||
{
|
||||
}
|
||||
}
|
||||
704
backend/vendor/symfony/property-access/PropertyAccessor.php
vendored
Normal file
704
backend/vendor/symfony/property-access/PropertyAccessor.php
vendored
Normal file
@@ -0,0 +1,704 @@
|
||||
<?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\Component\PropertyAccess;
|
||||
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
use Symfony\Component\Cache\Adapter\AdapterInterface;
|
||||
use Symfony\Component\Cache\Adapter\ApcuAdapter;
|
||||
use Symfony\Component\Cache\Adapter\NullAdapter;
|
||||
use Symfony\Component\PropertyAccess\Exception\AccessException;
|
||||
use Symfony\Component\PropertyAccess\Exception\InvalidTypeException;
|
||||
use Symfony\Component\PropertyAccess\Exception\NoSuchIndexException;
|
||||
use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException;
|
||||
use Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\PropertyAccess\Exception\UninitializedPropertyException;
|
||||
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
|
||||
use Symfony\Component\PropertyInfo\PropertyReadInfo;
|
||||
use Symfony\Component\PropertyInfo\PropertyReadInfoExtractorInterface;
|
||||
use Symfony\Component\PropertyInfo\PropertyWriteInfo;
|
||||
use 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 const RESULT_PROTO = [self::VALUE => null];
|
||||
|
||||
private bool $ignoreInvalidIndices;
|
||||
private bool $ignoreInvalidProperty;
|
||||
private ?CacheItemPoolInterface $cacheItemPool;
|
||||
private array $propertyPathCache = [];
|
||||
private PropertyReadInfoExtractorInterface $readInfoExtractor;
|
||||
private PropertyWriteInfoExtractorInterface $writeInfoExtractor;
|
||||
private array $readPropertyCache = [];
|
||||
private array $writePropertyCache = [];
|
||||
|
||||
/**
|
||||
* Should not be used by application code. Use
|
||||
* {@link PropertyAccess::createPropertyAccessor()} instead.
|
||||
*
|
||||
* @param int $magicMethodsFlags 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
|
||||
*/
|
||||
public function __construct(
|
||||
private int $magicMethodsFlags = self::MAGIC_GET | self::MAGIC_SET,
|
||||
int $throw = self::THROW_ON_INVALID_PROPERTY_PATH,
|
||||
?CacheItemPoolInterface $cacheItemPool = null,
|
||||
?PropertyReadInfoExtractorInterface $readInfoExtractor = null,
|
||||
?PropertyWriteInfoExtractorInterface $writeInfoExtractor = null,
|
||||
) {
|
||||
$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);
|
||||
}
|
||||
|
||||
public function getValue(object|array $objectOrArray, string|PropertyPathInterface $propertyPath): mixed
|
||||
{
|
||||
$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];
|
||||
}
|
||||
|
||||
public function setValue(object|array &$objectOrArray, string|PropertyPathInterface $propertyPath, mixed $value): void
|
||||
{
|
||||
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 (preg_match('/^\S+::\S+\(\): Argument #\d+ \(\$\S+\) must be of type (\S+), (\S+) given/', $message, $matches)) {
|
||||
[, $expectedType, $actualType] = $matches;
|
||||
|
||||
throw new InvalidTypeException($expectedType, $actualType, $propertyPath, $previous);
|
||||
}
|
||||
if (preg_match('/^Cannot assign (\S+) to property \S+::\$\S+ of type (\S+)$/', $message, $matches)) {
|
||||
[, $actualType, $expectedType] = $matches;
|
||||
|
||||
throw new InvalidTypeException($expectedType, $actualType, $propertyPath, $previous);
|
||||
}
|
||||
}
|
||||
|
||||
public function isReadable(object|array $objectOrArray, string|PropertyPathInterface $propertyPath): bool
|
||||
{
|
||||
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|UnexpectedTypeException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function isWritable(object|array $objectOrArray, string|PropertyPathInterface $propertyPath): bool
|
||||
{
|
||||
$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|UnexpectedTypeException) {
|
||||
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);
|
||||
$isNullSafe = $propertyPath->isNullSafe($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 && !$isNullSafe) {
|
||||
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);
|
||||
} elseif ($isNullSafe && !\is_object($zval[self::VALUE])) {
|
||||
$zval[self::VALUE] = null;
|
||||
} else {
|
||||
$zval = $this->readProperty($zval, $property, $this->ignoreInvalidProperty, $isNullSafe);
|
||||
}
|
||||
|
||||
// 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]) && !$isNullSafe) {
|
||||
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;
|
||||
|
||||
if ($isNullSafe && null === $zval[self::VALUE]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $propertyValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a key from an array-like structure.
|
||||
*
|
||||
* @throws NoSuchIndexException If the array does not implement \ArrayAccess or it is not an array
|
||||
*/
|
||||
private function readIndex(array $zval, string|int $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, bool $isNullSafe = 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 = $object::class;
|
||||
$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 (!isset($object->$name) && !\array_key_exists($name, (array) $object)) {
|
||||
try {
|
||||
$r = new \ReflectionProperty($class, $name);
|
||||
|
||||
if ($r->isPublic() && !$r->hasType()) {
|
||||
throw new UninitializedPropertyException(\sprintf('The property "%s::$%s" is not initialized.', $class, $name));
|
||||
}
|
||||
} catch (\ReflectionException $e) {
|
||||
if (!$ignoreInvalidProperty) {
|
||||
throw new NoSuchPropertyException(\sprintf('Can\'t get a way to read the property "%s" in class "%s".', $property, $class));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$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 (preg_match('/^Typed property ([\w\\\\@]+)::\$(\w+) must not be accessed before initialization$/', $e->getMessage(), $matches) || preg_match('/^Cannot access uninitialized non-nullable property ([\w\\\\@]+)::\$(\w+) by reference$/', $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 ($isNullSafe) {
|
||||
$result[self::VALUE] = null;
|
||||
} 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.
|
||||
*
|
||||
* @throws NoSuchIndexException If the array does not implement \ArrayAccess or it is not an array
|
||||
*/
|
||||
private function writeIndex(array $zval, string|int $index, mixed $value): void
|
||||
{
|
||||
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.
|
||||
*
|
||||
* @throws NoSuchPropertyException if the property does not exist or is not public
|
||||
*/
|
||||
private function writeProperty(array $zval, string $property, mixed $value, bool $recursive = false): void
|
||||
{
|
||||
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 = $object::class;
|
||||
$mutator = $this->getWriteInfo($class, $property, $value);
|
||||
|
||||
try {
|
||||
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)));
|
||||
}
|
||||
} catch (\TypeError $e) {
|
||||
if ($recursive || !$value instanceof \DateTimeInterface || !\in_array($value::class, ['DateTime', 'DateTimeImmutable'], true) || __FILE__ !== ($e->getTrace()[0]['file'] ?? null)) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$value = $value instanceof \DateTimeImmutable ? \DateTime::createFromImmutable($value) : \DateTimeImmutable::createFromMutable($value);
|
||||
try {
|
||||
$this->writeProperty($zval, $property, $value, true);
|
||||
} catch (\TypeError) {
|
||||
throw $e; // throw the previous error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts a collection-valued property by calling add*() and remove*() methods.
|
||||
*/
|
||||
private function writeCollection(array $zval, string $property, iterable $collection, PropertyWriteInfo $addMethod, PropertyWriteInfo $removeMethod): void
|
||||
{
|
||||
// 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, mixed $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
|
||||
{
|
||||
if ($object instanceof \stdClass && property_exists($object, $property)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$mutatorForArray = $this->getWriteInfo($object::class, $property, []);
|
||||
if (PropertyWriteInfo::TYPE_PROPERTY === $mutatorForArray->getType()) {
|
||||
return 'public' === $mutatorForArray->getVisibility();
|
||||
}
|
||||
|
||||
if (PropertyWriteInfo::TYPE_NONE !== $mutatorForArray->getType()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$mutator = $this->getWriteInfo($object::class, $property, '');
|
||||
|
||||
return PropertyWriteInfo::TYPE_NONE !== $mutator->getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a PropertyPath instance and caches it.
|
||||
*/
|
||||
private function getPropertyPath(string|PropertyPath $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.
|
||||
*
|
||||
* @throws \LogicException When the Cache Component isn't available
|
||||
*/
|
||||
public static function createCache(string $namespace, int $defaultLifetime, string $version, ?LoggerInterface $logger = null): AdapterInterface
|
||||
{
|
||||
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_BOOL)) {
|
||||
$apcu->setLogger(new NullLogger());
|
||||
} elseif (null !== $logger) {
|
||||
$apcu->setLogger($logger);
|
||||
}
|
||||
|
||||
return $apcu;
|
||||
}
|
||||
}
|
||||
291
backend/vendor/symfony/property-access/PropertyAccessorBuilder.php
vendored
Normal file
291
backend/vendor/symfony/property-access/PropertyAccessorBuilder.php
vendored
Normal file
@@ -0,0 +1,291 @@
|
||||
<?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\Component\PropertyAccess;
|
||||
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Component\PropertyInfo\PropertyReadInfoExtractorInterface;
|
||||
use Symfony\Component\PropertyInfo\PropertyWriteInfoExtractorInterface;
|
||||
|
||||
/**
|
||||
* A configurable builder to create a PropertyAccessor.
|
||||
*
|
||||
* @author Jérémie Augustin <jeremie.augustin@pixel-cookers.com>
|
||||
*/
|
||||
class PropertyAccessorBuilder
|
||||
{
|
||||
private int $magicMethods = PropertyAccessor::MAGIC_GET | PropertyAccessor::MAGIC_SET;
|
||||
private bool $throwExceptionOnInvalidIndex = false;
|
||||
private bool $throwExceptionOnInvalidPropertyPath = true;
|
||||
private ?CacheItemPoolInterface $cacheItemPool = null;
|
||||
private ?PropertyReadInfoExtractorInterface $readInfoExtractor = null;
|
||||
private ?PropertyWriteInfoExtractorInterface $writeInfoExtractor = null;
|
||||
|
||||
/**
|
||||
* Enables the use of all magic methods by the PropertyAccessor.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function enableMagicMethods(): static
|
||||
{
|
||||
$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(): static
|
||||
{
|
||||
$this->magicMethods = PropertyAccessor::DISALLOW_MAGIC_METHODS;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the use of "__call" by the PropertyAccessor.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function enableMagicCall(): static
|
||||
{
|
||||
$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(): static
|
||||
{
|
||||
$this->magicMethods |= PropertyAccessor::MAGIC_SET;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the use of "__call" by the PropertyAccessor.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function disableMagicCall(): static
|
||||
{
|
||||
$this->magicMethods &= ~PropertyAccessor::MAGIC_CALL;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the use of "__get" by the PropertyAccessor.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function disableMagicGet(): static
|
||||
{
|
||||
$this->magicMethods &= ~PropertyAccessor::MAGIC_GET;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the use of "__set" by the PropertyAccessor.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function disableMagicSet(): static
|
||||
{
|
||||
$this->magicMethods &= ~PropertyAccessor::MAGIC_SET;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool whether the use of "__call" by the PropertyAccessor is enabled
|
||||
*/
|
||||
public function isMagicCallEnabled(): bool
|
||||
{
|
||||
return $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(): static
|
||||
{
|
||||
$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(): static
|
||||
{
|
||||
$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(): bool
|
||||
{
|
||||
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(): static
|
||||
{
|
||||
$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(): static
|
||||
{
|
||||
$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(): bool
|
||||
{
|
||||
return $this->throwExceptionOnInvalidPropertyPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a cache system.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCacheItemPool(?CacheItemPoolInterface $cacheItemPool): static
|
||||
{
|
||||
$this->cacheItemPool = $cacheItemPool;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the used cache system.
|
||||
*/
|
||||
public function getCacheItemPool(): ?CacheItemPoolInterface
|
||||
{
|
||||
return $this->cacheItemPool;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setReadInfoExtractor(?PropertyReadInfoExtractorInterface $readInfoExtractor): static
|
||||
{
|
||||
$this->readInfoExtractor = $readInfoExtractor;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getReadInfoExtractor(): ?PropertyReadInfoExtractorInterface
|
||||
{
|
||||
return $this->readInfoExtractor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setWriteInfoExtractor(?PropertyWriteInfoExtractorInterface $writeInfoExtractor): static
|
||||
{
|
||||
$this->writeInfoExtractor = $writeInfoExtractor;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getWriteInfoExtractor(): ?PropertyWriteInfoExtractorInterface
|
||||
{
|
||||
return $this->writeInfoExtractor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and returns a new PropertyAccessor object.
|
||||
*/
|
||||
public function getPropertyAccessor(): PropertyAccessorInterface
|
||||
{
|
||||
$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);
|
||||
}
|
||||
}
|
||||
101
backend/vendor/symfony/property-access/PropertyAccessorInterface.php
vendored
Normal file
101
backend/vendor/symfony/property-access/PropertyAccessorInterface.php
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
<?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\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.
|
||||
*
|
||||
* @template T of object|array
|
||||
*
|
||||
* @param T $objectOrArray
|
||||
*
|
||||
* @param-out ($objectOrArray is array ? array : T) $objectOrArray
|
||||
*
|
||||
* @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(object|array &$objectOrArray, string|PropertyPathInterface $propertyPath, mixed $value): void;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @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(object|array $objectOrArray, string|PropertyPathInterface $propertyPath): mixed;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @throws Exception\InvalidArgumentException If the property path is invalid
|
||||
*/
|
||||
public function isWritable(object|array $objectOrArray, string|PropertyPathInterface $propertyPath): bool;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @throws Exception\InvalidArgumentException If the property path is invalid
|
||||
*/
|
||||
public function isReadable(object|array $objectOrArray, string|PropertyPathInterface $propertyPath): bool;
|
||||
}
|
||||
205
backend/vendor/symfony/property-access/PropertyPath.php
vendored
Normal file
205
backend/vendor/symfony/property-access/PropertyPath.php
vendored
Normal file
@@ -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\Component\PropertyAccess;
|
||||
|
||||
use Symfony\Component\PropertyAccess\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\PropertyAccess\Exception\InvalidPropertyPathException;
|
||||
use 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 array $elements = [];
|
||||
|
||||
/**
|
||||
* The number of elements in the property path.
|
||||
*/
|
||||
private int $length;
|
||||
|
||||
/**
|
||||
* Contains a Boolean for each property in $elements denoting whether this
|
||||
* element is an index. It is a property otherwise.
|
||||
*
|
||||
* @var array<bool>
|
||||
*/
|
||||
private array $isIndex = [];
|
||||
|
||||
/**
|
||||
* Contains a Boolean for each property in $elements denoting whether this
|
||||
* element is optional or not.
|
||||
*
|
||||
* @var array<bool>
|
||||
*/
|
||||
private array $isNullSafe = [];
|
||||
|
||||
/**
|
||||
* String representation of the path.
|
||||
*/
|
||||
private string $pathAsString;
|
||||
|
||||
/**
|
||||
* Constructs a property path from a string.
|
||||
*
|
||||
* @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(self|string $propertyPath)
|
||||
{
|
||||
// Can be used as copy constructor
|
||||
if ($propertyPath instanceof self) {
|
||||
$this->elements = $propertyPath->elements;
|
||||
$this->length = $propertyPath->length;
|
||||
$this->isIndex = $propertyPath->isIndex;
|
||||
$this->isNullSafe = $propertyPath->isNullSafe;
|
||||
$this->pathAsString = $propertyPath->pathAsString;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// Mark as optional when last character is "?".
|
||||
if (str_ends_with($element, '?')) {
|
||||
$this->isNullSafe[] = true;
|
||||
$element = substr($element, 0, -1);
|
||||
} else {
|
||||
$this->isNullSafe[] = false;
|
||||
}
|
||||
|
||||
$element = preg_replace('/\\\([.[])/', '$1', $element);
|
||||
if (str_ends_with($element, '\\\\')) {
|
||||
$element = substr($element, 0, -1);
|
||||
}
|
||||
$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);
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->pathAsString;
|
||||
}
|
||||
|
||||
public function getLength(): int
|
||||
{
|
||||
return $this->length;
|
||||
}
|
||||
|
||||
public function getParent(): ?PropertyPathInterface
|
||||
{
|
||||
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);
|
||||
array_pop($parent->isNullSafe);
|
||||
|
||||
return $parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new iterator for this path.
|
||||
*/
|
||||
public function getIterator(): PropertyPathIteratorInterface
|
||||
{
|
||||
return new PropertyPathIterator($this);
|
||||
}
|
||||
|
||||
public function getElements(): array
|
||||
{
|
||||
return $this->elements;
|
||||
}
|
||||
|
||||
public function getElement(int $index): string
|
||||
{
|
||||
if (!isset($this->elements[$index])) {
|
||||
throw new OutOfBoundsException(\sprintf('The index "%s" is not within the property path.', $index));
|
||||
}
|
||||
|
||||
return $this->elements[$index];
|
||||
}
|
||||
|
||||
public function isProperty(int $index): bool
|
||||
{
|
||||
if (!isset($this->isIndex[$index])) {
|
||||
throw new OutOfBoundsException(\sprintf('The index "%s" is not within the property path.', $index));
|
||||
}
|
||||
|
||||
return !$this->isIndex[$index];
|
||||
}
|
||||
|
||||
public function isIndex(int $index): bool
|
||||
{
|
||||
if (!isset($this->isIndex[$index])) {
|
||||
throw new OutOfBoundsException(\sprintf('The index "%s" is not within the property path.', $index));
|
||||
}
|
||||
|
||||
return $this->isIndex[$index];
|
||||
}
|
||||
|
||||
public function isNullSafe(int $index): bool
|
||||
{
|
||||
if (!isset($this->isNullSafe[$index])) {
|
||||
throw new OutOfBoundsException(\sprintf('The index "%s" is not within the property path.', $index));
|
||||
}
|
||||
|
||||
return $this->isNullSafe[$index];
|
||||
}
|
||||
}
|
||||
261
backend/vendor/symfony/property-access/PropertyPathBuilder.php
vendored
Normal file
261
backend/vendor/symfony/property-access/PropertyPathBuilder.php
vendored
Normal file
@@ -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 Symfony\Component\PropertyAccess;
|
||||
|
||||
use Symfony\Component\PropertyAccess\Exception\OutOfBoundsException;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class PropertyPathBuilder
|
||||
{
|
||||
private array $elements = [];
|
||||
private array $isIndex = [];
|
||||
|
||||
public function __construct(PropertyPathInterface|string|null $path = null)
|
||||
{
|
||||
if (null !== $path) {
|
||||
$this->append($path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a (sub-) path to the current path.
|
||||
*
|
||||
* @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(PropertyPathInterface|string $path, int $offset = 0, int $length = 0): void
|
||||
{
|
||||
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): void
|
||||
{
|
||||
$this->elements[] = $name;
|
||||
$this->isIndex[] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a property element to the current path.
|
||||
*/
|
||||
public function appendProperty(string $name): void
|
||||
{
|
||||
$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): void
|
||||
{
|
||||
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 $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, PropertyPathInterface|string $path, int $pathOffset = 0, int $pathLength = 0): void
|
||||
{
|
||||
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): void
|
||||
{
|
||||
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): void
|
||||
{
|
||||
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.
|
||||
*/
|
||||
public function getLength(): int
|
||||
{
|
||||
return \count($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current property path.
|
||||
*/
|
||||
public function getPropertyPath(): ?PropertyPathInterface
|
||||
{
|
||||
$pathAsString = $this->__toString();
|
||||
|
||||
return '' !== $pathAsString ? new PropertyPath($pathAsString) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current property path as string.
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
$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): void
|
||||
{
|
||||
// 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
backend/vendor/symfony/property-access/PropertyPathInterface.php
vendored
Normal file
81
backend/vendor/symfony/property-access/PropertyPathInterface.php
vendored
Normal file
@@ -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 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, \Stringable
|
||||
{
|
||||
/**
|
||||
* Returns the string representation of the property path.
|
||||
*/
|
||||
public function __toString(): string;
|
||||
|
||||
/**
|
||||
* Returns the length of the property path, i.e. the number of elements.
|
||||
*/
|
||||
public function getLength(): int;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public function getParent(): ?self;
|
||||
|
||||
/**
|
||||
* Returns the elements of the property path as array.
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public function getElements(): array;
|
||||
|
||||
/**
|
||||
* Returns the element at the given index in the property path.
|
||||
*
|
||||
* @param int $index The index key
|
||||
*
|
||||
* @throws Exception\OutOfBoundsException If the offset is invalid
|
||||
*/
|
||||
public function getElement(int $index): string;
|
||||
|
||||
/**
|
||||
* Returns whether the element at the given index is a property.
|
||||
*
|
||||
* @param int $index The index in the property path
|
||||
*
|
||||
* @throws Exception\OutOfBoundsException If the offset is invalid
|
||||
*/
|
||||
public function isProperty(int $index): bool;
|
||||
|
||||
/**
|
||||
* Returns whether the element at the given index is an array index.
|
||||
*
|
||||
* @param int $index The index in the property path
|
||||
*
|
||||
* @throws Exception\OutOfBoundsException If the offset is invalid
|
||||
*/
|
||||
public function isIndex(int $index): bool;
|
||||
|
||||
/**
|
||||
* Returns whether the element at the given index is null safe.
|
||||
*/
|
||||
public function isNullSafe(int $index): bool;
|
||||
}
|
||||
39
backend/vendor/symfony/property-access/PropertyPathIterator.php
vendored
Normal file
39
backend/vendor/symfony/property-access/PropertyPathIterator.php
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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\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
|
||||
{
|
||||
public function __construct(
|
||||
protected PropertyPathInterface $path,
|
||||
) {
|
||||
parent::__construct($path->getElements());
|
||||
}
|
||||
|
||||
public function isIndex(): bool
|
||||
{
|
||||
return $this->path->isIndex($this->key());
|
||||
}
|
||||
|
||||
public function isProperty(): bool
|
||||
{
|
||||
return $this->path->isProperty($this->key());
|
||||
}
|
||||
}
|
||||
32
backend/vendor/symfony/property-access/PropertyPathIteratorInterface.php
vendored
Normal file
32
backend/vendor/symfony/property-access/PropertyPathIteratorInterface.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?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\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.
|
||||
*/
|
||||
public function isIndex(): bool;
|
||||
|
||||
/**
|
||||
* Returns whether the current element in the property path is a property
|
||||
* name.
|
||||
*/
|
||||
public function isProperty(): bool;
|
||||
}
|
||||
14
backend/vendor/symfony/property-access/README.md
vendored
Normal file
14
backend/vendor/symfony/property-access/README.md
vendored
Normal file
@@ -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)
|
||||
33
backend/vendor/symfony/property-access/composer.json
vendored
Normal file
33
backend/vendor/symfony/property-access/composer.json
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"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": ">=8.2",
|
||||
"symfony/property-info": "^6.4.32|~7.3.10|^7.4.4|^8.0.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/cache": "^6.4|^7.0|^8.0",
|
||||
"symfony/var-exporter": "^6.4.1|^7.0.1|^8.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Symfony\\Component\\PropertyAccess\\": "" },
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
Reference in New Issue
Block a user