From f0ccfc023aae4061022635090c888801d6b717cc Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 14 Feb 2017 23:28:12 +0100 Subject: [PATCH] Create helper functions --- DataStorage/Database/Query/Builder.php | 31 ++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/DataStorage/Database/Query/Builder.php b/DataStorage/Database/Query/Builder.php index 39a54bed7..b0e02dab1 100644 --- a/DataStorage/Database/Query/Builder.php +++ b/DataStorage/Database/Query/Builder.php @@ -449,7 +449,7 @@ class Builder extends BuilderAbstract throw new \InvalidArgumentException('Unknown operator.'); } - $this->wheres[$key][] = [ + $this->wheres[$this->getPublicColumnName($column)][] = [ 'column' => $column, 'operator' => $operator[$i], 'value' => $values[$i], @@ -463,7 +463,7 @@ class Builder extends BuilderAbstract throw new \InvalidArgumentException('Unknown operator.'); } - $this->wheres[null][] = ['column' => $columns, 'operator' => $operator, 'value' => $values, + $this->wheres[$this->getPublicColumnName($columns)][] = ['column' => $columns, 'operator' => $operator, 'value' => $values, 'boolean' => $boolean,]; } else { throw new \InvalidArgumentException(); @@ -472,6 +472,18 @@ class Builder extends BuilderAbstract return $this; } + public function getWhereByColumn($column) + { + return $this->wheres[$this->getPublicColumnName($column)] ?? null; + } + + public function getTableOfSystem($expression, $systemIdentifier) + { + if(($pos = strpos($expression, $systemIdentifier . '.' . $systemIdentifier)) === false) { + return null; + } + } + /** * Where and sub condition. * @@ -1068,4 +1080,19 @@ class Builder extends BuilderAbstract throw new \Exception(); } + + public function getPublicColumnName($column) : string + { + if(is_string($column)) { + return $column; + } elseif($column instanceof Column) { + return $column->getPublicName(); + } elseif($column instanceof \Closure) { + return $column(); + } elseif($column instanceof \Serializable) { + return $column; + } + + throw new \Exception(); + } }