From ed839e96e6cc1014dcc713966e2e20423dbf8f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dtalo=20Lelis=20de=20Vietro?= Date: Mon, 28 Jul 2014 18:26:03 -0300 Subject: [PATCH] Fixing collections with abstract methods --- composer.lock | 87 ++++++++++----------- src/Easy/Collections/AbstractCollection.php | 18 +++++ src/Easy/Collections/CollectionArray.php | 18 ----- src/Easy/Collections/ImmutableVector.php | 53 +------------ src/Easy/Collections/Queue.php | 20 +++-- src/Easy/Collections/Stack.php | 15 +++- 6 files changed, 81 insertions(+), 130 deletions(-) diff --git a/composer.lock b/composer.lock index 122b581..8c9e0bd 100755 --- a/composer.lock +++ b/composer.lock @@ -1,13 +1,14 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" ], - "hash": "fb8968b247d4748812129cdbd00aa337", + "hash": "3d734983502a04a38442f214e721d034", "packages": [ { "name": "easyframework/generics", - "version": "dev-master", + "version": "v1.0.1", "target-dir": "Easy/Generics", "source": { "type": "git", @@ -56,22 +57,22 @@ "packages-dev": [ { "name": "phpunit/php-code-coverage", - "version": "1.2.13", + "version": "1.2.17", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "466e7cd2554b4e264c9e3f31216d25ac0e5f3d94" + "reference": "6ef2bf3a1c47eca07ea95f0d8a902a6340390b34" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/466e7cd2554b4e264c9e3f31216d25ac0e5f3d94", - "reference": "466e7cd2554b4e264c9e3f31216d25ac0e5f3d94", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/6ef2bf3a1c47eca07ea95f0d8a902a6340390b34", + "reference": "6ef2bf3a1c47eca07ea95f0d8a902a6340390b34", "shasum": "" }, "require": { "php": ">=5.3.3", "phpunit/php-file-iterator": ">=1.3.0@stable", - "phpunit/php-text-template": ">=1.1.1@stable", + "phpunit/php-text-template": ">=1.2.0@stable", "phpunit/php-token-stream": ">=1.1.3@stable" }, "require-dev": { @@ -113,7 +114,7 @@ "testing", "xunit" ], - "time": "2013-09-10 08:14:32" + "time": "2014-03-28 10:53:45" }, { "name": "phpunit/php-file-iterator", @@ -162,16 +163,16 @@ }, { "name": "phpunit/php-text-template", - "version": "1.1.4", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "5180896f51c5b3648ac946b05f9ec02be78a0b23" + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/5180896f51c5b3648ac946b05f9ec02be78a0b23", - "reference": "5180896f51c5b3648ac946b05f9ec02be78a0b23", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", "shasum": "" }, "require": { @@ -202,7 +203,7 @@ "keywords": [ "template" ], - "time": "2012-10-31 18:15:28" + "time": "2014-01-30 17:20:04" }, { "name": "phpunit/php-timer", @@ -250,7 +251,7 @@ }, { "name": "phpunit/php-token-stream", - "version": "dev-master", + "version": "1.2.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", @@ -300,38 +301,37 @@ }, { "name": "phpunit/phpunit", - "version": "3.7.x-dev", + "version": "3.7.37", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "4dbc3ab5de25a9ffd07796519f9f7f4aaddc37e0" + "reference": "ae6cefd7cc84586a5ef27e04bae11ee940ec63dc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/4dbc3ab5de25a9ffd07796519f9f7f4aaddc37e0", - "reference": "4dbc3ab5de25a9ffd07796519f9f7f4aaddc37e0", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ae6cefd7cc84586a5ef27e04bae11ee940ec63dc", + "reference": "ae6cefd7cc84586a5ef27e04bae11ee940ec63dc", "shasum": "" }, "require": { + "ext-ctype": "*", "ext-dom": "*", + "ext-json": "*", "ext-pcre": "*", "ext-reflection": "*", "ext-spl": "*", "php": ">=5.3.3", - "phpunit/php-code-coverage": "~1.2.1", - "phpunit/php-file-iterator": "~1.3.1", - "phpunit/php-text-template": "~1.1.1", - "phpunit/php-timer": "~1.0.4", - "phpunit/phpunit-mock-objects": "~1.2.0", + "phpunit/php-code-coverage": "~1.2", + "phpunit/php-file-iterator": "~1.3", + "phpunit/php-text-template": "~1.1", + "phpunit/php-timer": "~1.0", + "phpunit/phpunit-mock-objects": "~1.2", "symfony/yaml": "~2.0" }, "require-dev": { "pear-pear.php.net/pear": "1.9.4" }, "suggest": { - "ext-json": "*", - "ext-simplexml": "*", - "ext-tokenizer": "*", "phpunit/php-invoker": "~1.1" }, "bin": [ @@ -370,38 +370,30 @@ "testing", "xunit" ], - "time": "2014-03-05 12:52:24" + "time": "2014-04-30 12:24:19" }, { "name": "phpunit/phpunit-mock-objects", - "version": "1.2.x-dev", + "version": "1.2.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "c39c4511c3b007539eb170c32cbc2af49a07351a" + "reference": "5794e3c5c5ba0fb037b11d8151add2a07fa82875" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/c39c4511c3b007539eb170c32cbc2af49a07351a", - "reference": "c39c4511c3b007539eb170c32cbc2af49a07351a", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/5794e3c5c5ba0fb037b11d8151add2a07fa82875", + "reference": "5794e3c5c5ba0fb037b11d8151add2a07fa82875", "shasum": "" }, "require": { "php": ">=5.3.3", "phpunit/php-text-template": ">=1.1.1@stable" }, - "require-dev": { - "phpunit/phpunit": "3.7.*@dev" - }, "suggest": { "ext-soap": "*" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, "autoload": { "classmap": [ "PHPUnit/" @@ -427,21 +419,21 @@ "mock", "xunit" ], - "time": "2014-02-16 12:43:56" + "time": "2013-01-13 10:24:48" }, { "name": "symfony/yaml", - "version": "dev-master", + "version": "v2.5.2", "target-dir": "Symfony/Component/Yaml", "source": { "type": "git", "url": "https://github.com/symfony/Yaml.git", - "reference": "6194137af5f12fbcfc0cb21e269f47542b8beb47" + "reference": "f868ecdbcc0276b6158dfbf08b9e98ce07f014e1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/6194137af5f12fbcfc0cb21e269f47542b8beb47", - "reference": "6194137af5f12fbcfc0cb21e269f47542b8beb47", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/f868ecdbcc0276b6158dfbf08b9e98ce07f014e1", + "reference": "f868ecdbcc0276b6158dfbf08b9e98ce07f014e1", "shasum": "" }, "require": { @@ -476,16 +468,17 @@ ], "description": "Symfony Yaml Component", "homepage": "http://symfony.com", - "time": "2014-03-03 12:53:01" + "time": "2014-07-09 09:05:48" } ], "aliases": [ ], - "minimum-stability": "dev", + "minimum-stability": "stable", "stability-flags": [ ], + "prefer-stable": false, "platform": [ ], diff --git a/src/Easy/Collections/AbstractCollection.php b/src/Easy/Collections/AbstractCollection.php index ea2adce..b743afb 100644 --- a/src/Easy/Collections/AbstractCollection.php +++ b/src/Easy/Collections/AbstractCollection.php @@ -135,4 +135,22 @@ public function toKeysArrays() { return array_keys($this->array); } + + /** + * {@inheritdoc} + */ + public function concat(ICollectionConvertable $collection) + { + $this->array = array_merge_recursive($this->array, + $collection->toArray()); + return $this; + } + + /** + * {@inheritdoc} + */ + public static function fromItems(Traversable $items) + { + return new static($items); + } } \ No newline at end of file diff --git a/src/Easy/Collections/CollectionArray.php b/src/Easy/Collections/CollectionArray.php index 521fa8d..eb6e4ac 100644 --- a/src/Easy/Collections/CollectionArray.php +++ b/src/Easy/Collections/CollectionArray.php @@ -139,24 +139,6 @@ public function map($p) return static::fromArray(array_map($p, $this->array)); } - /** - * {@inheritdoc} - */ - public function concat(ICollectionConvertable $collection) - { - $this->array = array_merge_recursive($this->array, - $collection->toArray()); - return $this; - } - - /** - * {@inheritdoc} - */ - public static function fromItems(Traversable $items) - { - return new static($items); - } - /** * {@inheritdoc} */ diff --git a/src/Easy/Collections/ImmutableVector.php b/src/Easy/Collections/ImmutableVector.php index 013dca5..af3e40d 100644 --- a/src/Easy/Collections/ImmutableVector.php +++ b/src/Easy/Collections/ImmutableVector.php @@ -1,16 +1,11 @@ array, $p)); - } - - /** - * {@inheritdoc} - */ - public function matching(Criteria $criteria) - { - $expr = $criteria->getWhereExpression(); - $filtered = $this->array; - - if ($expr) { - $visitor = new ClosureExpressionVisitor(); - $filter = $visitor->dispatch($expr); - $filtered = array_filter($filtered, $filter); - } - - if ($orderings = $criteria->getOrderings()) { - $next = null; - foreach (array_reverse($orderings) as $field => $ordering) { - $next = ClosureExpressionVisitor::sortByField($field, $ordering == 'DESC' ? -1 : 1, $next); - } - - if ($next === null) { - throw new InvalidArgumentException("The next value needs to be a callable function"); - } - - usort($filtered, $next); - } - - $offset = $criteria->getFirstResult(); - $length = $criteria->getMaxResults(); - - if ($offset || $length) { - $filtered = array_slice($filtered, (int) $offset, $length); - } - - return ImmutableVector::fromArray($filtered); - } - -} +} \ No newline at end of file diff --git a/src/Easy/Collections/Queue.php b/src/Easy/Collections/Queue.php index 46ef84c..fa7d660 100644 --- a/src/Easy/Collections/Queue.php +++ b/src/Easy/Collections/Queue.php @@ -60,18 +60,16 @@ public function peek() return $this->array[0]; } - public function concat(ICollectionConvertable $collection) - { - - } - public static function fromArray(array $arr) { - - } - - public static function fromItems(\Traversable $items) - { - + $collection = new Queue(); + foreach ($arr as $v) { + if (is_array($v)) { + $collection->enqueue(static::fromArray($v)); + } else { + $collection->enqueue($v); + } + } + return $collection; } } \ No newline at end of file diff --git a/src/Easy/Collections/Stack.php b/src/Easy/Collections/Stack.php index 625f1b3..ff2ef9a 100644 --- a/src/Easy/Collections/Stack.php +++ b/src/Easy/Collections/Stack.php @@ -1,7 +1,6 @@ array); } -} + public static function fromArray(array $arr) + { + $collection = new Stack(); + foreach ($arr as $v) { + if (is_array($v)) { + $collection->push(static::fromArray($v)); + } else { + $collection->push($v); + } + } + return $collection; + } +} \ No newline at end of file