]> git.mxchange.org Git - friendica.git/blob - src/BaseCollection.php
Merge pull request #8072 from nupplaphil/task/Cache_to_DI
[friendica.git] / src / BaseCollection.php
1 <?php
2
3 namespace Friendica;
4
5 /**
6  * The Collection classes inheriting from this abstract class are meant to represent a list of database record.
7  * The associated model class has to be provided in the child classes.
8  *
9  * Collections can be used with foreach(), accessed like an array and counted.
10  */
11 abstract class BaseCollection extends \ArrayIterator
12 {
13         /**
14          * This property is used with paginated results to hold the total number of items satisfying the paginated request.
15          * @var int
16          */
17         protected $totalCount = 0;
18
19         /**
20          * @param BaseModel[] $models
21          * @param int|null    $totalCount
22          */
23         public function __construct(array $models = [], int $totalCount = null)
24         {
25                 parent::__construct($models);
26
27                 $this->models = $models;
28                 $this->totalCount = $totalCount ?? count($models);
29         }
30
31         /**
32          * @return int
33          */
34         public function getTotalCount()
35         {
36                 return $this->totalCount;
37         }
38 }