pax_global_header00006660000000000000000000000064131406142160014510gustar00rootroot0000000000000052 comment=7cfd9e65d11ffb5af41198476395774d4c8a84c5 object-enumerator-3.0.3/000077500000000000000000000000001314061421600151405ustar00rootroot00000000000000object-enumerator-3.0.3/.gitignore000066400000000000000000000001451314061421600171300ustar00rootroot00000000000000.idea composer.lock composer.phar vendor/ cache.properties build/LICENSE build/README.md build/*.tgz object-enumerator-3.0.3/.php_cs000066400000000000000000000036211314061421600164170ustar00rootroot00000000000000files() ->in('src') ->in('tests') ->name('*.php'); return Symfony\CS\Config\Config::create() ->level(\Symfony\CS\FixerInterface::NONE_LEVEL) ->fixers( array( 'align_double_arrow', 'align_equals', 'braces', 'concat_with_spaces', 'duplicate_semicolon', 'elseif', 'empty_return', 'encoding', 'eof_ending', 'extra_empty_lines', 'function_call_space', 'function_declaration', 'indentation', 'join_function', 'line_after_namespace', 'linefeed', 'list_commas', 'lowercase_constants', 'lowercase_keywords', 'method_argument_space', 'multiple_use', 'namespace_no_leading_whitespace', 'no_blank_lines_after_class_opening', 'no_empty_lines_after_phpdocs', 'parenthesis', 'php_closing_tag', 'phpdoc_indent', 'phpdoc_no_access', 'phpdoc_no_empty_return', 'phpdoc_no_package', 'phpdoc_params', 'phpdoc_scalar', 'phpdoc_separation', 'phpdoc_to_comment', 'phpdoc_trim', 'phpdoc_types', 'phpdoc_var_without_name', 'remove_lines_between_uses', 'return', 'self_accessor', 'short_array_syntax', 'short_tag', 'single_line_after_imports', 'single_quote', 'spaces_before_semicolon', 'spaces_cast', 'ternary_spaces', 'trailing_spaces', 'trim_array_spaces', 'unused_use', 'visibility', 'whitespacy_lines' ) ) ->finder($finder); object-enumerator-3.0.3/.travis.yml000066400000000000000000000007021314061421600172500ustar00rootroot00000000000000language: php php: - 7.0 - 7.0snapshot - 7.1 - 7.1snapshot - master sudo: false before_install: - composer self-update - composer clear-cache install: - travis_retry composer update --no-interaction --no-ansi --no-progress --no-suggest --optimize-autoloader --prefer-stable script: - ./vendor/bin/phpunit --coverage-clover=coverage.xml after_success: - bash <(curl -s https://codecov.io/bash) notifications: email: false object-enumerator-3.0.3/ChangeLog.md000066400000000000000000000025711314061421600173160ustar00rootroot00000000000000# Change Log All notable changes to `sebastianbergmann/object-enumerator` are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. ## [3.0.3] - 2017-08-03 ### Changed * Bumped required version of `sebastian/object-reflector` ## [3.0.2] - 2017-03-12 ### Changed * `sebastian/object-reflector` is now a dependency ## [3.0.1] - 2017-03-12 ### Fixed * Objects aggregated in inherited attributes are not enumerated ## [3.0.0] - 2017-03-03 ### Removed * This component is no longer supported on PHP 5.6 ## [2.0.1] - 2017-02-18 ### Fixed * Fixed [#2](https://github.com/sebastianbergmann/phpunit/pull/2): Exceptions in `ReflectionProperty::getValue()` are not handled ## [2.0.0] - 2016-11-19 ### Changed * This component is now compatible with `sebastian/recursion-context: ~1.0.4` ## 1.0.0 - 2016-02-04 ### Added * Initial release [3.0.3]: https://github.com/sebastianbergmann/object-enumerator/compare/3.0.2...3.0.3 [3.0.2]: https://github.com/sebastianbergmann/object-enumerator/compare/3.0.1...3.0.2 [3.0.1]: https://github.com/sebastianbergmann/object-enumerator/compare/3.0.0...3.0.1 [3.0.0]: https://github.com/sebastianbergmann/object-enumerator/compare/2.0...3.0.0 [2.0.1]: https://github.com/sebastianbergmann/object-enumerator/compare/2.0.0...2.0.1 [2.0.0]: https://github.com/sebastianbergmann/object-enumerator/compare/1.0...2.0.0 object-enumerator-3.0.3/LICENSE000066400000000000000000000030201314061421600161400ustar00rootroot00000000000000Object Enumerator Copyright (c) 2016-2017, Sebastian Bergmann . All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Sebastian Bergmann nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. object-enumerator-3.0.3/README.md000066400000000000000000000007671314061421600164310ustar00rootroot00000000000000# Object Enumerator Traverses array structures and object graphs to enumerate all referenced objects. ## Installation You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/): composer require sebastian/object-enumerator If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency: composer require --dev sebastian/object-enumerator object-enumerator-3.0.3/build.xml000066400000000000000000000014331314061421600167620ustar00rootroot00000000000000 object-enumerator-3.0.3/composer.json000066400000000000000000000015231314061421600176630ustar00rootroot00000000000000{ "name": "sebastian/object-enumerator", "description": "Traverses array structures and object graphs to enumerate all referenced objects", "homepage": "https://github.com/sebastianbergmann/object-enumerator/", "license": "BSD-3-Clause", "authors": [ { "name": "Sebastian Bergmann", "email": "sebastian@phpunit.de" } ], "require": { "php": "^7.0", "sebastian/object-reflector": "^1.1.1", "sebastian/recursion-context": "^3.0" }, "require-dev": { "phpunit/phpunit": "^6.0" }, "autoload": { "classmap": [ "src/" ] }, "autoload-dev": { "classmap": [ "tests/_fixture/" ] }, "extra": { "branch-alias": { "dev-master": "3.0.x-dev" } } } object-enumerator-3.0.3/phpunit.xml000066400000000000000000000013461314061421600173550ustar00rootroot00000000000000 tests src object-enumerator-3.0.3/src/000077500000000000000000000000001314061421600157275ustar00rootroot00000000000000object-enumerator-3.0.3/src/Enumerator.php000066400000000000000000000041621314061421600205640ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\ObjectEnumerator; 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; } } object-enumerator-3.0.3/src/Exception.php000066400000000000000000000004661314061421600204040ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\ObjectEnumerator; interface Exception { } object-enumerator-3.0.3/src/InvalidArgumentException.php000066400000000000000000000005701314061421600234120ustar00rootroot00000000000000 * * 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 { } object-enumerator-3.0.3/tests/000077500000000000000000000000001314061421600163025ustar00rootroot00000000000000object-enumerator-3.0.3/tests/EnumeratorTest.php000066400000000000000000000064431314061421600220030ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\ObjectEnumerator; use SebastianBergmann\ObjectEnumerator\Fixtures\ExceptionThrower; use PHPUnit\Framework\TestCase; /** * @covers SebastianBergmann\ObjectEnumerator\Enumerator */ class EnumeratorTest extends TestCase { /** * @var Enumerator */ private $enumerator; protected function setUp() { $this->enumerator = new Enumerator; } public function testEnumeratesSingleObject() { $a = new \stdClass; $objects = $this->enumerator->enumerate($a); $this->assertCount(1, $objects); $this->assertSame($a, $objects[0]); } public function testEnumeratesArrayWithSingleObject() { $a = new \stdClass; $objects = $this->enumerator->enumerate([$a]); $this->assertCount(1, $objects); $this->assertSame($a, $objects[0]); } public function testEnumeratesArrayWithTwoReferencesToTheSameObject() { $a = new \stdClass; $objects = $this->enumerator->enumerate([$a, $a]); $this->assertCount(1, $objects); $this->assertSame($a, $objects[0]); } public function testEnumeratesArrayOfObjects() { $a = new \stdClass; $b = new \stdClass; $objects = $this->enumerator->enumerate([$a, $b, null]); $this->assertCount(2, $objects); $this->assertSame($a, $objects[0]); $this->assertSame($b, $objects[1]); } public function testEnumeratesObjectWithAggregatedObject() { $a = new \stdClass; $b = new \stdClass; $a->b = $b; $a->c = null; $objects = $this->enumerator->enumerate($a); $this->assertCount(2, $objects); $this->assertSame($a, $objects[0]); $this->assertSame($b, $objects[1]); } public function testEnumeratesObjectWithAggregatedObjectsInArray() { $a = new \stdClass; $b = new \stdClass; $a->b = [$b]; $objects = $this->enumerator->enumerate($a); $this->assertCount(2, $objects); $this->assertSame($a, $objects[0]); $this->assertSame($b, $objects[1]); } public function testEnumeratesObjectsWithCyclicReferences() { $a = new \stdClass; $b = new \stdClass; $a->b = $b; $b->a = $a; $objects = $this->enumerator->enumerate([$a, $b]); $this->assertCount(2, $objects); $this->assertSame($a, $objects[0]); $this->assertSame($b, $objects[1]); } public function testEnumeratesClassThatThrowsException() { $thrower = new ExceptionThrower(); $objects = $this->enumerator->enumerate($thrower); $this->assertSame($thrower, $objects[0]); } public function testExceptionIsRaisedForInvalidArgument() { $this->expectException(InvalidArgumentException::class); $this->enumerator->enumerate(null); } public function testExceptionIsRaisedForInvalidArgument2() { $this->expectException(InvalidArgumentException::class); $this->enumerator->enumerate([], ''); } } object-enumerator-3.0.3/tests/_fixture/000077500000000000000000000000001314061421600201275ustar00rootroot00000000000000object-enumerator-3.0.3/tests/_fixture/ExceptionThrower.php000066400000000000000000000010251314061421600241470ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\ObjectEnumerator\Fixtures; use RuntimeException; class ExceptionThrower { private $property; public function __construct() { unset($this->property); } public function __get($property) { throw new RuntimeException; } }