Introduce Repository, Factory, Collection, Model base classes

This commit is contained in:
Hypolite Petovan 2020-01-05 17:26:51 -05:00
parent ef6e9ef26b
commit c748a82e8f
4 changed files with 291 additions and 26 deletions

42
src/BaseCollection.php Normal file
View 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;
}
}