From 42a1905c6a15e01962d52492111c8009c70c3b1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aryel=20Mota=20G=C3=B3is?= Date: Sun, 8 Jul 2018 10:51:55 -0300 Subject: [PATCH 1/2] Make ModelIterator Countable --- CHANGELOG.md | 3 +++ src/ModelIterator.php | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca5b7f7..4db9462 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Changed +- ModelIterator now implements Countable + ## [5.1.1] - 2018-07-07 diff --git a/src/ModelIterator.php b/src/ModelIterator.php index 405e0e8..1c38039 100644 --- a/src/ModelIterator.php +++ b/src/ModelIterator.php @@ -16,7 +16,7 @@ * @license MIT * @link https://www.github.com/aryelgois/Medools */ -class ModelIterator implements \Iterator +class ModelIterator implements \Iterator, \Countable { /** * List PRIMARY KEYS for $model_class @@ -63,6 +63,16 @@ public function __construct(string $model_class, $where = []) $this->list = $model_class::dump($where, $model_class::PRIMARY_KEY); } + /** + * Counts how many Models are in this Iterator + * + * @return int + */ + public function count() + { + return count($this->list); + } + /** * Loads the model with the current pointened PRIMARY KEY and returns it * From 951d165d424294151156d7ca8ef290cba20af8c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aryel=20Mota=20G=C3=B3is?= Date: Sun, 8 Jul 2018 10:52:36 -0300 Subject: [PATCH 2/2] Prepare 5.1.2 --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4db9462..d2b7560 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] + +## [5.1.2] - 2018-07-08 + ### Changed - ModelIterator now implements Countable @@ -270,7 +273,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - DatabaseObject.php -[Unreleased]: https://github.com/aryelgois/Medools/compare/v5.1.1...develop +[Unreleased]: https://github.com/aryelgois/Medools/compare/v5.1.2...develop +[5.1.2]: https://github.com/aryelgois/Medools/compare/v5.1.1...v5.1.2 [5.1.1]: https://github.com/aryelgois/Medools/compare/v5.1.0...v5.1.1 [5.1.0]: https://github.com/aryelgois/Medools/compare/v5.0.0...v5.1.0 [5.0.0]: https://github.com/aryelgois/Medools/compare/v4.3.0...v5.0.0