diff --git a/CHANGELOG.md b/CHANGELOG.md index ca5b7f7..d2b7560 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,12 @@ 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 + + ## [5.1.1] - 2018-07-07 ### Changed @@ -267,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 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 *