8 Commits

Author SHA1 Message Date
b11d283924 Merge branch 'develop' 2020-03-10 19:02:30 -03:00
79f5d4603a Merge branch 'develop' 2020-03-10 16:08:20 -03:00
1a5ad1162c Merge branch 'develop' 2020-03-10 11:44:19 -03:00
4212cefe4d Merge branch 'develop' 2020-03-02 13:53:26 -03:00
0e23c8b532 Merge branch 'develop' 2020-03-02 12:20:57 -03:00
4b2ea92a8d Merge branch 'develop' 2020-01-21 12:07:22 -03:00
5bc41ea3ff Merge branch 'develop' 2020-01-21 11:02:17 -03:00
c1b670f683 Merge branch 'develop' 2019-09-13 17:44:56 -03:00
5 changed files with 34 additions and 171 deletions

View File

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

View File

@ -127,20 +127,44 @@ class Model {
if ($this->conditions == null) {
$this->conditions = [];
}
foreach ($conditions as $condition) {
$this->addCondition($condition);
}
$this->conditions = array_merge($this->conditions, $conditions);
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) {
$orm = $condition->build($orm);
$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);
}
return $orm;
}

View File

@ -1,54 +0,0 @@
<?php
namespace Aldarien\Models\Factory;
class Condition {
protected $table;
protected $column;
protected $operator;
protected $value;
protected $alias;
public function setTable(string $table): Condition {
$this->table = $table;
return $this;
}
public function setColumn(string $column): Condition {
$this->column = $column;
return $this;
}
public function setOperator(Operator $operator): Condition {
$this->operator = $operator;
return $this;
}
public function setValue($value): Condition {
$this->value = $value;
return $this;
}
public function setAlias(string $alias): Condition {
$this->alias = $alias;
return $this;
}
public function fullColumn(): string {
$str = [];
if ($this->table != null) {
$str []= $this->table;
}
$str []= $this->column;
return implode('.', $str);
}
public function build(ORM $orm): ORM {
$method = $this->operator->method();
$params = [
$this->fullColumn()
];
if ($this->operator->hasValue()) {
$params []= $this->value;
}
if ($this->alias != null) {
$params []= $this->alias;
}
$orm = call_user_func_array([$orm, $method], $params);
return $orm;
}
}

View File

@ -1,107 +0,0 @@
<?php
namespace Aldarien\Models\Factory;
class Operator {
protected $value;
public function __construct(string $operator) {
$this->setOperator($operator);
}
public function setOperator(string $operator) {
if (!$this->isValid($operator)) {
throw new \InvalidArgumentException($operator . ' is not a valid operator.');
}
$this->value = strtolower($operator);
}
protected function isValid(string $operator): bool {
switch (strtolower($operator)) {
case '=':
case 'eq':
case '!=':
case 'neq':
case '<':
case 'lt':
case '<=':
case 'lte':
case '>':
case 'gt':
case '>=':
case 'gte':
case 'like':
case 'not like':
case 'in':
case 'not in':
case 'null':
case 'not null':
return true;
}
return false;
}
public function method(): string {
$method = 'where';
switch ($this->value) {
case '!=':
case 'neq':
$method .= '_not_equal';
break;
case '<':
case 'lt':
$method .= '_lt';
break;
case '<=':
case 'lte':
$method .= '_lte';
break;
case '>':
case 'gt':
$method .= '_gt';
break;
case '>=':
case 'gte':
$method .= '_gte';
break;
case 'like':
$method .= '_like';
break;
case 'not like':
$method .= '_not_like';
break;
case 'in':
$method .= '_in';
break;
case 'not in':
$method .='_not_in';
break;
case 'null':
$method .= '_null';
break;
case 'not null':
$method .= '_not_null';
break;
}
return $method;
}
public function hasValue(): bool {
switch ($this->value) {
case '=':
case 'eq':
case '!=':
case 'neq':
case '<':
case 'lt':
case '<=':
case 'lte':
case '>':
case 'gt':
case '>=':
case 'gte':
case 'like':
case 'not like':
case 'in':
case 'in':
case 'not in':
return true;
}
return false;
}
}

View File

@ -1,7 +1,7 @@
<?php
namespace Aldarien\Models;
use Aldarien\Common\Definition\DatabaseEngine\Requirements as EngineRequirementsInterface;
use Aldarien\Common\Definition\DatabaseEngineRequirements as EngineRequirementsInterface;
class MySQLRequirements implements EngineRequirementsInterface {
public function dsnSpecs(): array {