Se crea objeto para manejar las condiciones y otro para los operadores
This commit is contained in:
@ -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;
|
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user