From 1c4f7ab3b838b23afb2ee4dab14acbf75956e952 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 22 Mar 2022 12:24:31 +0300 Subject: * add phpunit as a dev dependency * add some basic tests for UrlHelper::rewrite_relative() * fix UrlHelper::rewrite_relative() to work better on non-absolute relative URL paths --- .../sebastian/object-enumerator/src/Enumerator.php | 88 ++++++++++++++++++++++ .../sebastian/object-enumerator/src/Exception.php | 16 ++++ .../src/InvalidArgumentException.php | 14 ++++ 3 files changed, 118 insertions(+) create mode 100644 vendor/sebastian/object-enumerator/src/Enumerator.php create mode 100644 vendor/sebastian/object-enumerator/src/Exception.php create mode 100644 vendor/sebastian/object-enumerator/src/InvalidArgumentException.php (limited to 'vendor/sebastian/object-enumerator/src') diff --git a/vendor/sebastian/object-enumerator/src/Enumerator.php b/vendor/sebastian/object-enumerator/src/Enumerator.php new file mode 100644 index 000000000..de75d17c5 --- /dev/null +++ b/vendor/sebastian/object-enumerator/src/Enumerator.php @@ -0,0 +1,88 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace SebastianBergmann\ObjectEnumerator; + +use function array_merge; +use function func_get_args; +use function is_array; +use function is_object; +use SebastianBergmann\ObjectReflector\ObjectReflector; +use SebastianBergmann\RecursionContext\Context; + +/** + * Traverses array structures and object graphs + * to enumerate all referenced objects. + */ +class Enumerator +{ + /** + * Returns an array of all objects referenced either + * directly or indirectly by a variable. + * + * @param array|object $variable + * + * @return object[] + */ + public function enumerate($variable) + { + if (!is_array($variable) && !is_object($variable)) { + throw new InvalidArgumentException; + } + + if (isset(func_get_args()[1])) { + if (!func_get_args()[1] instanceof Context) { + throw new InvalidArgumentException; + } + + $processed = func_get_args()[1]; + } else { + $processed = new Context; + } + + $objects = []; + + if ($processed->contains($variable)) { + return $objects; + } + + $array = $variable; + $processed->add($variable); + + if (is_array($variable)) { + foreach ($array as $element) { + if (!is_array($element) && !is_object($element)) { + continue; + } + + $objects = array_merge( + $objects, + $this->enumerate($element, $processed) + ); + } + } else { + $objects[] = $variable; + + $reflector = new ObjectReflector; + + foreach ($reflector->getAttributes($variable) as $value) { + if (!is_array($value) && !is_object($value)) { + continue; + } + + $objects = array_merge( + $objects, + $this->enumerate($value, $processed) + ); + } + } + + return $objects; + } +} diff --git a/vendor/sebastian/object-enumerator/src/Exception.php b/vendor/sebastian/object-enumerator/src/Exception.php new file mode 100644 index 000000000..2f09d70aa --- /dev/null +++ b/vendor/sebastian/object-enumerator/src/Exception.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace SebastianBergmann\ObjectEnumerator; + +use Throwable; + +interface Exception extends Throwable +{ +} diff --git a/vendor/sebastian/object-enumerator/src/InvalidArgumentException.php b/vendor/sebastian/object-enumerator/src/InvalidArgumentException.php new file mode 100644 index 000000000..ce2037cdb --- /dev/null +++ b/vendor/sebastian/object-enumerator/src/InvalidArgumentException.php @@ -0,0 +1,14 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace SebastianBergmann\ObjectEnumerator; + +class InvalidArgumentException extends \InvalidArgumentException implements Exception +{ +} -- cgit v1.2.3