orm refactoring

This commit is contained in:
Yuri Kuznetsov
2021-07-25 10:15:00 +03:00
parent bf943cc706
commit 49f12ac82f
12 changed files with 197 additions and 59 deletions
@@ -29,8 +29,53 @@
namespace Espo\ORM\Query;
use Espo\ORM\Query\Part\OrderExpression;
use Espo\ORM\Query\Part\WhereClause;
use RuntimeException;
trait SelectingTrait
{
/**
* Get ORDER items.
*
* @return OrderExpression[]
*/
public function getOrder(): array
{
return array_map(
function ($item) {
if (is_array($item) && count($item)) {
$itemValue = is_int($item[0]) ? (string) $item[0] : $item[0];
return OrderExpression::fromString($itemValue)
->withDirection($item[1] ?? OrderExpression::ASC);
}
if (is_string($item)) {
return OrderExpression::fromString($item);
}
throw new RuntimeException("Bad order item.");
},
$this->params['orderBy'] ?? []
);
}
/**
* Get WHERE clause.
*/
public function getWhere(): ?WhereClause
{
$whereClause = $this->params['whereClause'] ?? null;
if ($whereClause === null || $whereClause === []) {
return null;
}
return WhereClause::fromRaw($whereClause);
}
private static function validateRawParamsSelecting(array $params): void
{
}