pax_global_header00006660000000000000000000000064126524132660014521gustar00rootroot0000000000000052 comment=d4ca2fb70344987502567bc50081c03e6192fb26 object-enumerator-1.0.0/000077500000000000000000000000001265241326600151445ustar00rootroot00000000000000object-enumerator-1.0.0/.gitignore000066400000000000000000000001451265241326600171340ustar00rootroot00000000000000.idea composer.lock composer.phar vendor/ cache.properties build/LICENSE build/README.md build/*.tgz object-enumerator-1.0.0/.php_cs000066400000000000000000000036211265241326600164230ustar00rootroot00000000000000files() ->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-1.0.0/.travis.yml000066400000000000000000000003231265241326600172530ustar00rootroot00000000000000language: php php: - 5.6 - 7.0 sudo: false before_script: - composer self-update - composer install --no-interaction --prefer-source --dev script: ./vendor/bin/phpunit notifications: email: false object-enumerator-1.0.0/ChangeLog.md000066400000000000000000000003411265241326600173130ustar00rootroot00000000000000# Change Log All notable changes to `sebastianbergmann/object-enumerator` are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. ## 1.0.0 - 2016-MM-DD ### Added * Initial release object-enumerator-1.0.0/LICENSE000066400000000000000000000030131265241326600161460ustar00rootroot00000000000000Object Enumerator Copyright (c) 2016, 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-1.0.0/README.md000066400000000000000000000007621265241326600164300ustar00rootroot00000000000000# Object Enumerator Traverses array structures and object graphs to enumerate all referenced objects. ## Installation To add Object Enumerator as a local, per-project dependency to your project, simply add a dependency on `sebastian/object-enumerator` to your project's `composer.json` file. Here is a minimal example of a `composer.json` file that just defines a dependency on Object Enumerator 1.0: { "require": { "sebastian/object-enumerator": "~1.0" } } object-enumerator-1.0.0/build.xml000066400000000000000000000016711265241326600167720ustar00rootroot00000000000000 object-enumerator-1.0.0/composer.json000066400000000000000000000013071265241326600176670ustar00rootroot00000000000000{ "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": ">=5.6", "sebastian/recursion-context": "~1.0" }, "require-dev": { "phpunit/phpunit": "~5" }, "autoload": { "classmap": [ "src/" ] }, "extra": { "branch-alias": { "dev-master": "1.0.x-dev" } } } object-enumerator-1.0.0/phpunit.xml000066400000000000000000000014231265241326600173550ustar00rootroot00000000000000 tests src object-enumerator-1.0.0/src/000077500000000000000000000000001265241326600157335ustar00rootroot00000000000000object-enumerator-1.0.0/src/Enumerator.php000066400000000000000000000042261265241326600205710ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\ObjectEnumerator; 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; } $processed->add($variable); if (is_array($variable)) { foreach ($variable as $element) { if (!is_array($element) && !is_object($element)) { continue; } $objects = array_merge( $objects, $this->enumerate($element, $processed) ); } } else { $objects[] = $variable; $reflector = new \ReflectionObject($variable); foreach ($reflector->getProperties() as $attribute) { $attribute->setAccessible(true); $value = $attribute->getValue($variable); if (!is_array($value) && !is_object($value)) { continue; } $objects = array_merge( $objects, $this->enumerate($value, $processed) ); } } return $objects; } } object-enumerator-1.0.0/src/Exception.php000066400000000000000000000004661265241326600204100ustar00rootroot00000000000000 * * 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-1.0.0/src/InvalidArgumentException.php000066400000000000000000000005701265241326600234160ustar00rootroot00000000000000 * * 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-1.0.0/tests/000077500000000000000000000000001265241326600163065ustar00rootroot00000000000000object-enumerator-1.0.0/tests/EnumeratorTest.php000066400000000000000000000057711265241326600220120ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\ObjectEnumerator; /** * @covers SebastianBergmann\ObjectEnumerator\Enumerator */ class EnumeratorTest extends \PHPUnit_Framework_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 testExceptionIsRaisedForInvalidArgument() { $this->setExpectedException(InvalidArgumentException::class); $this->enumerator->enumerate(null); } public function testExceptionIsRaisedForInvalidArgument2() { $this->setExpectedException(InvalidArgumentException::class); $this->enumerator->enumerate([], ''); } }