Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Collections/IAggregateDaoCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

use Packaged\Dal\IDaoCollection;

/**
* @template T of \Packaged\Dal\IDao
* @extends IDaoCollection<T>
*/
interface IAggregateDaoCollection extends IDaoCollection
{
public function min($property = 'id');
Expand Down
29 changes: 16 additions & 13 deletions src/Foundation/DaoCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,26 @@
use Packaged\Helpers\Arrays;
use Packaged\Helpers\Objects;
use RuntimeException;
use Traversable;

/**
* @template T of IDao
* @implements IDaoCollection<T>
*/
class DaoCollection implements IDaoCollection
{
/**
* @var IDao[]
* @var T[]
*/
protected $_daos = [];

/**
* @var IDao
* @var T|null
*/
protected $_dao;
/**
* Class for the DAOs contained
*
* @var string
* @var class-string<T>
*/
protected $_daoClass;

Expand All @@ -40,7 +43,7 @@ protected function _prepareDaos()
/**
* @param $fresh bool Create a new instance of the DAO Class
*
* @return IDao
* @return T
*/
public function createNewDao($fresh = true)
{
Expand Down Expand Up @@ -68,9 +71,11 @@ public function createNewDao($fresh = true)
/**
* Create a new collection based on a DAO class
*
* @param string|object $daoClass
* @template D of IDao
*
* @return static
* @param class-string<D>|D $daoClass
*
* @return static<D>
*/
public static function create($daoClass)
{
Expand Down Expand Up @@ -99,7 +104,7 @@ public function clear()
}

/**
* @return IDao[]
* @return T[]
*/
public function getRawArray()
{
Expand All @@ -112,7 +117,7 @@ public function getRawArray()
*
* @param mixed $default
*
* @return IDao
* @return T|null
*/
public function first($default = null)
{
Expand Down Expand Up @@ -205,9 +210,7 @@ public function apull(array $properties, $keyProperty = null)
* Retrieve an external iterator
*
* @link http://php.net/manual/en/iteratoraggregate.getiterator.php
* @return Traversable An instance of an object implementing <b>Iterator</b>
* or
* <b>Traversable</b>
* @return ArrayIterator<array-key, T>
*/
#[\ReturnTypeWillChange]
public function getIterator()
Expand Down Expand Up @@ -248,7 +251,7 @@ public function offsetExists($offset)
* The offset to retrieve.
* </p>
*
* @return mixed Can return all value types.
* @return T|null
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
Expand Down
5 changes: 5 additions & 0 deletions src/IDaoCollection.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?php
namespace Packaged\Dal;

/**
* @template T of IDao
* @extends \IteratorAggregate<array-key, T>
* @extends \ArrayAccess<array-key, T>
*/
interface IDaoCollection
extends \Countable, \JsonSerializable, \IteratorAggregate,
\ArrayAccess
Expand Down
2 changes: 1 addition & 1 deletion src/Ql/Cql/CqlDao.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function getTimestamp()
/**
* @param string|object|null $class
*
* @return CqlDaoCollection
* @return CqlDaoCollection<static>
*/
protected static function _createCollection($class = null)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Ql/Cql/CqlDaoCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
use Packaged\QueryBuilder\SelectExpression\ISelectExpression;

/**
* @method CqlDao createNewDao($fresh = true)
* @method CqlDao[] getRawArray()
* @template T of CqlDao
* @extends QlDaoCollection<T>
*/
class CqlDaoCollection extends QlDaoCollection
{
/**
* @return CqlQueryBuilder
* @return class-string<CqlQueryBuilder>
*/
protected function _getQueryBuilder()
{
Expand Down
8 changes: 4 additions & 4 deletions src/Ql/QlDao.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function getTableName()
*
* @param $params
*
* @return QlDaoCollection
* @return QlDaoCollection<static>
*/
public static function loadWhere(...$params)
{
Expand All @@ -73,7 +73,7 @@ public static function loadWhere(...$params)
/**
* @param string|object|null $class
*
* @return QlDaoCollection
* @return QlDaoCollection<static>
*/
protected static function _createCollection($class = null)
{
Expand All @@ -88,7 +88,7 @@ protected static function _createCollection($class = null)
/**
* @param $params
*
* @return QlDaoCollection
* @return QlDaoCollection<static>
*/
public static function collection(...$params)
{
Expand All @@ -103,7 +103,7 @@ public static function collection(...$params)
/**
* @param $params
*
* @return QlDaoCollection
* @return QlDaoCollection<static>
*/
public function getCollection(...$params)
{
Expand Down
23 changes: 20 additions & 3 deletions src/Ql/QlDaoCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,22 @@
use Packaged\QueryBuilder\Statement\QueryStatement;

/**
* @method QlDao createNewDao($fresh = true)
* @method QlDao[] getRawArray()
* @template T of QlDao
* @extends DaoCollection<T>
* @implements IAggregateDaoCollection<T>
*
* @method $this where(...$expressions)
* @method $this andWhere(...$expressions)
* @method $this orWhere(...$expressions)
* @method $this having(...$expressions)
* @method $this orderBy($fields)
* @method $this limit($limit)
* @method $this limitWithOffset($offset, $limit)
* @method $this join($table, $sourceField, $destField = null, $where = null)
* @method $this innerJoin($table, $sourceField, $destField = null, $where = null)
* @method $this leftOuterJoin($table, $sourceField, $destField = null, $where = null)
* @method $this rightOuterJoin($table, $sourceField, $destField = null, $where = null)
* @method $this joinWithPredicates($table, ...$predicates)
*/
class QlDaoCollection extends DaoCollection
implements IAggregateDaoCollection, IStatement
Expand Down Expand Up @@ -166,6 +180,9 @@ public function loadWhere(...$params)
return $this;
}

/**
* @return $this
*/
public function load()
{
$dao = $this->createNewDao(false);
Expand Down Expand Up @@ -203,7 +220,7 @@ public function delete()
*
* @param mixed $default
*
* @return QlDao|null|mixed
* @return T|null
*/
public function first($default = null)
{
Expand Down
Loading