v1.0 Initial commit of project
This commit is contained in:
3
vendor/symfony/property-access/.gitattributes
vendored
Normal file
3
vendor/symfony/property-access/.gitattributes
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/Tests export-ignore
|
||||
/phpunit.xml.dist export-ignore
|
||||
/.git* export-ignore
|
||||
8
vendor/symfony/property-access/.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
8
vendor/symfony/property-access/.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
Please do not submit any Pull Requests here. They will be closed.
|
||||
---
|
||||
|
||||
Please submit your PR here instead:
|
||||
https://github.com/symfony/symfony
|
||||
|
||||
This repository is what we call a "subtree split": a read-only subset of that main repository.
|
||||
We're looking forward to your PR there!
|
||||
20
vendor/symfony/property-access/.github/workflows/close-pull-request.yml
vendored
Normal file
20
vendor/symfony/property-access/.github/workflows/close-pull-request.yml
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
name: Close Pull Request
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [opened]
|
||||
|
||||
jobs:
|
||||
run:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: superbrothers/close-pull-request@v3
|
||||
with:
|
||||
comment: |
|
||||
Thanks for your Pull Request! We love contributions.
|
||||
|
||||
However, you should instead open your PR on the main repository:
|
||||
https://github.com/symfony/symfony
|
||||
|
||||
This repository is what we call a "subtree split": a read-only subset of that main repository.
|
||||
We're looking forward to your PR there!
|
||||
3
vendor/symfony/property-access/.gitignore
vendored
Normal file
3
vendor/symfony/property-access/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
vendor/
|
||||
composer.lock
|
||||
phpunit.xml
|
||||
70
vendor/symfony/property-access/CHANGELOG.md
vendored
Normal file
70
vendor/symfony/property-access/CHANGELOG.md
vendored
Normal file
@@ -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
|
||||
21
vendor/symfony/property-access/Exception/AccessException.php
vendored
Normal file
21
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
vendor/symfony/property-access/Exception/ExceptionInterface.php
vendored
Normal file
21
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
vendor/symfony/property-access/Exception/InvalidArgumentException.php
vendored
Normal file
21
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
vendor/symfony/property-access/Exception/InvalidPropertyPathException.php
vendored
Normal file
21
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
|
||||
{
|
||||
}
|
||||
21
vendor/symfony/property-access/Exception/NoSuchIndexException.php
vendored
Normal file
21
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
vendor/symfony/property-access/Exception/NoSuchPropertyException.php
vendored
Normal file
21
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
vendor/symfony/property-access/Exception/OutOfBoundsException.php
vendored
Normal file
21
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
vendor/symfony/property-access/Exception/RuntimeException.php
vendored
Normal file
21
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
vendor/symfony/property-access/Exception/UnexpectedTypeException.php
vendored
Normal file
39
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($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
vendor/symfony/property-access/Exception/UninitializedPropertyException.php
vendored
Normal file
21
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
vendor/symfony/property-access/LICENSE
vendored
Normal file
19
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
vendor/symfony/property-access/PropertyAccess.php
vendored
Normal file
40
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()
|
||||
{
|
||||
}
|
||||
}
|
||||
762
vendor/symfony/property-access/PropertyAccessor.php
vendored
Normal file
762
vendor/symfony/property-access/PropertyAccessor.php
vendored
Normal file
@@ -0,0 +1,762 @@
|
||||
<?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\InvalidArgumentException;
|
||||
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 $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;
|
||||
}
|
||||
}
|
||||
308
vendor/symfony/property-access/PropertyAccessorBuilder.php
vendored
Normal file
308
vendor/symfony/property-access/PropertyAccessorBuilder.php
vendored
Normal file
@@ -0,0 +1,308 @@
|
||||
<?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
|
||||
{
|
||||
/** @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);
|
||||
}
|
||||
}
|
||||
114
vendor/symfony/property-access/PropertyAccessorInterface.php
vendored
Normal file
114
vendor/symfony/property-access/PropertyAccessorInterface.php
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
<?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.
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
208
vendor/symfony/property-access/PropertyPath.php
vendored
Normal file
208
vendor/symfony/property-access/PropertyPath.php
vendored
Normal file
@@ -0,0 +1,208 @@
|
||||
<?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 $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];
|
||||
}
|
||||
}
|
||||
281
vendor/symfony/property-access/PropertyPathBuilder.php
vendored
Normal file
281
vendor/symfony/property-access/PropertyPathBuilder.php
vendored
Normal file
@@ -0,0 +1,281 @@
|
||||
<?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 $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];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
88
vendor/symfony/property-access/PropertyPathInterface.php
vendored
Normal file
88
vendor/symfony/property-access/PropertyPathInterface.php
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
<?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
|
||||
{
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
48
vendor/symfony/property-access/PropertyPathIterator.php
vendored
Normal file
48
vendor/symfony/property-access/PropertyPathIterator.php
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
<?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
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
36
vendor/symfony/property-access/PropertyPathIteratorInterface.php
vendored
Normal file
36
vendor/symfony/property-access/PropertyPathIteratorInterface.php
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isIndex();
|
||||
|
||||
/**
|
||||
* Returns whether the current element in the property path is a property
|
||||
* name.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isProperty();
|
||||
}
|
||||
14
vendor/symfony/property-access/README.md
vendored
Normal file
14
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)
|
||||
17
vendor/symfony/property-access/Tests/Fixtures/ExtendedUninitializedProperty.php
vendored
Normal file
17
vendor/symfony/property-access/Tests/Fixtures/ExtendedUninitializedProperty.php
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
<?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\Tests\Fixtures;
|
||||
|
||||
class ExtendedUninitializedProperty extends UninitializedProperty
|
||||
{
|
||||
|
||||
}
|
||||
81
vendor/symfony/property-access/Tests/Fixtures/NonTraversableArrayObject.php
vendored
Normal file
81
vendor/symfony/property-access/Tests/Fixtures/NonTraversableArrayObject.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\Tests\Fixtures;
|
||||
|
||||
/**
|
||||
* This class is a hand written simplified version of PHP native `ArrayObject`
|
||||
* class, to show that it behaves differently than the PHP native implementation.
|
||||
*/
|
||||
class NonTraversableArrayObject implements \ArrayAccess, \Countable, \Serializable
|
||||
{
|
||||
private $array;
|
||||
|
||||
public function __construct(?array $array = null)
|
||||
{
|
||||
$this->array = $array ?: [];
|
||||
}
|
||||
|
||||
public function offsetExists($offset): bool
|
||||
{
|
||||
return \array_key_exists($offset, $this->array);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $offset
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
return $this->array[$offset];
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value): void
|
||||
{
|
||||
if (null === $offset) {
|
||||
$this->array[] = $value;
|
||||
} else {
|
||||
$this->array[$offset] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function offsetUnset($offset): void
|
||||
{
|
||||
unset($this->array[$offset]);
|
||||
}
|
||||
|
||||
public function count(): int
|
||||
{
|
||||
return \count($this->array);
|
||||
}
|
||||
|
||||
public function __serialize(): array
|
||||
{
|
||||
return $this->array;
|
||||
}
|
||||
|
||||
public function serialize(): string
|
||||
{
|
||||
return serialize($this->__serialize());
|
||||
}
|
||||
|
||||
public function __unserialize(array $data): void
|
||||
{
|
||||
$this->array = $data;
|
||||
}
|
||||
|
||||
public function unserialize($serialized): void
|
||||
{
|
||||
$this->__unserialize((array) unserialize((string) $serialized));
|
||||
}
|
||||
}
|
||||
36
vendor/symfony/property-access/Tests/Fixtures/ReturnTyped.php
vendored
Normal file
36
vendor/symfony/property-access/Tests/Fixtures/ReturnTyped.php
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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\Tests\Fixtures;
|
||||
|
||||
/**
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
class ReturnTyped
|
||||
{
|
||||
public function getFoos(): array
|
||||
{
|
||||
return 'It doesn\'t respect the return type on purpose';
|
||||
}
|
||||
|
||||
public function addFoo(\DateTime $dateTime)
|
||||
{
|
||||
}
|
||||
|
||||
public function removeFoo(\DateTime $dateTime)
|
||||
{
|
||||
}
|
||||
|
||||
public function setName($name): self
|
||||
{
|
||||
return 'This does not respect the return type on purpose.';
|
||||
}
|
||||
}
|
||||
27
vendor/symfony/property-access/Tests/Fixtures/TestAdderRemoverInvalidArgumentLength.php
vendored
Normal file
27
vendor/symfony/property-access/Tests/Fixtures/TestAdderRemoverInvalidArgumentLength.php
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<?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\Tests\Fixtures;
|
||||
|
||||
class TestAdderRemoverInvalidArgumentLength
|
||||
{
|
||||
public function addFoo()
|
||||
{
|
||||
}
|
||||
|
||||
public function removeFoo($var1, $var2)
|
||||
{
|
||||
}
|
||||
|
||||
public function setBar($var1, $var2)
|
||||
{
|
||||
}
|
||||
}
|
||||
23
vendor/symfony/property-access/Tests/Fixtures/TestAdderRemoverInvalidMethods.php
vendored
Normal file
23
vendor/symfony/property-access/Tests/Fixtures/TestAdderRemoverInvalidMethods.php
vendored
Normal file
@@ -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.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\PropertyAccess\Tests\Fixtures;
|
||||
|
||||
class TestAdderRemoverInvalidMethods
|
||||
{
|
||||
public function addFoo($foo)
|
||||
{
|
||||
}
|
||||
|
||||
public function removeBar($foo)
|
||||
{
|
||||
}
|
||||
}
|
||||
204
vendor/symfony/property-access/Tests/Fixtures/TestClass.php
vendored
Normal file
204
vendor/symfony/property-access/Tests/Fixtures/TestClass.php
vendored
Normal file
@@ -0,0 +1,204 @@
|
||||
<?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\Tests\Fixtures;
|
||||
|
||||
class TestClass
|
||||
{
|
||||
public $publicProperty;
|
||||
protected $protectedProperty;
|
||||
private $privateProperty;
|
||||
|
||||
private $publicAccessor;
|
||||
private $publicMethodAccessor;
|
||||
private $publicGetSetter;
|
||||
private $publicAccessorWithDefaultValue;
|
||||
private $publicAccessorWithRequiredAndDefaultValue;
|
||||
private $publicAccessorWithMoreRequiredParameters;
|
||||
private $publicIsAccessor;
|
||||
private $publicHasAccessor;
|
||||
private $publicCanAccessor;
|
||||
private $publicGetter;
|
||||
private $date;
|
||||
|
||||
public function __construct($value)
|
||||
{
|
||||
$this->publicProperty = $value;
|
||||
$this->publicAccessor = $value;
|
||||
$this->publicMethodAccessor = $value;
|
||||
$this->publicGetSetter = $value;
|
||||
$this->publicAccessorWithDefaultValue = $value;
|
||||
$this->publicAccessorWithRequiredAndDefaultValue = $value;
|
||||
$this->publicAccessorWithMoreRequiredParameters = $value;
|
||||
$this->publicIsAccessor = $value;
|
||||
$this->publicHasAccessor = $value;
|
||||
$this->publicCanAccessor = $value;
|
||||
$this->publicGetter = $value;
|
||||
}
|
||||
|
||||
public function setPublicAccessor($value)
|
||||
{
|
||||
$this->publicAccessor = $value;
|
||||
}
|
||||
|
||||
public function setPublicAccessorWithDefaultValue($value = null)
|
||||
{
|
||||
$this->publicAccessorWithDefaultValue = $value;
|
||||
}
|
||||
|
||||
public function setPublicAccessorWithRequiredAndDefaultValue($value, $optional = null)
|
||||
{
|
||||
$this->publicAccessorWithRequiredAndDefaultValue = $value;
|
||||
}
|
||||
|
||||
public function setPublicAccessorWithMoreRequiredParameters($value, $needed)
|
||||
{
|
||||
$this->publicAccessorWithMoreRequiredParameters = $value;
|
||||
}
|
||||
|
||||
public function getPublicAccessor()
|
||||
{
|
||||
return $this->publicAccessor;
|
||||
}
|
||||
|
||||
public function isPublicAccessor($param)
|
||||
{
|
||||
throw new \LogicException('This method should never have been called.');
|
||||
}
|
||||
|
||||
public function getPublicAccessorWithDefaultValue()
|
||||
{
|
||||
return $this->publicAccessorWithDefaultValue;
|
||||
}
|
||||
|
||||
public function getPublicAccessorWithRequiredAndDefaultValue()
|
||||
{
|
||||
return $this->publicAccessorWithRequiredAndDefaultValue;
|
||||
}
|
||||
|
||||
public function getPublicAccessorWithMoreRequiredParameters()
|
||||
{
|
||||
return $this->publicAccessorWithMoreRequiredParameters;
|
||||
}
|
||||
|
||||
public function setPublicIsAccessor($value)
|
||||
{
|
||||
$this->publicIsAccessor = $value;
|
||||
}
|
||||
|
||||
public function isPublicIsAccessor()
|
||||
{
|
||||
return $this->publicIsAccessor;
|
||||
}
|
||||
|
||||
public function setPublicHasAccessor($value)
|
||||
{
|
||||
$this->publicHasAccessor = $value;
|
||||
}
|
||||
|
||||
public function hasPublicHasAccessor()
|
||||
{
|
||||
return $this->publicHasAccessor;
|
||||
}
|
||||
|
||||
public function setPublicCanAccessor($value)
|
||||
{
|
||||
$this->publicCanAccessor = $value;
|
||||
}
|
||||
|
||||
public function canPublicCanAccessor()
|
||||
{
|
||||
return $this->publicCanAccessor;
|
||||
}
|
||||
|
||||
public function publicGetSetter($value = null)
|
||||
{
|
||||
if (null !== $value) {
|
||||
$this->publicGetSetter = $value;
|
||||
}
|
||||
|
||||
return $this->publicGetSetter;
|
||||
}
|
||||
|
||||
public function getPublicMethodMutator()
|
||||
{
|
||||
return $this->publicGetSetter;
|
||||
}
|
||||
|
||||
protected function setProtectedAccessor($value)
|
||||
{
|
||||
}
|
||||
|
||||
protected function getProtectedAccessor()
|
||||
{
|
||||
return 'foobar';
|
||||
}
|
||||
|
||||
protected function setProtectedIsAccessor($value)
|
||||
{
|
||||
}
|
||||
|
||||
protected function isProtectedIsAccessor()
|
||||
{
|
||||
return 'foobar';
|
||||
}
|
||||
|
||||
protected function setProtectedHasAccessor($value)
|
||||
{
|
||||
}
|
||||
|
||||
protected function hasProtectedHasAccessor()
|
||||
{
|
||||
return 'foobar';
|
||||
}
|
||||
|
||||
private function setPrivateAccessor($value)
|
||||
{
|
||||
}
|
||||
|
||||
private function getPrivateAccessor()
|
||||
{
|
||||
return 'foobar';
|
||||
}
|
||||
|
||||
private function setPrivateIsAccessor($value)
|
||||
{
|
||||
}
|
||||
|
||||
private function isPrivateIsAccessor()
|
||||
{
|
||||
return 'foobar';
|
||||
}
|
||||
|
||||
private function setPrivateHasAccessor($value)
|
||||
{
|
||||
}
|
||||
|
||||
private function hasPrivateHasAccessor()
|
||||
{
|
||||
return 'foobar';
|
||||
}
|
||||
|
||||
public function getPublicGetter()
|
||||
{
|
||||
return $this->publicGetter;
|
||||
}
|
||||
|
||||
public function setDate(\DateTimeInterface $date)
|
||||
{
|
||||
$this->date = $date;
|
||||
}
|
||||
|
||||
public function getDate()
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
}
|
||||
27
vendor/symfony/property-access/Tests/Fixtures/TestClassIsWritable.php
vendored
Normal file
27
vendor/symfony/property-access/Tests/Fixtures/TestClassIsWritable.php
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<?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\Tests\Fixtures;
|
||||
|
||||
class TestClassIsWritable
|
||||
{
|
||||
protected $value;
|
||||
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function __construct($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
}
|
||||
39
vendor/symfony/property-access/Tests/Fixtures/TestClassMagicCall.php
vendored
Normal file
39
vendor/symfony/property-access/Tests/Fixtures/TestClassMagicCall.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\Tests\Fixtures;
|
||||
|
||||
class TestClassMagicCall
|
||||
{
|
||||
private $magicCallProperty;
|
||||
|
||||
public function __construct($value)
|
||||
{
|
||||
$this->magicCallProperty = $value;
|
||||
}
|
||||
|
||||
public function __call(string $method, array $args)
|
||||
{
|
||||
if ('getMagicCallProperty' === $method) {
|
||||
return $this->magicCallProperty;
|
||||
}
|
||||
|
||||
if ('getConstantMagicCallProperty' === $method) {
|
||||
return 'constant value';
|
||||
}
|
||||
|
||||
if ('setMagicCallProperty' === $method) {
|
||||
$this->magicCallProperty = reset($args);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
42
vendor/symfony/property-access/Tests/Fixtures/TestClassMagicGet.php
vendored
Normal file
42
vendor/symfony/property-access/Tests/Fixtures/TestClassMagicGet.php
vendored
Normal file
@@ -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.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\PropertyAccess\Tests\Fixtures;
|
||||
|
||||
class TestClassMagicGet
|
||||
{
|
||||
private $magicProperty;
|
||||
|
||||
public $publicProperty;
|
||||
|
||||
public function __construct($value)
|
||||
{
|
||||
$this->magicProperty = $value;
|
||||
}
|
||||
|
||||
public function __set(string $property, $value)
|
||||
{
|
||||
if ('magicProperty' === $property) {
|
||||
$this->magicProperty = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function __get(string $property)
|
||||
{
|
||||
if ('magicProperty' === $property) {
|
||||
return $this->magicProperty;
|
||||
}
|
||||
|
||||
if ('constantMagicProperty' === $property) {
|
||||
return 'constant value';
|
||||
}
|
||||
}
|
||||
}
|
||||
36
vendor/symfony/property-access/Tests/Fixtures/TestClassSetValue.php
vendored
Normal file
36
vendor/symfony/property-access/Tests/Fixtures/TestClassSetValue.php
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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\Tests\Fixtures;
|
||||
|
||||
class TestClassSetValue
|
||||
{
|
||||
protected $value;
|
||||
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function __construct($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
private function setFoo()
|
||||
{
|
||||
}
|
||||
}
|
||||
28
vendor/symfony/property-access/Tests/Fixtures/TestClassTypeErrorInsideCall.php
vendored
Normal file
28
vendor/symfony/property-access/Tests/Fixtures/TestClassTypeErrorInsideCall.php
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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\Tests\Fixtures;
|
||||
|
||||
class TestClassTypeErrorInsideCall
|
||||
{
|
||||
public function expectsDateTime(\DateTime $date)
|
||||
{
|
||||
}
|
||||
|
||||
public function getProperty()
|
||||
{
|
||||
}
|
||||
|
||||
public function setProperty($property)
|
||||
{
|
||||
$this->expectsDateTime(null); // throws TypeError
|
||||
}
|
||||
}
|
||||
17
vendor/symfony/property-access/Tests/Fixtures/TestClassTypedProperty.php
vendored
Normal file
17
vendor/symfony/property-access/Tests/Fixtures/TestClassTypedProperty.php
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
<?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\Tests\Fixtures;
|
||||
|
||||
class TestClassTypedProperty
|
||||
{
|
||||
public float $publicProperty;
|
||||
}
|
||||
21
vendor/symfony/property-access/Tests/Fixtures/TestPublicPropertyDynamicallyCreated.php
vendored
Normal file
21
vendor/symfony/property-access/Tests/Fixtures/TestPublicPropertyDynamicallyCreated.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\Tests\Fixtures;
|
||||
|
||||
#[\AllowDynamicProperties]
|
||||
class TestPublicPropertyDynamicallyCreated
|
||||
{
|
||||
public function __construct(string $bar)
|
||||
{
|
||||
$this->foo = $bar;
|
||||
}
|
||||
}
|
||||
18
vendor/symfony/property-access/Tests/Fixtures/TestPublicPropertyGetterOnObject.php
vendored
Normal file
18
vendor/symfony/property-access/Tests/Fixtures/TestPublicPropertyGetterOnObject.php
vendored
Normal file
@@ -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 Symfony\Component\PropertyAccess\Tests\Fixtures;
|
||||
|
||||
class TestPublicPropertyGetterOnObject
|
||||
{
|
||||
public $a = 'A';
|
||||
private $b = 'B';
|
||||
}
|
||||
25
vendor/symfony/property-access/Tests/Fixtures/TestPublicPropertyGetterOnObjectMagicGet.php
vendored
Normal file
25
vendor/symfony/property-access/Tests/Fixtures/TestPublicPropertyGetterOnObjectMagicGet.php
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<?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\Tests\Fixtures;
|
||||
|
||||
class TestPublicPropertyGetterOnObjectMagicGet
|
||||
{
|
||||
public $a = 'A';
|
||||
private $b = 'B';
|
||||
|
||||
public function __get($property)
|
||||
{
|
||||
if ('b' === $property) {
|
||||
return $this->b;
|
||||
}
|
||||
}
|
||||
}
|
||||
50
vendor/symfony/property-access/Tests/Fixtures/TestSingularAndPluralProps.php
vendored
Normal file
50
vendor/symfony/property-access/Tests/Fixtures/TestSingularAndPluralProps.php
vendored
Normal file
@@ -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 Symfony\Component\PropertyAccess\Tests\Fixtures;
|
||||
|
||||
/**
|
||||
* Notice we don't have getter/setter for emails
|
||||
* because we count on adder/remover.
|
||||
*/
|
||||
class TestSingularAndPluralProps
|
||||
{
|
||||
/** @var string|null */
|
||||
private $email;
|
||||
|
||||
/** @var array */
|
||||
private $emails = [];
|
||||
|
||||
public function getEmail(): ?string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function setEmail(?string $email)
|
||||
{
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
public function getEmails(): array
|
||||
{
|
||||
return $this->emails;
|
||||
}
|
||||
|
||||
public function addEmail(string $email)
|
||||
{
|
||||
$this->emails[] = $email;
|
||||
}
|
||||
|
||||
public function removeEmail(string $email)
|
||||
{
|
||||
$this->emails = array_diff($this->emails, [$email]);
|
||||
}
|
||||
}
|
||||
31
vendor/symfony/property-access/Tests/Fixtures/Ticket5775Object.php
vendored
Normal file
31
vendor/symfony/property-access/Tests/Fixtures/Ticket5775Object.php
vendored
Normal file
@@ -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.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\PropertyAccess\Tests\Fixtures;
|
||||
|
||||
class Ticket5775Object
|
||||
{
|
||||
private $property;
|
||||
|
||||
public function getProperty()
|
||||
{
|
||||
return $this->property;
|
||||
}
|
||||
|
||||
private function setProperty()
|
||||
{
|
||||
}
|
||||
|
||||
public function __set(string $property, $value)
|
||||
{
|
||||
$this->$property = $value;
|
||||
}
|
||||
}
|
||||
86
vendor/symfony/property-access/Tests/Fixtures/TraversableArrayObject.php
vendored
Normal file
86
vendor/symfony/property-access/Tests/Fixtures/TraversableArrayObject.php
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
<?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\Tests\Fixtures;
|
||||
|
||||
/**
|
||||
* This class is a hand written simplified version of PHP native `ArrayObject`
|
||||
* class, to show that it behaves differently than the PHP native implementation.
|
||||
*/
|
||||
class TraversableArrayObject implements \ArrayAccess, \IteratorAggregate, \Countable, \Serializable
|
||||
{
|
||||
private $array;
|
||||
|
||||
public function __construct(?array $array = null)
|
||||
{
|
||||
$this->array = $array ?: [];
|
||||
}
|
||||
|
||||
public function offsetExists($offset): bool
|
||||
{
|
||||
return \array_key_exists($offset, $this->array);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $offset
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
return $this->array[$offset];
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value): void
|
||||
{
|
||||
if (null === $offset) {
|
||||
$this->array[] = $value;
|
||||
} else {
|
||||
$this->array[$offset] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function offsetUnset($offset): void
|
||||
{
|
||||
unset($this->array[$offset]);
|
||||
}
|
||||
|
||||
public function getIterator(): \Traversable
|
||||
{
|
||||
return new \ArrayIterator($this->array);
|
||||
}
|
||||
|
||||
public function count(): int
|
||||
{
|
||||
return \count($this->array);
|
||||
}
|
||||
|
||||
public function __serialize(): array
|
||||
{
|
||||
return $this->array;
|
||||
}
|
||||
|
||||
public function serialize(): string
|
||||
{
|
||||
return serialize($this->__serialize());
|
||||
}
|
||||
|
||||
public function __unserialize(array $data): void
|
||||
{
|
||||
$this->array = $data;
|
||||
}
|
||||
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
$this->__unserialize((array) unserialize((string) $serialized));
|
||||
}
|
||||
}
|
||||
45
vendor/symfony/property-access/Tests/Fixtures/TypeHinted.php
vendored
Normal file
45
vendor/symfony/property-access/Tests/Fixtures/TypeHinted.php
vendored
Normal file
@@ -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 Symfony\Component\PropertyAccess\Tests\Fixtures;
|
||||
|
||||
/**
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
class TypeHinted
|
||||
{
|
||||
private $date;
|
||||
|
||||
/**
|
||||
* @var \Countable
|
||||
*/
|
||||
private $countable;
|
||||
|
||||
public function setDate(\DateTime $date)
|
||||
{
|
||||
$this->date = $date;
|
||||
}
|
||||
|
||||
public function getDate()
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
public function getCountable(): \Countable
|
||||
{
|
||||
return $this->countable;
|
||||
}
|
||||
|
||||
public function setCountable(\Countable $countable)
|
||||
{
|
||||
$this->countable = $countable;
|
||||
}
|
||||
}
|
||||
22
vendor/symfony/property-access/Tests/Fixtures/UninitializedPrivateProperty.php
vendored
Normal file
22
vendor/symfony/property-access/Tests/Fixtures/UninitializedPrivateProperty.php
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<?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\Tests\Fixtures;
|
||||
|
||||
class UninitializedPrivateProperty
|
||||
{
|
||||
private $uninitialized;
|
||||
|
||||
public function getUninitialized(): array
|
||||
{
|
||||
return $this->uninitialized;
|
||||
}
|
||||
}
|
||||
28
vendor/symfony/property-access/Tests/Fixtures/UninitializedProperty.php
vendored
Normal file
28
vendor/symfony/property-access/Tests/Fixtures/UninitializedProperty.php
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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\Tests\Fixtures;
|
||||
|
||||
class UninitializedProperty
|
||||
{
|
||||
public string $uninitialized;
|
||||
private string $privateUninitialized;
|
||||
|
||||
public function getPrivateUninitialized(): string
|
||||
{
|
||||
return $this->privateUninitialized;
|
||||
}
|
||||
|
||||
public function setPrivateUninitialized(string $privateUninitialized): void
|
||||
{
|
||||
$this->privateUninitialized = $privateUninitialized;
|
||||
}
|
||||
}
|
||||
102
vendor/symfony/property-access/Tests/PropertyAccessorArrayAccessTestCase.php
vendored
Normal file
102
vendor/symfony/property-access/Tests/PropertyAccessorArrayAccessTestCase.php
vendored
Normal file
@@ -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 Symfony\Component\PropertyAccess\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\PropertyAccess\Exception\NoSuchIndexException;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccess;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccessor;
|
||||
|
||||
abstract class PropertyAccessorArrayAccessTestCase extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var PropertyAccessor
|
||||
*/
|
||||
protected $propertyAccessor;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->propertyAccessor = new PropertyAccessor();
|
||||
}
|
||||
|
||||
abstract protected static function getContainer(array $array);
|
||||
|
||||
public static function getValidPropertyPaths(): array
|
||||
{
|
||||
return [
|
||||
[static::getContainer(['firstName' => 'Bernhard']), '[firstName]', 'Bernhard'],
|
||||
[static::getContainer(['person' => static::getContainer(['firstName' => 'Bernhard'])]), '[person][firstName]', 'Bernhard'],
|
||||
];
|
||||
}
|
||||
|
||||
public static function getInvalidPropertyPaths(): array
|
||||
{
|
||||
return [
|
||||
[static::getContainer(['firstName' => 'Bernhard']), 'firstName', 'Bernhard'],
|
||||
[static::getContainer(['person' => static::getContainer(['firstName' => 'Bernhard'])]), 'person.firstName', 'Bernhard'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getValidPropertyPaths
|
||||
*/
|
||||
public function testGetValue($collection, $path, $value)
|
||||
{
|
||||
$this->assertSame($value, $this->propertyAccessor->getValue($collection, $path));
|
||||
}
|
||||
|
||||
public function testGetValueFailsIfNoSuchIndex()
|
||||
{
|
||||
$this->expectException(NoSuchIndexException::class);
|
||||
$this->propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()
|
||||
->enableExceptionOnInvalidIndex()
|
||||
->getPropertyAccessor();
|
||||
|
||||
$object = static::getContainer(['firstName' => 'Bernhard']);
|
||||
|
||||
$this->propertyAccessor->getValue($object, '[lastName]');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getValidPropertyPaths
|
||||
*/
|
||||
public function testSetValue($collection, $path)
|
||||
{
|
||||
$this->propertyAccessor->setValue($collection, $path, 'Updated');
|
||||
|
||||
$this->assertSame('Updated', $this->propertyAccessor->getValue($collection, $path));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getValidPropertyPaths
|
||||
*/
|
||||
public function testIsReadable($collection, $path)
|
||||
{
|
||||
$this->assertTrue($this->propertyAccessor->isReadable($collection, $path));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getValidPropertyPaths
|
||||
*/
|
||||
public function testIsWritable($collection, $path)
|
||||
{
|
||||
$this->assertTrue($this->propertyAccessor->isWritable($collection, $path));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidPropertyPaths
|
||||
*/
|
||||
public function testIsNotWritable($collection, $path)
|
||||
{
|
||||
$this->assertFalse($this->propertyAccessor->isWritable($collection, $path));
|
||||
}
|
||||
}
|
||||
20
vendor/symfony/property-access/Tests/PropertyAccessorArrayObjectTest.php
vendored
Normal file
20
vendor/symfony/property-access/Tests/PropertyAccessorArrayObjectTest.php
vendored
Normal file
@@ -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 Symfony\Component\PropertyAccess\Tests;
|
||||
|
||||
class PropertyAccessorArrayObjectTest extends PropertyAccessorCollectionTestCase
|
||||
{
|
||||
protected static function getContainer(array $array)
|
||||
{
|
||||
return new \ArrayObject($array);
|
||||
}
|
||||
}
|
||||
20
vendor/symfony/property-access/Tests/PropertyAccessorArrayTest.php
vendored
Normal file
20
vendor/symfony/property-access/Tests/PropertyAccessorArrayTest.php
vendored
Normal file
@@ -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 Symfony\Component\PropertyAccess\Tests;
|
||||
|
||||
class PropertyAccessorArrayTest extends PropertyAccessorCollectionTestCase
|
||||
{
|
||||
protected static function getContainer(array $array)
|
||||
{
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
128
vendor/symfony/property-access/Tests/PropertyAccessorBuilderTest.php
vendored
Normal file
128
vendor/symfony/property-access/Tests/PropertyAccessorBuilderTest.php
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
<?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\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccessor;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccessorBuilder;
|
||||
use Symfony\Component\PropertyInfo\PropertyReadInfoExtractorInterface;
|
||||
use Symfony\Component\PropertyInfo\PropertyWriteInfoExtractorInterface;
|
||||
|
||||
class PropertyAccessorBuilderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var PropertyAccessorBuilder
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->builder = new PropertyAccessorBuilder();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->builder = null;
|
||||
}
|
||||
|
||||
public function testEnableMagicGet()
|
||||
{
|
||||
$this->assertSame($this->builder, $this->builder->enableMagicGet());
|
||||
$this->assertTrue($this->builder->isMagicGetEnabled());
|
||||
}
|
||||
|
||||
public function testDisableMagicGet()
|
||||
{
|
||||
$this->assertSame($this->builder, $this->builder->disableMagicGet());
|
||||
$this->assertFalse($this->builder->disableMagicGet()->isMagicGetEnabled());
|
||||
}
|
||||
|
||||
public function testEnableMagicSet()
|
||||
{
|
||||
$this->assertSame($this->builder, $this->builder->enableMagicSet());
|
||||
$this->assertTrue($this->builder->isMagicSetEnabled());
|
||||
}
|
||||
|
||||
public function testDisableMagicSet()
|
||||
{
|
||||
$this->assertSame($this->builder, $this->builder->disableMagicSet());
|
||||
$this->assertFalse($this->builder->disableMagicSet()->isMagicSetEnabled());
|
||||
}
|
||||
|
||||
public function testEnableMagicCall()
|
||||
{
|
||||
$this->assertSame($this->builder, $this->builder->enableMagicCall());
|
||||
$this->assertTrue($this->builder->isMagicCallEnabled());
|
||||
}
|
||||
|
||||
public function testDisableMagicCall()
|
||||
{
|
||||
$this->assertSame($this->builder, $this->builder->disableMagicCall());
|
||||
$this->assertFalse($this->builder->isMagicCallEnabled());
|
||||
}
|
||||
|
||||
public function testTogglingMagicGet()
|
||||
{
|
||||
$this->assertTrue($this->builder->isMagicGetEnabled());
|
||||
$this->assertFalse($this->builder->disableMagicGet()->isMagicGetEnabled());
|
||||
$this->assertTrue($this->builder->enableMagicGet()->isMagicGetEnabled());
|
||||
}
|
||||
|
||||
public function testTogglingMagicSet()
|
||||
{
|
||||
$this->assertTrue($this->builder->isMagicSetEnabled());
|
||||
$this->assertFalse($this->builder->disableMagicSet()->isMagicSetEnabled());
|
||||
$this->assertTrue($this->builder->enableMagicSet()->isMagicSetEnabled());
|
||||
}
|
||||
|
||||
public function testTogglingMagicCall()
|
||||
{
|
||||
$this->assertFalse($this->builder->isMagicCallEnabled());
|
||||
$this->assertTrue($this->builder->enableMagicCall()->isMagicCallEnabled());
|
||||
$this->assertFalse($this->builder->disableMagicCall()->isMagicCallEnabled());
|
||||
}
|
||||
|
||||
public function testGetPropertyAccessor()
|
||||
{
|
||||
$this->assertInstanceOf(PropertyAccessor::class, $this->builder->getPropertyAccessor());
|
||||
$this->assertInstanceOf(PropertyAccessor::class, $this->builder->enableMagicCall()->getPropertyAccessor());
|
||||
}
|
||||
|
||||
public function testUseCache()
|
||||
{
|
||||
$cacheItemPool = new ArrayAdapter();
|
||||
$this->builder->setCacheItemPool($cacheItemPool);
|
||||
$this->assertEquals($cacheItemPool, $this->builder->getCacheItemPool());
|
||||
$this->assertInstanceOf(PropertyAccessor::class, $this->builder->getPropertyAccessor());
|
||||
}
|
||||
|
||||
public function testUseReadInfoExtractor()
|
||||
{
|
||||
$readInfoExtractor = $this->createMock(PropertyReadInfoExtractorInterface::class);
|
||||
|
||||
$this->builder->setReadInfoExtractor($readInfoExtractor);
|
||||
|
||||
$this->assertSame($readInfoExtractor, $this->builder->getReadInfoExtractor());
|
||||
$this->assertInstanceOf(PropertyAccessor::class, $this->builder->getPropertyAccessor());
|
||||
}
|
||||
|
||||
public function testUseWriteInfoExtractor()
|
||||
{
|
||||
$writeInfoExtractor = $this->createMock(PropertyWriteInfoExtractorInterface::class);
|
||||
|
||||
$this->builder->setWriteInfoExtractor($writeInfoExtractor);
|
||||
|
||||
$this->assertSame($writeInfoExtractor, $this->builder->getWriteInfoExtractor());
|
||||
$this->assertInstanceOf(PropertyAccessor::class, $this->builder->getPropertyAccessor());
|
||||
}
|
||||
}
|
||||
204
vendor/symfony/property-access/Tests/PropertyAccessorCollectionTestCase.php
vendored
Normal file
204
vendor/symfony/property-access/Tests/PropertyAccessorCollectionTestCase.php
vendored
Normal file
@@ -0,0 +1,204 @@
|
||||
<?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\Tests;
|
||||
|
||||
use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException;
|
||||
|
||||
class PropertyAccessorCollectionTestCase_Car
|
||||
{
|
||||
private $axes;
|
||||
|
||||
public function __construct($axes = null)
|
||||
{
|
||||
$this->axes = $axes;
|
||||
}
|
||||
|
||||
// In the test, use a name that StringUtil can't uniquely singularify
|
||||
public function addAxis($axis)
|
||||
{
|
||||
$this->axes[] = $axis;
|
||||
}
|
||||
|
||||
public function removeAxis($axis)
|
||||
{
|
||||
foreach ($this->axes as $key => $value) {
|
||||
if ($value === $axis) {
|
||||
unset($this->axes[$key]);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getAxes()
|
||||
{
|
||||
return $this->axes;
|
||||
}
|
||||
}
|
||||
|
||||
class PropertyAccessorCollectionTestCase_CarOnlyAdder
|
||||
{
|
||||
public function addAxis($axis)
|
||||
{
|
||||
}
|
||||
|
||||
public function getAxes()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class PropertyAccessorCollectionTestCase_CarOnlyRemover
|
||||
{
|
||||
public function removeAxis($axis)
|
||||
{
|
||||
}
|
||||
|
||||
public function getAxes()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class PropertyAccessorCollectionTestCase_CarNoAdderAndRemover
|
||||
{
|
||||
public function getAxes()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class PropertyAccessorCollectionTestCase_CompositeCar
|
||||
{
|
||||
public function getStructure()
|
||||
{
|
||||
}
|
||||
|
||||
public function setStructure($structure)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class PropertyAccessorCollectionTestCase_CarStructure
|
||||
{
|
||||
public function addAxis($axis)
|
||||
{
|
||||
}
|
||||
|
||||
public function removeAxis($axis)
|
||||
{
|
||||
}
|
||||
|
||||
public function getAxes()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
abstract class PropertyAccessorCollectionTestCase extends PropertyAccessorArrayAccessTestCase
|
||||
{
|
||||
public function testSetValueCallsAdderAndRemoverForCollections()
|
||||
{
|
||||
$axesBefore = $this->getContainer([1 => 'second', 3 => 'fourth', 4 => 'fifth']);
|
||||
$axesMerged = $this->getContainer([1 => 'first', 2 => 'second', 3 => 'third']);
|
||||
$axesAfter = $this->getContainer([1 => 'second', 5 => 'first', 6 => 'third']);
|
||||
$axesMergedCopy = \is_object($axesMerged) ? clone $axesMerged : $axesMerged;
|
||||
|
||||
// Don't use a mock in order to test whether the collections are
|
||||
// modified while iterating them
|
||||
$car = new PropertyAccessorCollectionTestCase_Car($axesBefore);
|
||||
|
||||
$this->propertyAccessor->setValue($car, 'axes', $axesMerged);
|
||||
|
||||
$this->assertEquals($axesAfter, $car->getAxes());
|
||||
|
||||
// The passed collection was not modified
|
||||
$this->assertEquals($axesMergedCopy, $axesMerged);
|
||||
}
|
||||
|
||||
public function testSetValueCallsAdderAndRemoverForNestedCollections()
|
||||
{
|
||||
$car = $this->createMock(__CLASS__.'_CompositeCar');
|
||||
$structure = $this->createMock(__CLASS__.'_CarStructure');
|
||||
$axesBefore = $this->getContainer([1 => 'second', 3 => 'fourth']);
|
||||
$axesAfter = $this->getContainer([0 => 'first', 1 => 'second', 2 => 'third']);
|
||||
|
||||
$car->expects($this->any())
|
||||
->method('getStructure')
|
||||
->willReturn($structure);
|
||||
|
||||
$structure->expects($this->once())
|
||||
->method('getAxes')
|
||||
->willReturn($axesBefore);
|
||||
$structure->expects($this->once())
|
||||
->method('removeAxis')
|
||||
->with('fourth');
|
||||
|
||||
$structure->expects($this->exactly(2))
|
||||
->method('addAxis')
|
||||
->willReturnCallback(function (string $axis) {
|
||||
static $series = [
|
||||
'first',
|
||||
'third',
|
||||
];
|
||||
|
||||
$this->assertSame(array_shift($series), $axis);
|
||||
})
|
||||
;
|
||||
|
||||
$this->propertyAccessor->setValue($car, 'structure.axes', $axesAfter);
|
||||
}
|
||||
|
||||
public function testSetValueFailsIfNoAdderNorRemoverFound()
|
||||
{
|
||||
$this->expectException(NoSuchPropertyException::class);
|
||||
$this->expectExceptionMessageMatches('/Could not determine access type for property "axes" in class "Mock_PropertyAccessorCollectionTestCase_CarNoAdderAndRemover_[^"]*"./');
|
||||
$car = $this->createMock(__CLASS__.'_CarNoAdderAndRemover');
|
||||
$axesBefore = $this->getContainer([1 => 'second', 3 => 'fourth']);
|
||||
$axesAfter = $this->getContainer([0 => 'first', 1 => 'second', 2 => 'third']);
|
||||
|
||||
$car->expects($this->any())
|
||||
->method('getAxes')
|
||||
->willReturn($axesBefore);
|
||||
|
||||
$this->propertyAccessor->setValue($car, 'axes', $axesAfter);
|
||||
}
|
||||
|
||||
public function testIsWritableReturnsTrueIfAdderAndRemoverExists()
|
||||
{
|
||||
$car = new PropertyAccessorCollectionTestCase_Car();
|
||||
$this->assertTrue($this->propertyAccessor->isWritable($car, 'axes'));
|
||||
}
|
||||
|
||||
public function testIsWritableReturnsFalseIfOnlyAdderExists()
|
||||
{
|
||||
$car = new PropertyAccessorCollectionTestCase_CarOnlyAdder();
|
||||
$this->assertFalse($this->propertyAccessor->isWritable($car, 'axes'));
|
||||
}
|
||||
|
||||
public function testIsWritableReturnsFalseIfOnlyRemoverExists()
|
||||
{
|
||||
$car = new PropertyAccessorCollectionTestCase_CarOnlyRemover();
|
||||
$this->assertFalse($this->propertyAccessor->isWritable($car, 'axes'));
|
||||
}
|
||||
|
||||
public function testIsWritableReturnsFalseIfNoAdderNorRemoverExists()
|
||||
{
|
||||
$car = new PropertyAccessorCollectionTestCase_CarNoAdderAndRemover();
|
||||
$this->assertFalse($this->propertyAccessor->isWritable($car, 'axes'));
|
||||
}
|
||||
|
||||
public function testSetValueFailsIfAdderAndRemoverExistButValueIsNotTraversable()
|
||||
{
|
||||
$this->expectException(NoSuchPropertyException::class);
|
||||
$this->expectExceptionMessageMatches('/The property "axes" in class "Symfony\\\Component\\\PropertyAccess\\\Tests\\\PropertyAccessorCollectionTestCase_Car" can be defined with the methods "addAxis\(\)", "removeAxis\(\)" but the new value must be an array or an instance of \\\Traversable\./');
|
||||
$car = new PropertyAccessorCollectionTestCase_Car();
|
||||
|
||||
$this->propertyAccessor->setValue($car, 'axes', 'Not an array or Traversable');
|
||||
}
|
||||
}
|
||||
22
vendor/symfony/property-access/Tests/PropertyAccessorNonTraversableArrayObjectTest.php
vendored
Normal file
22
vendor/symfony/property-access/Tests/PropertyAccessorNonTraversableArrayObjectTest.php
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<?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\Tests;
|
||||
|
||||
use Symfony\Component\PropertyAccess\Tests\Fixtures\NonTraversableArrayObject;
|
||||
|
||||
class PropertyAccessorNonTraversableArrayObjectTest extends PropertyAccessorArrayAccessTestCase
|
||||
{
|
||||
protected static function getContainer(array $array)
|
||||
{
|
||||
return new NonTraversableArrayObject($array);
|
||||
}
|
||||
}
|
||||
1073
vendor/symfony/property-access/Tests/PropertyAccessorTest.php
vendored
Normal file
1073
vendor/symfony/property-access/Tests/PropertyAccessorTest.php
vendored
Normal file
File diff suppressed because it is too large
Load Diff
22
vendor/symfony/property-access/Tests/PropertyAccessorTraversableArrayObjectTest.php
vendored
Normal file
22
vendor/symfony/property-access/Tests/PropertyAccessorTraversableArrayObjectTest.php
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<?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\Tests;
|
||||
|
||||
use Symfony\Component\PropertyAccess\Tests\Fixtures\TraversableArrayObject;
|
||||
|
||||
class PropertyAccessorTraversableArrayObjectTest extends PropertyAccessorCollectionTestCase
|
||||
{
|
||||
protected static function getContainer(array $array)
|
||||
{
|
||||
return new TraversableArrayObject($array);
|
||||
}
|
||||
}
|
||||
297
vendor/symfony/property-access/Tests/PropertyPathBuilderTest.php
vendored
Normal file
297
vendor/symfony/property-access/Tests/PropertyPathBuilderTest.php
vendored
Normal file
@@ -0,0 +1,297 @@
|
||||
<?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\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\PropertyAccess\PropertyPath;
|
||||
use Symfony\Component\PropertyAccess\PropertyPathBuilder;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class PropertyPathBuilderTest extends TestCase
|
||||
{
|
||||
private const PREFIX = 'old1[old2].old3[old4][old5].old6';
|
||||
|
||||
/**
|
||||
* @var PropertyPathBuilder
|
||||
*/
|
||||
private $builder;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->builder = new PropertyPathBuilder(new PropertyPath(self::PREFIX));
|
||||
}
|
||||
|
||||
public function testCreateEmpty()
|
||||
{
|
||||
$builder = new PropertyPathBuilder();
|
||||
|
||||
$this->assertNull($builder->getPropertyPath());
|
||||
}
|
||||
|
||||
public function testCreateCopyPath()
|
||||
{
|
||||
$this->assertEquals(new PropertyPath(self::PREFIX), $this->builder->getPropertyPath());
|
||||
}
|
||||
|
||||
public function testAppendIndex()
|
||||
{
|
||||
$this->builder->appendIndex('new1');
|
||||
|
||||
$path = new PropertyPath(self::PREFIX.'[new1]');
|
||||
|
||||
$this->assertEquals($path, $this->builder->getPropertyPath());
|
||||
}
|
||||
|
||||
public function testAppendProperty()
|
||||
{
|
||||
$this->builder->appendProperty('new1');
|
||||
|
||||
$path = new PropertyPath(self::PREFIX.'.new1');
|
||||
|
||||
$this->assertEquals($path, $this->builder->getPropertyPath());
|
||||
}
|
||||
|
||||
public function testAppend()
|
||||
{
|
||||
$this->builder->append(new PropertyPath('new1[new2]'));
|
||||
|
||||
$path = new PropertyPath(self::PREFIX.'.new1[new2]');
|
||||
|
||||
$this->assertEquals($path, $this->builder->getPropertyPath());
|
||||
}
|
||||
|
||||
public function testAppendUsingString()
|
||||
{
|
||||
$this->builder->append('new1[new2]');
|
||||
|
||||
$path = new PropertyPath(self::PREFIX.'.new1[new2]');
|
||||
|
||||
$this->assertEquals($path, $this->builder->getPropertyPath());
|
||||
}
|
||||
|
||||
public function testAppendWithOffset()
|
||||
{
|
||||
$this->builder->append(new PropertyPath('new1[new2].new3'), 1);
|
||||
|
||||
$path = new PropertyPath(self::PREFIX.'[new2].new3');
|
||||
|
||||
$this->assertEquals($path, $this->builder->getPropertyPath());
|
||||
}
|
||||
|
||||
public function testAppendWithOffsetAndLength()
|
||||
{
|
||||
$this->builder->append(new PropertyPath('new1[new2].new3'), 1, 1);
|
||||
|
||||
$path = new PropertyPath(self::PREFIX.'[new2]');
|
||||
|
||||
$this->assertEquals($path, $this->builder->getPropertyPath());
|
||||
}
|
||||
|
||||
public function testReplaceByIndex()
|
||||
{
|
||||
$this->builder->replaceByIndex(1, 'new1');
|
||||
|
||||
$path = new PropertyPath('old1[new1].old3[old4][old5].old6');
|
||||
|
||||
$this->assertEquals($path, $this->builder->getPropertyPath());
|
||||
}
|
||||
|
||||
public function testReplaceByIndexWithoutName()
|
||||
{
|
||||
$this->builder->replaceByIndex(0);
|
||||
|
||||
$path = new PropertyPath('[old1][old2].old3[old4][old5].old6');
|
||||
|
||||
$this->assertEquals($path, $this->builder->getPropertyPath());
|
||||
}
|
||||
|
||||
public function testReplaceByIndexDoesNotAllowInvalidOffsets()
|
||||
{
|
||||
$this->expectException(\OutOfBoundsException::class);
|
||||
$this->builder->replaceByIndex(6, 'new1');
|
||||
}
|
||||
|
||||
public function testReplaceByIndexDoesNotAllowNegativeOffsets()
|
||||
{
|
||||
$this->expectException(\OutOfBoundsException::class);
|
||||
$this->builder->replaceByIndex(-1, 'new1');
|
||||
}
|
||||
|
||||
public function testReplaceByProperty()
|
||||
{
|
||||
$this->builder->replaceByProperty(1, 'new1');
|
||||
|
||||
$path = new PropertyPath('old1.new1.old3[old4][old5].old6');
|
||||
|
||||
$this->assertEquals($path, $this->builder->getPropertyPath());
|
||||
}
|
||||
|
||||
public function testReplaceByPropertyWithoutName()
|
||||
{
|
||||
$this->builder->replaceByProperty(1);
|
||||
|
||||
$path = new PropertyPath('old1.old2.old3[old4][old5].old6');
|
||||
|
||||
$this->assertEquals($path, $this->builder->getPropertyPath());
|
||||
}
|
||||
|
||||
public function testReplaceByPropertyDoesNotAllowInvalidOffsets()
|
||||
{
|
||||
$this->expectException(\OutOfBoundsException::class);
|
||||
$this->builder->replaceByProperty(6, 'new1');
|
||||
}
|
||||
|
||||
public function testReplaceByPropertyDoesNotAllowNegativeOffsets()
|
||||
{
|
||||
$this->expectException(\OutOfBoundsException::class);
|
||||
$this->builder->replaceByProperty(-1, 'new1');
|
||||
}
|
||||
|
||||
public function testReplace()
|
||||
{
|
||||
$this->builder->replace(1, 1, new PropertyPath('new1[new2].new3'));
|
||||
|
||||
$path = new PropertyPath('old1.new1[new2].new3.old3[old4][old5].old6');
|
||||
|
||||
$this->assertEquals($path, $this->builder->getPropertyPath());
|
||||
}
|
||||
|
||||
public function testReplaceUsingString()
|
||||
{
|
||||
$this->builder->replace(1, 1, 'new1[new2].new3');
|
||||
|
||||
$path = new PropertyPath('old1.new1[new2].new3.old3[old4][old5].old6');
|
||||
|
||||
$this->assertEquals($path, $this->builder->getPropertyPath());
|
||||
}
|
||||
|
||||
public function testReplaceNegative()
|
||||
{
|
||||
$this->builder->replace(-1, 1, new PropertyPath('new1[new2].new3'));
|
||||
|
||||
$path = new PropertyPath('old1[old2].old3[old4][old5].new1[new2].new3');
|
||||
|
||||
$this->assertEquals($path, $this->builder->getPropertyPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideInvalidOffsets
|
||||
*/
|
||||
public function testReplaceDoesNotAllowInvalidOffsets($offset)
|
||||
{
|
||||
$this->expectException(\OutOfBoundsException::class);
|
||||
$this->builder->replace($offset, 1, new PropertyPath('new1[new2].new3'));
|
||||
}
|
||||
|
||||
public static function provideInvalidOffsets()
|
||||
{
|
||||
return [
|
||||
[6],
|
||||
[-7],
|
||||
];
|
||||
}
|
||||
|
||||
public function testReplaceWithLengthGreaterOne()
|
||||
{
|
||||
$this->builder->replace(0, 2, new PropertyPath('new1[new2].new3'));
|
||||
|
||||
$path = new PropertyPath('new1[new2].new3.old3[old4][old5].old6');
|
||||
|
||||
$this->assertEquals($path, $this->builder->getPropertyPath());
|
||||
}
|
||||
|
||||
public function testReplaceSubstring()
|
||||
{
|
||||
$this->builder->replace(1, 1, new PropertyPath('new1[new2].new3.new4[new5]'), 1, 3);
|
||||
|
||||
$path = new PropertyPath('old1[new2].new3.new4.old3[old4][old5].old6');
|
||||
|
||||
$this->assertEquals($path, $this->builder->getPropertyPath());
|
||||
}
|
||||
|
||||
public function testReplaceSubstringWithLengthGreaterOne()
|
||||
{
|
||||
$this->builder->replace(1, 2, new PropertyPath('new1[new2].new3.new4[new5]'), 1, 3);
|
||||
|
||||
$path = new PropertyPath('old1[new2].new3.new4[old4][old5].old6');
|
||||
|
||||
$this->assertEquals($path, $this->builder->getPropertyPath());
|
||||
}
|
||||
|
||||
// https://github.com/symfony/symfony/issues/5605
|
||||
public function testReplaceWithLongerPath()
|
||||
{
|
||||
// error occurs when path contains at least two more elements
|
||||
// than the builder
|
||||
$path = new PropertyPath('new1.new2.new3');
|
||||
|
||||
$builder = new PropertyPathBuilder(new PropertyPath('old1'));
|
||||
$builder->replace(0, 1, $path);
|
||||
|
||||
$this->assertEquals($path, $builder->getPropertyPath());
|
||||
}
|
||||
|
||||
public function testReplaceWithLongerPathKeepsOrder()
|
||||
{
|
||||
$path = new PropertyPath('new1.new2.new3');
|
||||
$expected = new PropertyPath('new1.new2.new3.old2');
|
||||
|
||||
$builder = new PropertyPathBuilder(new PropertyPath('old1.old2'));
|
||||
$builder->replace(0, 1, $path);
|
||||
|
||||
$this->assertEquals($expected, $builder->getPropertyPath());
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$this->builder->remove(3);
|
||||
|
||||
$path = new PropertyPath('old1[old2].old3[old5].old6');
|
||||
|
||||
$this->assertEquals($path, $this->builder->getPropertyPath());
|
||||
}
|
||||
|
||||
public function testRemoveDoesNotAllowInvalidOffsets()
|
||||
{
|
||||
$this->expectException(\OutOfBoundsException::class);
|
||||
$this->builder->remove(6);
|
||||
}
|
||||
|
||||
public function testRemoveDoesNotAllowNegativeOffsets()
|
||||
{
|
||||
$this->expectException(\OutOfBoundsException::class);
|
||||
$this->builder->remove(-1);
|
||||
}
|
||||
|
||||
public function testRemoveAndAppendAtTheEnd()
|
||||
{
|
||||
$this->builder->remove($this->builder->getLength() - 1);
|
||||
|
||||
$path = new PropertyPath('old1[old2].old3[old4][old5]');
|
||||
|
||||
$this->assertEquals($path, $this->builder->getPropertyPath());
|
||||
|
||||
$this->builder->appendProperty('old7');
|
||||
|
||||
$path = new PropertyPath('old1[old2].old3[old4][old5].old7');
|
||||
|
||||
$this->assertEquals($path, $this->builder->getPropertyPath());
|
||||
|
||||
$this->builder->remove($this->builder->getLength() - 1);
|
||||
|
||||
$path = new PropertyPath('old1[old2].old3[old4][old5]');
|
||||
|
||||
$this->assertEquals($path, $this->builder->getPropertyPath());
|
||||
}
|
||||
}
|
||||
186
vendor/symfony/property-access/Tests/PropertyPathTest.php
vendored
Normal file
186
vendor/symfony/property-access/Tests/PropertyPathTest.php
vendored
Normal file
@@ -0,0 +1,186 @@
|
||||
<?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\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\PropertyAccess\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\PropertyAccess\Exception\InvalidPropertyPathException;
|
||||
use Symfony\Component\PropertyAccess\PropertyPath;
|
||||
|
||||
class PropertyPathTest extends TestCase
|
||||
{
|
||||
public function testToString()
|
||||
{
|
||||
$path = new PropertyPath('reference.traversable[index].property');
|
||||
|
||||
$this->assertEquals('reference.traversable[index].property', $path->__toString());
|
||||
}
|
||||
|
||||
public function testDotIsRequiredBeforeProperty()
|
||||
{
|
||||
$this->expectException(InvalidPropertyPathException::class);
|
||||
new PropertyPath('[index]property');
|
||||
}
|
||||
|
||||
public function testDotCannotBePresentAtTheBeginning()
|
||||
{
|
||||
$this->expectException(InvalidPropertyPathException::class);
|
||||
new PropertyPath('.property');
|
||||
}
|
||||
|
||||
public static function providePathsContainingUnexpectedCharacters()
|
||||
{
|
||||
return [
|
||||
['property.'],
|
||||
['property.['],
|
||||
['property..'],
|
||||
['property['],
|
||||
['property[['],
|
||||
['property[.'],
|
||||
['property[]'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providePathsContainingUnexpectedCharacters
|
||||
*/
|
||||
public function testUnexpectedCharacters($path)
|
||||
{
|
||||
$this->expectException(InvalidPropertyPathException::class);
|
||||
new PropertyPath($path);
|
||||
}
|
||||
|
||||
public function testPathCannotBeEmpty()
|
||||
{
|
||||
$this->expectException(InvalidPropertyPathException::class);
|
||||
new PropertyPath('');
|
||||
}
|
||||
|
||||
public function testPathCannotBeNull()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
new PropertyPath(null);
|
||||
}
|
||||
|
||||
public function testPathCannotBeFalse()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
new PropertyPath(false);
|
||||
}
|
||||
|
||||
public function testZeroIsValidPropertyPath()
|
||||
{
|
||||
$propertyPath = new PropertyPath('0');
|
||||
|
||||
$this->assertSame('0', (string) $propertyPath);
|
||||
}
|
||||
|
||||
public function testGetParentWithDot()
|
||||
{
|
||||
$propertyPath = new PropertyPath('grandpa.parent.child');
|
||||
|
||||
$this->assertEquals(new PropertyPath('grandpa.parent'), $propertyPath->getParent());
|
||||
}
|
||||
|
||||
public function testGetParentWithIndex()
|
||||
{
|
||||
$propertyPath = new PropertyPath('grandpa.parent[child]');
|
||||
|
||||
$this->assertEquals(new PropertyPath('grandpa.parent'), $propertyPath->getParent());
|
||||
}
|
||||
|
||||
public function testGetParentWhenThereIsNoParent()
|
||||
{
|
||||
$propertyPath = new PropertyPath('path');
|
||||
|
||||
$this->assertNull($propertyPath->getParent());
|
||||
}
|
||||
|
||||
public function testCopyConstructor()
|
||||
{
|
||||
$propertyPath = new PropertyPath('grandpa.parent[child]');
|
||||
$copy = new PropertyPath($propertyPath);
|
||||
|
||||
$this->assertEquals($propertyPath, $copy);
|
||||
}
|
||||
|
||||
public function testGetElement()
|
||||
{
|
||||
$propertyPath = new PropertyPath('grandpa.parent[child]');
|
||||
|
||||
$this->assertEquals('child', $propertyPath->getElement(2));
|
||||
}
|
||||
|
||||
public function testGetElementDoesNotAcceptInvalidIndices()
|
||||
{
|
||||
$this->expectException(\OutOfBoundsException::class);
|
||||
$propertyPath = new PropertyPath('grandpa.parent[child]');
|
||||
|
||||
$propertyPath->getElement(3);
|
||||
}
|
||||
|
||||
public function testGetElementDoesNotAcceptNegativeIndices()
|
||||
{
|
||||
$this->expectException(\OutOfBoundsException::class);
|
||||
$propertyPath = new PropertyPath('grandpa.parent[child]');
|
||||
|
||||
$propertyPath->getElement(-1);
|
||||
}
|
||||
|
||||
public function testIsProperty()
|
||||
{
|
||||
$propertyPath = new PropertyPath('grandpa.parent[child]');
|
||||
|
||||
$this->assertTrue($propertyPath->isProperty(1));
|
||||
$this->assertFalse($propertyPath->isProperty(2));
|
||||
}
|
||||
|
||||
public function testIsPropertyDoesNotAcceptInvalidIndices()
|
||||
{
|
||||
$this->expectException(\OutOfBoundsException::class);
|
||||
$propertyPath = new PropertyPath('grandpa.parent[child]');
|
||||
|
||||
$propertyPath->isProperty(3);
|
||||
}
|
||||
|
||||
public function testIsPropertyDoesNotAcceptNegativeIndices()
|
||||
{
|
||||
$this->expectException(\OutOfBoundsException::class);
|
||||
$propertyPath = new PropertyPath('grandpa.parent[child]');
|
||||
|
||||
$propertyPath->isProperty(-1);
|
||||
}
|
||||
|
||||
public function testIsIndex()
|
||||
{
|
||||
$propertyPath = new PropertyPath('grandpa.parent[child]');
|
||||
|
||||
$this->assertFalse($propertyPath->isIndex(1));
|
||||
$this->assertTrue($propertyPath->isIndex(2));
|
||||
}
|
||||
|
||||
public function testIsIndexDoesNotAcceptInvalidIndices()
|
||||
{
|
||||
$this->expectException(\OutOfBoundsException::class);
|
||||
$propertyPath = new PropertyPath('grandpa.parent[child]');
|
||||
|
||||
$propertyPath->isIndex(3);
|
||||
}
|
||||
|
||||
public function testIsIndexDoesNotAcceptNegativeIndices()
|
||||
{
|
||||
$this->expectException(\OutOfBoundsException::class);
|
||||
$propertyPath = new PropertyPath('grandpa.parent[child]');
|
||||
|
||||
$propertyPath->isIndex(-1);
|
||||
}
|
||||
}
|
||||
37
vendor/symfony/property-access/Tests/TestPluralAdderRemoverAndSetter.php
vendored
Normal file
37
vendor/symfony/property-access/Tests/TestPluralAdderRemoverAndSetter.php
vendored
Normal file
@@ -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 Symfony\Component\PropertyAccess\Tests;
|
||||
|
||||
class TestPluralAdderRemoverAndSetter
|
||||
{
|
||||
private $emails = [];
|
||||
|
||||
public function getEmails()
|
||||
{
|
||||
return $this->emails;
|
||||
}
|
||||
|
||||
public function setEmails(array $emails)
|
||||
{
|
||||
$this->emails = ['foo@email.com'];
|
||||
}
|
||||
|
||||
public function addEmail($email)
|
||||
{
|
||||
$this->emails[] = $email;
|
||||
}
|
||||
|
||||
public function removeEmail($email)
|
||||
{
|
||||
$this->emails = array_diff($this->emails, [$email]);
|
||||
}
|
||||
}
|
||||
37
vendor/symfony/property-access/Tests/TestPluralAdderRemoverAndSetterSameSingularAndPlural.php
vendored
Normal file
37
vendor/symfony/property-access/Tests/TestPluralAdderRemoverAndSetterSameSingularAndPlural.php
vendored
Normal file
@@ -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 Symfony\Component\PropertyAccess\Tests;
|
||||
|
||||
class TestPluralAdderRemoverAndSetterSameSingularAndPlural
|
||||
{
|
||||
private $aircraft = [];
|
||||
|
||||
public function getAircraft()
|
||||
{
|
||||
return $this->aircraft;
|
||||
}
|
||||
|
||||
public function setAircraft(array $aircraft)
|
||||
{
|
||||
$this->aircraft = ['plane'];
|
||||
}
|
||||
|
||||
public function addAircraft($aircraft)
|
||||
{
|
||||
$this->aircraft[] = $aircraft;
|
||||
}
|
||||
|
||||
public function removeAircraft($aircraft)
|
||||
{
|
||||
$this->aircraft = array_diff($this->aircraft, [$aircraft]);
|
||||
}
|
||||
}
|
||||
31
vendor/symfony/property-access/phpunit.xml.dist
vendored
Normal file
31
vendor/symfony/property-access/phpunit.xml.dist
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd"
|
||||
backupGlobals="false"
|
||||
colors="true"
|
||||
bootstrap="vendor/autoload.php"
|
||||
failOnRisky="true"
|
||||
failOnWarning="true"
|
||||
>
|
||||
<php>
|
||||
<ini name="error_reporting" value="-1" />
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Symfony PropertyAccess Component Test Suite">
|
||||
<directory>./Tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>./</directory>
|
||||
<exclude>
|
||||
<directory>./Resources</directory>
|
||||
<directory>./Tests</directory>
|
||||
<directory>./vendor</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
Reference in New Issue
Block a user