From 705a25fbbfee688353351f0bc13f34d61f9f668a Mon Sep 17 00:00:00 2001 From: Benson Lee Date: Tue, 24 Jan 2017 08:58:09 -0800 Subject: [PATCH] Laravel 5.4 changes (#32) --- composer.json | 4 +- composer.lock | 478 +++++++++++------- src/Illuminate/Support/Collection.php | 139 ++++- .../Support/HigherOrderCollectionProxy.php | 60 +++ src/Illuminate/Support/helpers.php | 13 + tests/Support/SupportCollectionTest.php | 216 +++++++- 6 files changed, 686 insertions(+), 224 deletions(-) create mode 100644 src/Illuminate/Support/HigherOrderCollectionProxy.php diff --git a/composer.json b/composer.json index d6b7043..8ea440b 100644 --- a/composer.json +++ b/composer.json @@ -13,8 +13,8 @@ "php": ">=5.6.4" }, "require-dev": { - "mockery/mockery": "~0.9.4", - "phpunit/phpunit": "~4.1" + "mockery/mockery": "^0.9.7", + "phpunit/phpunit": "^5.7" }, "autoload": { "files": [ diff --git a/composer.lock b/composer.lock index 2ce5a02..ebbe0dc 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "5de455b29bebe43c932773f5f13fb54b", - "content-hash": "3a8c06cb4be3971698b10905a8a52024", + "hash": "c9b25e4485c2d0f57b934728f95000ec", + "content-hash": "02ddcc63b880313d80c438fcae4371eb", "packages": [], "packages-dev": [ { @@ -62,54 +62,6 @@ ], "time": "2015-06-14 21:17:01" }, - { - "name": "fzaninotto/faker", - "version": "v1.6.0", - "source": { - "type": "git", - "url": "https://github.com/fzaninotto/Faker.git", - "reference": "44f9a286a04b80c76a4e5fb7aad8bb539b920123" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/44f9a286a04b80c76a4e5fb7aad8bb539b920123", - "reference": "44f9a286a04b80c76a4e5fb7aad8bb539b920123", - "shasum": "" - }, - "require": { - "php": "^5.3.3|^7.0" - }, - "require-dev": { - "ext-intl": "*", - "phpunit/phpunit": "~4.0", - "squizlabs/php_codesniffer": "~1.5" - }, - "type": "library", - "extra": { - "branch-alias": [] - }, - "autoload": { - "psr-4": { - "Faker\\": "src/Faker/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "François Zaninotto" - } - ], - "description": "Faker is a PHP library that generates fake data for you.", - "keywords": [ - "data", - "faker", - "fixtures" - ], - "time": "2016-04-29 12:21:54" - }, { "name": "hamcrest/hamcrest-php", "version": "v1.2.2", @@ -157,16 +109,16 @@ }, { "name": "mockery/mockery", - "version": "0.9.4", + "version": "0.9.7", "source": { "type": "git", "url": "https://github.com/padraic/mockery.git", - "reference": "70bba85e4aabc9449626651f48b9018ede04f86b" + "reference": "4de7969f4664da3cef1ccd83866c9f59378c3371" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/padraic/mockery/zipball/70bba85e4aabc9449626651f48b9018ede04f86b", - "reference": "70bba85e4aabc9449626651f48b9018ede04f86b", + "url": "https://api.github.com/repos/padraic/mockery/zipball/4de7969f4664da3cef1ccd83866c9f59378c3371", + "reference": "4de7969f4664da3cef1ccd83866c9f59378c3371", "shasum": "" }, "require": { @@ -218,20 +170,20 @@ "test double", "testing" ], - "time": "2015-04-02 19:54:00" + "time": "2016-12-19 14:50:55" }, { "name": "myclabs/deep-copy", - "version": "1.5.1", + "version": "1.5.5", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "a8773992b362b58498eed24bf85005f363c34771" + "reference": "399c1f9781e222f6eb6cc238796f5200d1b7f108" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/a8773992b362b58498eed24bf85005f363c34771", - "reference": "a8773992b362b58498eed24bf85005f363c34771", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/399c1f9781e222f6eb6cc238796f5200d1b7f108", + "reference": "399c1f9781e222f6eb6cc238796f5200d1b7f108", "shasum": "" }, "require": { @@ -260,41 +212,138 @@ "object", "object graph" ], - "time": "2015-11-20 12:04:31" + "time": "2016-10-31 17:19:45" + }, + { + "name": "phpdocumentor/reflection-common", + "version": "1.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2015-12-27 11:43:31" }, { "name": "phpdocumentor/reflection-docblock", - "version": "2.0.4", + "version": "3.1.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8" + "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8", - "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/8331b5efe816ae05461b7ca1e721c01b46bafb3e", + "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=5.5", + "phpdocumentor/reflection-common": "^1.0@dev", + "phpdocumentor/type-resolver": "^0.2.0", + "webmozart/assert": "^1.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^4.4" }, - "suggest": { - "dflydev/markdown": "~1.0", - "erusev/parsedown": "~1.0" + "type": "library", + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "time": "2016-09-30 07:12:33" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "0.2.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb", + "reference": "e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb", + "shasum": "" + }, + "require": { + "php": ">=5.5", + "phpdocumentor/reflection-common": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^5.2||^4.8.24" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "1.0.x-dev" } }, "autoload": { - "psr-0": { - "phpDocumentor": [ + "psr-4": { + "phpDocumentor\\Reflection\\": [ "src/" ] } @@ -306,39 +355,40 @@ "authors": [ { "name": "Mike van Riel", - "email": "mike.vanriel@naenius.com" + "email": "me@mikevanriel.com" } ], - "time": "2015-02-03 12:10:50" + "time": "2016-11-25 06:54:22" }, { "name": "phpspec/prophecy", - "version": "v1.6.0", + "version": "v1.6.2", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "3c91bdf81797d725b14cb62906f9a4ce44235972" + "reference": "6c52c2722f8460122f96f86346600e1077ce22cb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/3c91bdf81797d725b14cb62906f9a4ce44235972", - "reference": "3c91bdf81797d725b14cb62906f9a4ce44235972", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/6c52c2722f8460122f96f86346600e1077ce22cb", + "reference": "6c52c2722f8460122f96f86346600e1077ce22cb", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", "php": "^5.3|^7.0", - "phpdocumentor/reflection-docblock": "~2.0", - "sebastian/comparator": "~1.1", - "sebastian/recursion-context": "~1.0" + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2", + "sebastian/comparator": "^1.1", + "sebastian/recursion-context": "^1.0|^2.0" }, "require-dev": { - "phpspec/phpspec": "~2.0" + "phpspec/phpspec": "^2.0", + "phpunit/phpunit": "^4.8 || ^5.6.5" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.5.x-dev" + "dev-master": "1.6.x-dev" } }, "autoload": { @@ -371,20 +421,20 @@ "spy", "stub" ], - "time": "2016-02-15 07:46:21" + "time": "2016-11-21 14:58:47" }, { "name": "phpunit/php-code-coverage", - "version": "3.3.1", + "version": "4.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "2431befdd451fac43fbcde94d1a92fb3b8b68f86" + "reference": "c19cfc7cbb0e9338d8c469c7eedecc2a428b0971" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2431befdd451fac43fbcde94d1a92fb3b8b68f86", - "reference": "2431befdd451fac43fbcde94d1a92fb3b8b68f86", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/c19cfc7cbb0e9338d8c469c7eedecc2a428b0971", + "reference": "c19cfc7cbb0e9338d8c469c7eedecc2a428b0971", "shasum": "" }, "require": { @@ -393,12 +443,12 @@ "phpunit/php-text-template": "~1.2", "phpunit/php-token-stream": "^1.4.2", "sebastian/code-unit-reverse-lookup": "~1.0", - "sebastian/environment": "^1.3.2", + "sebastian/environment": "^1.3.2 || ^2.0", "sebastian/version": "~1.0|~2.0" }, "require-dev": { "ext-xdebug": ">=2.1.4", - "phpunit/phpunit": "~5" + "phpunit/phpunit": "^5.4" }, "suggest": { "ext-dom": "*", @@ -408,7 +458,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.3.x-dev" + "dev-master": "4.0.x-dev" } }, "autoload": { @@ -434,20 +484,20 @@ "testing", "xunit" ], - "time": "2016-04-08 08:14:53" + "time": "2017-01-20 15:06:43" }, { "name": "phpunit/php-file-iterator", - "version": "1.4.1", + "version": "1.4.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0" + "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6150bf2c35d3fc379e50c7602b75caceaa39dbf0", - "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5", "shasum": "" }, "require": { @@ -481,7 +531,7 @@ "filesystem", "iterator" ], - "time": "2015-06-21 13:08:43" + "time": "2016-10-03 07:40:28" }, { "name": "phpunit/php-text-template", @@ -526,21 +576,24 @@ }, { "name": "phpunit/php-timer", - "version": "1.0.7", + "version": "1.0.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b" + "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3e82f4e9fc92665fafd9157568e4dcb01d014e5b", - "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/38e9124049cf1a164f1e4537caf19c99bf1eb260", + "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260", "shasum": "" }, "require": { "php": ">=5.3.3" }, + "require-dev": { + "phpunit/phpunit": "~4|~5" + }, "type": "library", "autoload": { "classmap": [ @@ -563,20 +616,20 @@ "keywords": [ "timer" ], - "time": "2015-06-21 08:01:12" + "time": "2016-05-12 18:03:57" }, { "name": "phpunit/php-token-stream", - "version": "1.4.8", + "version": "1.4.9", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da" + "reference": "3b402f65a4cc90abf6e1104e388b896ce209631b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da", - "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3b402f65a4cc90abf6e1104e388b896ce209631b", + "reference": "3b402f65a4cc90abf6e1104e388b896ce209631b", "shasum": "" }, "require": { @@ -612,47 +665,54 @@ "keywords": [ "tokenizer" ], - "time": "2015-09-15 10:49:45" + "time": "2016-11-15 14:06:22" }, { "name": "phpunit/phpunit", - "version": "5.3.2", + "version": "5.7.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "2c6da3536035617bae3fe3db37283c9e0eb63ab3" + "reference": "caf8141b89691498d91aaac6c82e9cd5f685ae86" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2c6da3536035617bae3fe3db37283c9e0eb63ab3", - "reference": "2c6da3536035617bae3fe3db37283c9e0eb63ab3", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/caf8141b89691498d91aaac6c82e9cd5f685ae86", + "reference": "caf8141b89691498d91aaac6c82e9cd5f685ae86", "shasum": "" }, "require": { "ext-dom": "*", "ext-json": "*", - "ext-pcre": "*", - "ext-reflection": "*", - "ext-spl": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", "myclabs/deep-copy": "~1.3", "php": "^5.6 || ^7.0", - "phpspec/prophecy": "^1.3.1", - "phpunit/php-code-coverage": "^3.3.0", + "phpspec/prophecy": "^1.6.2", + "phpunit/php-code-coverage": "^4.0.4", "phpunit/php-file-iterator": "~1.4", "phpunit/php-text-template": "~1.2", "phpunit/php-timer": "^1.0.6", - "phpunit/phpunit-mock-objects": "^3.1", - "sebastian/comparator": "~1.1", + "phpunit/phpunit-mock-objects": "^3.2", + "sebastian/comparator": "~1.2.2", "sebastian/diff": "~1.2", - "sebastian/environment": "~1.3", - "sebastian/exporter": "~1.2", - "sebastian/global-state": "~1.0", - "sebastian/object-enumerator": "~1.0", + "sebastian/environment": "^1.3.4 || ^2.0", + "sebastian/exporter": "~2.0", + "sebastian/global-state": "^1.0 || ^2.0", + "sebastian/object-enumerator": "~2.0", "sebastian/resource-operations": "~1.0", "sebastian/version": "~1.0|~2.0", "symfony/yaml": "~2.1|~3.0" }, + "conflict": { + "phpdocumentor/reflection-docblock": "3.0.2" + }, + "require-dev": { + "ext-pdo": "*" + }, "suggest": { + "ext-xdebug": "*", "phpunit/php-invoker": "~1.1" }, "bin": [ @@ -661,7 +721,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "5.3.x-dev" + "dev-master": "5.7.x-dev" } }, "autoload": { @@ -687,30 +747,33 @@ "testing", "xunit" ], - "time": "2016-04-12 16:20:08" + "time": "2017-01-22 08:39:59" }, { "name": "phpunit/phpunit-mock-objects", - "version": "3.1.3", + "version": "3.4.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "151c96874bff6fe61a25039df60e776613a61489" + "reference": "3ab72b65b39b491e0c011e2e09bb2206c2aa8e24" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/151c96874bff6fe61a25039df60e776613a61489", - "reference": "151c96874bff6fe61a25039df60e776613a61489", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/3ab72b65b39b491e0c011e2e09bb2206c2aa8e24", + "reference": "3ab72b65b39b491e0c011e2e09bb2206c2aa8e24", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", - "php": ">=5.6", - "phpunit/php-text-template": "~1.2", - "sebastian/exporter": "~1.2" + "php": "^5.6 || ^7.0", + "phpunit/php-text-template": "^1.2", + "sebastian/exporter": "^1.2 || ^2.0" + }, + "conflict": { + "phpunit/phpunit": "<5.4.0" }, "require-dev": { - "phpunit/phpunit": "~5" + "phpunit/phpunit": "^5.4" }, "suggest": { "ext-soap": "*" @@ -718,7 +781,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.1.x-dev" + "dev-master": "3.2.x-dev" } }, "autoload": { @@ -743,7 +806,7 @@ "mock", "xunit" ], - "time": "2016-04-20 14:39:26" + "time": "2016-12-08 20:27:08" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -792,22 +855,22 @@ }, { "name": "sebastian/comparator", - "version": "1.2.0", + "version": "1.2.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "937efb279bd37a375bcadf584dec0726f84dbf22" + "reference": "6a1ed12e8b2409076ab22e3897126211ff8b1f7f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/937efb279bd37a375bcadf584dec0726f84dbf22", - "reference": "937efb279bd37a375bcadf584dec0726f84dbf22", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/6a1ed12e8b2409076ab22e3897126211ff8b1f7f", + "reference": "6a1ed12e8b2409076ab22e3897126211ff8b1f7f", "shasum": "" }, "require": { "php": ">=5.3.3", "sebastian/diff": "~1.2", - "sebastian/exporter": "~1.2" + "sebastian/exporter": "~1.2 || ~2.0" }, "require-dev": { "phpunit/phpunit": "~4.4" @@ -852,7 +915,7 @@ "compare", "equality" ], - "time": "2015-07-26 15:48:44" + "time": "2016-11-19 09:18:40" }, { "name": "sebastian/diff", @@ -908,28 +971,28 @@ }, { "name": "sebastian/environment", - "version": "1.3.5", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "dc7a29032cf72b54f36dac15a1ca5b3a1b6029bf" + "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/dc7a29032cf72b54f36dac15a1ca5b3a1b6029bf", - "reference": "dc7a29032cf72b54f36dac15a1ca5b3a1b6029bf", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5795ffe5dc5b02460c3e34222fee8cbe245d8fac", + "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^5.6 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^5.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.3.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -954,33 +1017,34 @@ "environment", "hhvm" ], - "time": "2016-02-26 18:40:46" + "time": "2016-11-26 07:53:53" }, { "name": "sebastian/exporter", - "version": "1.2.1", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "7ae5513327cb536431847bcc0c10edba2701064e" + "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/7ae5513327cb536431847bcc0c10edba2701064e", - "reference": "7ae5513327cb536431847bcc0c10edba2701064e", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", + "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", "shasum": "" }, "require": { "php": ">=5.3.3", - "sebastian/recursion-context": "~1.0" + "sebastian/recursion-context": "~2.0" }, "require-dev": { + "ext-mbstring": "*", "phpunit/phpunit": "~4.4" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -1020,7 +1084,7 @@ "export", "exporter" ], - "time": "2015-06-21 07:55:53" + "time": "2016-11-19 08:54:04" }, { "name": "sebastian/global-state", @@ -1075,21 +1139,21 @@ }, { "name": "sebastian/object-enumerator", - "version": "1.0.0", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-enumerator.git", - "reference": "d4ca2fb70344987502567bc50081c03e6192fb26" + "reference": "96f8a3f257b69e8128ad74d3a7fd464bcbaa3b35" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/d4ca2fb70344987502567bc50081c03e6192fb26", - "reference": "d4ca2fb70344987502567bc50081c03e6192fb26", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/96f8a3f257b69e8128ad74d3a7fd464bcbaa3b35", + "reference": "96f8a3f257b69e8128ad74d3a7fd464bcbaa3b35", "shasum": "" }, "require": { "php": ">=5.6", - "sebastian/recursion-context": "~1.0" + "sebastian/recursion-context": "~2.0" }, "require-dev": { "phpunit/phpunit": "~5" @@ -1097,7 +1161,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -1117,20 +1181,20 @@ ], "description": "Traverses array structures and object graphs to enumerate all referenced objects", "homepage": "https://github.com/sebastianbergmann/object-enumerator/", - "time": "2016-01-28 13:25:10" + "time": "2016-11-19 07:35:10" }, { "name": "sebastian/recursion-context", - "version": "1.0.2", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "913401df809e99e4f47b27cdd781f4a258d58791" + "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/913401df809e99e4f47b27cdd781f4a258d58791", - "reference": "913401df809e99e4f47b27cdd781f4a258d58791", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/2c3ba150cbec723aa057506e73a8d33bdb286c9a", + "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a", "shasum": "" }, "require": { @@ -1142,7 +1206,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -1170,7 +1234,7 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2015-11-11 19:50:13" + "time": "2016-11-19 07:33:16" }, { "name": "sebastian/resource-operations", @@ -1216,16 +1280,16 @@ }, { "name": "sebastian/version", - "version": "2.0.0", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/version.git", - "reference": "c829badbd8fdf16a0bad8aa7fa7971c029f1b9c5" + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c829badbd8fdf16a0bad8aa7fa7971c029f1b9c5", - "reference": "c829badbd8fdf16a0bad8aa7fa7971c029f1b9c5", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", "shasum": "" }, "require": { @@ -1255,29 +1319,35 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2016-02-04 12:56:52" + "time": "2016-10-03 07:35:21" }, { "name": "symfony/yaml", - "version": "v3.0.4", + "version": "v3.2.2", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "0047c8366744a16de7516622c5b7355336afae96" + "reference": "50eadbd7926e31842893c957eca362b21592a97d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/0047c8366744a16de7516622c5b7355336afae96", - "reference": "0047c8366744a16de7516622c5b7355336afae96", + "url": "https://api.github.com/repos/symfony/yaml/zipball/50eadbd7926e31842893c957eca362b21592a97d", + "reference": "50eadbd7926e31842893c957eca362b21592a97d", "shasum": "" }, "require": { "php": ">=5.5.9" }, + "require-dev": { + "symfony/console": "~2.8|~3.0" + }, + "suggest": { + "symfony/console": "For validating YAML files using the lint command" + }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "3.2-dev" } }, "autoload": { @@ -1304,7 +1374,57 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2016-03-04 07:55:57" + "time": "2017-01-03 13:51:32" + }, + { + "name": "webmozart/assert", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/webmozart/assert.git", + "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozart/assert/zipball/2db61e59ff05fe5126d152bd0655c9ea113e550f", + "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.6", + "sebastian/version": "^1.0.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "time": "2016-11-23 20:04:58" } ], "aliases": [], diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index 0c29db1..b21e0aa 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -3,6 +3,7 @@ namespace Illuminate\Support; use Countable; +use Exception; use ArrayAccess; use Traversable; use ArrayIterator; @@ -25,6 +26,16 @@ class Collection implements ArrayAccess, Arrayable, Countable, IteratorAggregate */ protected $items = []; + /** + * The methods that can be proxied. + * + * @var array + */ + protected static $proxies = [ + 'contains', 'each', 'every', 'filter', 'first', 'map', + 'partition', 'reject', 'sortBy', 'sortByDesc', 'sum', + ]; + /** * Create a new collection. * @@ -113,7 +124,7 @@ public function median($key = null) * Get the mode of a given key. * * @param mixed $key - * @return array + * @return array|null */ public function mode($key = null) { @@ -154,22 +165,27 @@ public function collapse() * Determine if an item exists in the collection. * * @param mixed $key + * @param mixed $operator * @param mixed $value * @return bool */ - public function contains($key, $value = null) + public function contains($key, $operator = null, $value = null) { - if (func_num_args() == 2) { - return $this->contains(function ($item) use ($key, $value) { - return data_get($item, $key) == $value; - }); + if (func_num_args() == 1) { + if ($this->useAsCallable($key)) { + return ! is_null($this->first($key)); + } + + return in_array($key, $this->items); } - if ($this->useAsCallable($key)) { - return ! is_null($this->first($key)); + if (func_num_args() == 2) { + $value = $operator; + + $operator = '='; } - return in_array($key, $this->items); + return $this->contains($this->operatorForWhere($key, $operator, $value)); } /** @@ -234,27 +250,34 @@ public function each(callable $callback) } /** - * Create a new collection consisting of every n-th element. + * Determine if all items in the collection pass the given test. * - * @param int $step - * @param int $offset - * @return static + * @param string|callable $key + * @param mixed $operator + * @param mixed $value + * @return bool */ - public function every($step, $offset = 0) + public function every($key, $operator = null, $value = null) { - $new = []; - - $position = 0; + if (func_num_args() == 1) { + $callback = $this->valueRetriever($key); - foreach ($this->items as $item) { - if ($position % $step === $offset) { - $new[] = $item; + foreach ($this->items as $k => $v) { + if (! $callback($v, $k)) { + return false; + } } - $position++; + return true; } - return new static($new); + if (func_num_args() == 2) { + $value = $operator; + + $operator = '='; + } + + return $this->every($this->operatorForWhere($key, $operator, $value)); } /** @@ -625,7 +648,17 @@ public function map(callable $callback) */ public function mapWithKeys(callable $callback) { - return $this->flatMap($callback); + $result = []; + + foreach ($this->items as $key => $value) { + $assoc = $callback($value, $key); + + foreach ($assoc as $mapKey => $mapValue) { + $result[$mapKey] = $mapValue; + } + } + + return new static($result); } /** @@ -710,6 +743,30 @@ public function min($callback = null) }); } + /** + * Create a new collection consisting of every n-th element. + * + * @param int $step + * @param int $offset + * @return static + */ + public function nth($step, $offset = 0) + { + $new = []; + + $position = 0; + + foreach ($this->items as $item) { + if ($position % $step === $offset) { + $new[] = $item; + } + + $position++; + } + + return new static($new); + } + /** * Get the items with the specified keys. * @@ -835,7 +892,7 @@ public function put($key, $value) /** * Get one or more items randomly from the collection. * - * @param int $amount + * @param int|null $amount * @return mixed * * @throws \InvalidArgumentException @@ -843,15 +900,17 @@ public function put($key, $value) public function random($amount = 1) { if ($amount > ($count = $this->count())) { - throw new InvalidArgumentException("You requested {$amount} items, but there are only {$count} items in the collection"); + throw new InvalidArgumentException("You requested {$amount} items, but there are only {$count} items in the collection."); } $keys = array_rand($this->items, $amount); - if ($amount == 1) { + if (count(func_get_args()) == 0) { return $this->items[$keys]; } + $keys = array_wrap($keys); + return new static(array_intersect_key($this->items, array_flip($keys))); } @@ -1381,4 +1440,32 @@ protected function getArrayableItems($items) return (array) $items; } + + /** + * Add a method to the list of proxied methods. + * + * @param string $method + * @return void + */ + public static function proxy($method) + { + static::$proxies[] = $method; + } + + /** + * Dynamically access collection proxies. + * + * @param string $key + * @return mixed + * + * @throws \Exception + */ + public function __get($key) + { + if (! in_array($key, static::$proxies)) { + throw new Exception("Property [{$key}] does not exist on this collection instance."); + } + + return new HigherOrderCollectionProxy($this, $key); + } } diff --git a/src/Illuminate/Support/HigherOrderCollectionProxy.php b/src/Illuminate/Support/HigherOrderCollectionProxy.php new file mode 100644 index 0000000..f902431 --- /dev/null +++ b/src/Illuminate/Support/HigherOrderCollectionProxy.php @@ -0,0 +1,60 @@ +method = $method; + $this->collection = $collection; + } + + /** + * Proxy accessing an attribute onto the collection items. + * + * @param string $key + * @return mixed + */ + public function __get($key) + { + return $this->collection->{$this->method}(function ($value) use ($key) { + return is_array($value) ? $value[$key] : $value->{$key}; + }); + } + + /** + * Proxy a method call onto the collection items. + * + * @param string $method + * @param array $parameters + * @return mixed + */ + public function __call($method, $parameters) + { + return $this->collection->{$this->method}(function ($value) use ($method, $parameters) { + return $value->{$method}(...$parameters); + }); + } +} diff --git a/src/Illuminate/Support/helpers.php b/src/Illuminate/Support/helpers.php index 3b024ce..f5c730e 100644 --- a/src/Illuminate/Support/helpers.php +++ b/src/Illuminate/Support/helpers.php @@ -3,6 +3,19 @@ use Illuminate\Support\Arr; use Illuminate\Support\Collection; +if (! function_exists('array_wrap')) { + /** + * If the given value is not an array, wrap it in one. + * + * @param mixed $value + * @return array + */ + function array_wrap($value) + { + return ! is_array($value) ? [$value] : $value; + } +} + if (! function_exists('collect')) { /** * Create a collection from the given value. diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index 39be602..22ac4b3 100644 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -1,11 +1,19 @@ 'a', - 4 => 'b', - 7 => 'c', - 1 => 'd', - 5 => 'e', - 3 => 'f', - ]); + $c = new Collection([]); + $this->assertTrue($c->every('key', 'value')); + $this->assertTrue($c->every(function () { + return false; + })); + + $c = new Collection([['age' => 18], ['age' => 20], ['age' => 20]]); + $this->assertFalse($c->every('age', 18)); + $this->assertTrue($c->every('age', '>=', 18)); + $this->assertTrue($c->every(function ($item) { + return $item['age'] >= 18; + })); + $this->assertFalse($c->every(function ($item) { + return $item['age'] >= 20; + })); - $this->assertEquals(['a', 'e'], $data->every(4)->all()); - $this->assertEquals(['b', 'f'], $data->every(4, 1)->all()); - $this->assertEquals(['c'], $data->every(4, 2)->all()); - $this->assertEquals(['d'], $data->every(4, 3)->all()); + $c = new Collection([null, null]); + $this->assertTrue($c->every(function ($item) { + return $item === null; + })); + + $c = new Collection([['active' => true], ['active' => true]]); + $this->assertTrue($c->every('active')); + $this->assertTrue($c->every->active); + $this->assertFalse($c->push(['active' => false])->every->active); } public function testExcept() @@ -812,15 +832,24 @@ public function testRandom() { $data = new Collection([1, 2, 3, 4, 5, 6]); - $random = $data->random(); - $this->assertInternalType('integer', $random); - $this->assertContains($random, $data->all()); + $random = $data->random(1); + $this->assertInstanceOf(Collection::class, $random); + $this->assertCount(1, $random); $random = $data->random(3); $this->assertInstanceOf(Collection::class, $random); $this->assertCount(3, $random); } + public function testRandomWithoutArgument() + { + $data = new Collection([1, 2, 3, 4, 5, 6]); + + $random = $data->random(); + $this->assertInternalType('integer', $random); + $this->assertContains($random, $data->all()); + } + /** * @expectedException InvalidArgumentException */ @@ -852,6 +881,21 @@ public function testMacroable() $this->assertSame(['a', 'aa', 'aaa'], $c->foo()->all()); } + public function testCanAddMethodsToProxy() + { + Collection::macro('adults', function ($callback) { + return $this->filter(function ($item) use ($callback) { + return $callback($item) >= 18; + }); + }); + + Collection::proxy('adults'); + + $c = new Collection([['age' => 3], ['age' => 12], ['age' => 18], ['age' => 56]]); + + $this->assertSame([['age' => 18], ['age' => 56]], $c->adults->age->values()->all()); + } + public function testMakeMethod() { $collection = Collection::make('foo'); @@ -990,6 +1034,78 @@ public function testMapWithKeys() ); } + public function testMapWithKeysIntegerKeys() + { + $data = new Collection([ + ['id' => 1, 'name' => 'A'], + ['id' => 3, 'name' => 'B'], + ['id' => 2, 'name' => 'C'], + ]); + $data = $data->mapWithKeys(function ($item) { + return [$item['id'] => $item]; + }); + $this->assertSame( + [1, 3, 2], + $data->keys()->all() + ); + } + + public function testMapWithKeysMultipleRows() + { + $data = new Collection([ + ['id' => 1, 'name' => 'A'], + ['id' => 2, 'name' => 'B'], + ['id' => 3, 'name' => 'C'], + ]); + $data = $data->mapWithKeys(function ($item) { + return [$item['id'] => $item['name'], $item['name'] => $item['id']]; + }); + $this->assertSame( + [ + 1 => 'A', + 'A' => 1, + 2 => 'B', + 'B' => 2, + 3 => 'C', + 'C' => 3, + ], + $data->all() + ); + } + + public function testMapWithKeysCallbackKey() + { + $data = new Collection([ + 3 => ['id' => 1, 'name' => 'A'], + 5 => ['id' => 3, 'name' => 'B'], + 4 => ['id' => 2, 'name' => 'C'], + ]); + $data = $data->mapWithKeys(function ($item, $key) { + return [$key => $item['id']]; + }); + $this->assertSame( + [3, 5, 4], + $data->keys()->all() + ); + } + + public function testNth() + { + $data = new Collection([ + 6 => 'a', + 4 => 'b', + 7 => 'c', + 1 => 'd', + 5 => 'e', + 3 => 'f', + ]); + + $this->assertEquals(['a', 'e'], $data->nth(4)->all()); + $this->assertEquals(['b', 'f'], $data->nth(4, 1)->all()); + $this->assertEquals(['c'], $data->nth(4, 2)->all()); + $this->assertEquals(['d'], $data->nth(4, 3)->all()); + } + public function testTransform() { $data = new Collection(['first' => 'taylor', 'last' => 'otwell']); @@ -1160,6 +1276,11 @@ public function testContains() $this->assertTrue($c->contains('date')); $this->assertTrue($c->contains('class')); $this->assertFalse($c->contains('foo')); + + $c = new Collection([['a' => false, 'b' => false], ['a' => true, 'b' => false]]); + + $this->assertTrue($c->contains->a); + $this->assertFalse($c->contains->b); } public function testContainsStrict() @@ -1192,6 +1313,16 @@ public function testContainsStrict() $this->assertTrue($c->containsStrict('')); } + public function testContainsWithOperator() + { + $c = new Collection([['v' => 1], ['v' => 3], ['v' => '4'], ['v' => 5]]); + + $this->assertTrue($c->contains('v', '=', 4)); + $this->assertTrue($c->contains('v', '==', 4)); + $this->assertFalse($c->contains('v', '===', 4)); + $this->assertTrue($c->contains('v', '>', 4)); + } + public function testGettingSumFromCollection() { $c = new Collection([(object) ['foo' => 50], (object) ['foo' => 50]]); @@ -1664,7 +1795,35 @@ public function testSplitEmptyCollection() ); } - public function testPartitionWithClosure() + public function testHigherOrderCollectionMap() + { + $person1 = (object) ['name' => 'Taylor']; + $person2 = (object) ['name' => 'Yaz']; + + $collection = collect([$person1, $person2]); + + $this->assertEquals(['Taylor', 'Yaz'], $collection->map->name->toArray()); + + $collection = collect([new TestSupportCollectionHigherOrderItem, new TestSupportCollectionHigherOrderItem]); + + $this->assertEquals(['TAYLOR', 'TAYLOR'], $collection->each->uppercase()->map->name->toArray()); + } + + public function testHigherOrderCollectionMapFromArrays() + { + $person1 = ['name' => 'Taylor']; + $person2 = ['name' => 'Yaz']; + + $collection = collect([$person1, $person2]); + + $this->assertEquals(['Taylor', 'Yaz'], $collection->map->name->toArray()); + + $collection = collect([new TestSupportCollectionHigherOrderItem, new TestSupportCollectionHigherOrderItem]); + + $this->assertEquals(['TAYLOR', 'TAYLOR'], $collection->each->uppercase()->map->name->toArray()); + } + + public function testPartition() { $collection = new Collection(range(1, 10)); @@ -1710,6 +1869,29 @@ public function testPartitionEmptyCollection() return true; })); } + + public function testHigherOrderPartition() + { + $courses = new Collection([ + 'a' => ['free' => true], 'b' => ['free' => false], 'c' => ['free' => true], + ]); + + list($free, $premium) = $courses->partition->free; + + $this->assertSame(['a' => ['free' => true], 'c' => ['free' => true]], $free->toArray()); + + $this->assertSame(['b' => ['free' => false]], $premium->toArray()); + } +} + +class TestSupportCollectionHigherOrderItem +{ + public $name = 'taylor'; + + public function uppercase() + { + $this->name = strtoupper($this->name); + } } class TestAccessorEloquentTestStub