Se crea objeto para manejar las condiciones y otro para los operadores

This commit is contained in:
2021-02-21 20:54:30 -03:00
parent 92ea9e4c7f
commit 1f28d533de
5 changed files with 171 additions and 34 deletions

View File

@ -1,7 +1,7 @@
<?php
namespace Aldarien\Common\Definition;
namespace Aldarien\Common\Definition\DatabaseEngine;
interface DatabaseEngineRequirements {
interface Requirements {
public function dsnSpecs(): array;
public function getDSN(object $config): string;
public function hasUser(): bool;

View File

@ -127,44 +127,20 @@ class Model {
if ($this->conditions == null) {
$this->conditions = [];
}
$this->conditions = array_merge($this->conditions, $conditions);
foreach ($conditions as $condition) {
$this->addCondition($condition);
}
return $this;
}
protected function addCondition(Condition $condition) {
$this->conditions []= $condition;
}
protected function parseWhere(ORM $orm): ORM {
if ($this->conditions == null or count($this->conditions) == 0) {
return $orm;
}
foreach ($this->conditions as $condition) {
$method = 'where';
$op = '=';
if (isset($condition[2])) {
$op = strtolower($condition[2]);
}
if (isset($condition['operator'])) {
$op = strtolower($condition['operator']);
}
$mod = ['=' => '', '>' => 'Gt', '>=' => 'Gte', '<' => 'Lt', '<=' => 'Lte', '!=' => 'NotEqual'];
if (isset($mod[$op])) {
$method .= $mod[$op];
} else {
switch (strtolower($op)) {
case 'raw':
$method = 'rawWhere';
break;
case 'like':
$method = 'whereLike';
break;
}
}
$column = $condition[0];
if (isset($condition['column'])) {
$column = $condition['column'];
}
$value = $condition[1];
if (isset($condition['value'])) {
$value = $condition['value'];
}
$orm = $orm->{$method}($column, $value);
$orm = $condition->build($orm);
}
return $orm;
}