php-cs-fixer
This commit is contained in:
parent
f7d2431160
commit
167a482163
3 changed files with 32 additions and 28 deletions
|
|
@ -282,13 +282,12 @@ abstract class AbstractModel implements ModelInterface, \Serializable
|
|||
return $this->destroyRecursively();
|
||||
}
|
||||
|
||||
protected function getProtectedMethods(): array
|
||||
{
|
||||
return ['getPrimaryKeys', 'getProtectedMethods', 'getDIContainer'];
|
||||
}
|
||||
|
||||
abstract public static function find(Finder $finder);
|
||||
|
||||
abstract public static function findOne(Finder $finder);
|
||||
|
||||
protected function getProtectedMethods(): array
|
||||
{
|
||||
return ['getPrimaryKeys', 'getProtectedMethods', 'getDIContainer'];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -611,22 +611,27 @@ abstract class AbstractTableGateway extends TableGateway
|
|||
return $row;
|
||||
}
|
||||
|
||||
public function getByFinder(Finder $finder){
|
||||
public function getByFinder(Finder $finder)
|
||||
{
|
||||
$select = $this->sql->select();
|
||||
|
||||
$select->where($finder);
|
||||
|
||||
if($finder->getOrder())
|
||||
if ($finder->getOrder()) {
|
||||
$select->order($finder->getOrder());
|
||||
}
|
||||
|
||||
if($finder->getLimit())
|
||||
if ($finder->getLimit()) {
|
||||
$select->limit($finder->getLimit());
|
||||
}
|
||||
|
||||
if($finder->getOffset())
|
||||
if ($finder->getOffset()) {
|
||||
$select->offset($finder->getOffset());
|
||||
}
|
||||
|
||||
return $this->selectWith($select);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Where $where
|
||||
* @param null|int $limit
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Benzine\ORM;
|
||||
|
||||
use Benzine\ORM\Exception\BenzineOrmException;
|
||||
use Laminas\Db\Sql\Predicate\PredicateSet;
|
||||
|
||||
class Finder extends \Laminas\Db\Sql\Where
|
||||
{
|
||||
|
|
@ -13,24 +13,24 @@ class Finder extends \Laminas\Db\Sql\Where
|
|||
private ?int $limit = null,
|
||||
private ?string $order = null,
|
||||
private string $orderDirection = 'ASC',
|
||||
){
|
||||
) {
|
||||
parent::__construct($predicates, $defaultCombination);
|
||||
}
|
||||
|
||||
public static function Where(){
|
||||
public static function Where()
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
|
||||
public function getOffset()
|
||||
{
|
||||
return $this->offset;
|
||||
}
|
||||
|
||||
|
||||
public function offset($offset)
|
||||
{
|
||||
$this->offset = $offset;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
@ -39,44 +39,44 @@ class Finder extends \Laminas\Db\Sql\Where
|
|||
return $this->limit;
|
||||
}
|
||||
|
||||
|
||||
public function limit($limit)
|
||||
{
|
||||
$this->limit = $limit;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOrder() : ?string
|
||||
public function getOrder(): ?string
|
||||
{
|
||||
if($this->order)
|
||||
if ($this->order) {
|
||||
return "{$this->order} {$this->orderDirection}";
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public function orderBy($order, $direction =null)
|
||||
public function orderBy($order, $direction = null)
|
||||
{
|
||||
$this->order = $order;
|
||||
if($direction)
|
||||
if ($direction) {
|
||||
$this->orderDirection($direction);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $orderDirection
|
||||
*
|
||||
* @return Finder
|
||||
*/
|
||||
public function orderDirection(string $orderDirection): Finder
|
||||
{
|
||||
if(!in_array($orderDirection, ['desc','asc'])){
|
||||
if (!in_array($orderDirection, ['desc', 'asc'], true)) {
|
||||
throw new BenzineOrmException(sprintf("Order direction must be one of 'desc' or 'asc', given '%s'", $orderDirection));
|
||||
}
|
||||
$this->orderDirection = $orderDirection;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue