From 97e02abf76d38c4d595e631ee18ab29474d9d113 Mon Sep 17 00:00:00 2001 From: Reza Date: Fri, 4 Mar 2016 13:37:21 +0330 Subject: [PATCH] - extending Illuminate\Support\Collection so its method is available in ary. - checking php version before defining the ary() helper function. --- composer.json | 3 ++- src/Ary.php | 3 ++- src/helper.php | 23 ++++++++++++++++------- test/Test.php | 1 + 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index ffe6cc3..29d2287 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ } ], "require": { - "php": ">=5.4.0" + "php": ">=5.4.0", + "illuminate/support": "*" }, "autoload": { "psr-4": { diff --git a/src/Ary.php b/src/Ary.php index 71df75e..460074d 100644 --- a/src/Ary.php +++ b/src/Ary.php @@ -14,10 +14,11 @@ use ArrayAccess; use ArrayIterator; use CachingIterator; use Countable; +use Illuminate\Support\Collection; use IteratorAggregate; use JsonSerializable; -class Ary implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable +class Ary extends Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable { /** diff --git a/src/helper.php b/src/helper.php index 97b6531..93f210c 100644 --- a/src/helper.php +++ b/src/helper.php @@ -7,15 +7,24 @@ use Salarmehr\Ary; -if (!function_exists('ary')) { +if (!function_exists('ary') && phpversion()) { - /** - * @param mixed $items,... - * @return Ary - */ - function ary() + + function parse_version($version) { - return new Ary(...func_get_args()); + $version = explode('.', $version); + return $version[0] * 10000 + $version[1] * 100 + $version[2]; + } + + if (!defined('ary') && parse_version(PHP_VERSION) > parse_version('5.6.0')) { + /** + * @param mixed $items,... + * @return Ary + */ + function ary() + { + return new Ary(...func_get_args()); + } } } diff --git a/test/Test.php b/test/Test.php index 5a04d72..18d33d6 100644 --- a/test/Test.php +++ b/test/Test.php @@ -9,6 +9,7 @@ use \Salarmehr\Ary; +require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/../src/Ary.php'; class Test extends PHPUnit_Framework_TestCase