mirror of
https://github.com/friendica/friendica
synced 2025-04-24 11:10:18 +00:00
Introduce Repository, Factory, Collection, Model base classes
This commit is contained in:
parent
ef6e9ef26b
commit
c748a82e8f
4 changed files with 291 additions and 26 deletions
42
src/BaseCollection.php
Normal file
42
src/BaseCollection.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica;
|
||||
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* The Collection classes inheriting from this abstract class are meant to represent a list of database record.
|
||||
* The associated model class has to be provided in the child classes.
|
||||
*
|
||||
* Collections can be used with foreach(), accessed like an array and counted.
|
||||
*/
|
||||
abstract class BaseCollection extends \ArrayIterator
|
||||
{
|
||||
/**
|
||||
* This property is used with paginated results to hold the total number of items satisfying the paginated request.
|
||||
* @var int
|
||||
*/
|
||||
protected $totalCount = 0;
|
||||
|
||||
/**
|
||||
* @param BaseModel[] $models
|
||||
* @param int|null $totalCount
|
||||
*/
|
||||
public function __construct(array $models = [], int $totalCount = null)
|
||||
{
|
||||
parent::__construct($models);
|
||||
|
||||
$this->models = $models;
|
||||
$this->totalCount = $totalCount ?? count($models);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalCount()
|
||||
{
|
||||
return $this->totalCount;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue