Merge branch 'master' of https://git.mcnd.ca/mcndave/ulmus
This commit is contained in:
commit
eb6434bb72
|
@ -92,10 +92,6 @@ class PdoObject extends PDO {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
catch (\Throwable $e) {
|
catch (\Throwable $e) {
|
||||||
if ( function_exists("debogueur") ) {
|
|
||||||
debogueur($statement, $parameters, $commit);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,14 @@ class EntityCollection extends \ArrayObject {
|
||||||
|
|
||||||
public ? string $entityClass = null;
|
public ? string $entityClass = null;
|
||||||
|
|
||||||
|
public static function instance(array $data, null|string $entityClass) : self
|
||||||
|
{
|
||||||
|
$instance = new static($data);
|
||||||
|
$instance->entityClass = $entityClass;
|
||||||
|
|
||||||
|
return $instance;
|
||||||
|
}
|
||||||
|
|
||||||
public function filters(Callable $callback, bool $yieldValueOnly = false) : Generator
|
public function filters(Callable $callback, bool $yieldValueOnly = false) : Generator
|
||||||
{
|
{
|
||||||
$idx = 0;
|
$idx = 0;
|
||||||
|
|
|
@ -76,7 +76,7 @@ class Where extends Fragment {
|
||||||
protected function whereCondition($field, $value, string $operator = self::OPERATOR_EQUAL, string $condition = self::CONDITION_AND, bool $not = false) {
|
protected function whereCondition($field, $value, string $operator = self::OPERATOR_EQUAL, string $condition = self::CONDITION_AND, bool $not = false) {
|
||||||
return new class($this->queryBuilder, $field, $value, $operator, $condition, $not) {
|
return new class($this->queryBuilder, $field, $value, $operator, $condition, $not) {
|
||||||
|
|
||||||
public $value;
|
public mixed $value;
|
||||||
public bool $not = false;
|
public bool $not = false;
|
||||||
public string $field;
|
public string $field;
|
||||||
public string $operator;
|
public string $operator;
|
||||||
|
@ -85,7 +85,7 @@ class Where extends Fragment {
|
||||||
|
|
||||||
protected string $content = "";
|
protected string $content = "";
|
||||||
|
|
||||||
public function __construct(QueryBuilderInterface $queryBuilder, string $field, $value, string $operator, string $condition, bool $not) {
|
public function __construct(QueryBuilderInterface $queryBuilder, string $field, mixed $value, string $operator, string $condition, bool $not) {
|
||||||
$this->queryBuilder = $queryBuilder;
|
$this->queryBuilder = $queryBuilder;
|
||||||
$this->field = $field;
|
$this->field = $field;
|
||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
|
@ -122,9 +122,14 @@ class Where extends Fragment {
|
||||||
if ( is_array($this->value) ) {
|
if ( is_array($this->value) ) {
|
||||||
$stack = [];
|
$stack = [];
|
||||||
|
|
||||||
|
if ($this->value) {
|
||||||
foreach ($this->value as $item) {
|
foreach ($this->value as $item) {
|
||||||
$stack[] = $this->filterValue($item);
|
$stack[] = $this->filterValue($item);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$stack[] = $this->filterValue(false);
|
||||||
|
}
|
||||||
|
|
||||||
return "(" . implode(", ", $stack) . ")";
|
return "(" . implode(", ", $stack) . ")";
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,4 +4,4 @@
|
||||||
namespace Ulmus\Query;
|
namespace Ulmus\Query;
|
||||||
|
|
||||||
|
|
||||||
interface WhereRawParameter {}
|
interface WhereRawParameter extends \Stringable {}
|
|
@ -195,12 +195,12 @@ class QueryBuilder implements Query\QueryBuilderInterface
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function where(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_EQUAL, string $condition = Query\Where::CONDITION_AND, bool $not = false) : self
|
public function where(string|\Stringable $field, mixed $value, string $operator = Query\Where::OPERATOR_EQUAL, string $condition = Query\Where::CONDITION_AND, bool $not = false) : self
|
||||||
{
|
{
|
||||||
# Empty IN case
|
# Empty IN case
|
||||||
if ( [] === $value ) {
|
#if ( [] === $value ) {
|
||||||
return $this;
|
# return $this;
|
||||||
}
|
#}
|
||||||
|
|
||||||
if ( $this->where ?? false ) {
|
if ( $this->where ?? false ) {
|
||||||
$where = $this->where;
|
$where = $this->where;
|
||||||
|
@ -217,12 +217,12 @@ class QueryBuilder implements Query\QueryBuilderInterface
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function notWhere(string|\Stringable $field, $value, string $operator = Query\Where::CONDITION_AND) : self
|
public function notWhere(string|\Stringable $field, mixed $value, string $operator = Query\Where::CONDITION_AND) : self
|
||||||
{
|
{
|
||||||
return $this->where($field, $value, $operator, true);
|
return $this->where($field, $value, $operator, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function having(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_EQUAL, string $condition = Query\Where::CONDITION_AND, bool $not = false) : self
|
public function having(string|\Stringable $field, mixed $value, string $operator = Query\Where::OPERATOR_EQUAL, string $condition = Query\Where::CONDITION_AND, bool $not = false) : self
|
||||||
{
|
{
|
||||||
if ( $this->having ?? false ) {
|
if ( $this->having ?? false ) {
|
||||||
$having = $this->having;
|
$having = $this->having;
|
||||||
|
@ -476,7 +476,7 @@ class QueryBuilder implements Query\QueryBuilderInterface
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeFragment(/*Query\Fragment|array*/ $fragment) : void
|
public function removeFragment(Query\Fragment|array|\Stringable|string $fragment) : void
|
||||||
{
|
{
|
||||||
is_object($fragment) && $fragment = get_class($fragment);
|
is_object($fragment) && $fragment = get_class($fragment);
|
||||||
|
|
||||||
|
@ -494,7 +494,7 @@ class QueryBuilder implements Query\QueryBuilderInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFragments(/*? Query\Fragment|array*/ $fragment = null) : array
|
public function getFragments(Query\Fragment|array|\Stringable|string $fragment = null) : array
|
||||||
{
|
{
|
||||||
return $fragment !== null ? array_filter($this->queryStack, fn($e) => is_a($e, $fragment, true) ) : $this->queryStack;
|
return $fragment !== null ? array_filter($this->queryStack, fn($e) => is_a($e, $fragment, true) ) : $this->queryStack;
|
||||||
}
|
}
|
||||||
|
@ -504,7 +504,7 @@ class QueryBuilder implements Query\QueryBuilderInterface
|
||||||
return $this->render();
|
return $this->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addParameter($value, string $key = null) : string
|
public function addParameter(mixed $value, string $key = null) : string
|
||||||
{
|
{
|
||||||
if ( $this->parent ?? false ) {
|
if ( $this->parent ?? false ) {
|
||||||
return $this->parent->addParameter($value, $key);
|
return $this->parent->addParameter($value, $key);
|
||||||
|
|
|
@ -25,7 +25,7 @@ trait ConditionTrait
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function where(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_EQUAL, $condition = Query\Where::CONDITION_AND) : self
|
public function where(string|\Stringable $field, mixed $value, string $operator = Query\Where::OPERATOR_EQUAL, $condition = Query\Where::CONDITION_AND) : self
|
||||||
{
|
{
|
||||||
$this->queryBuilder->where($field, $value, $operator, $condition);
|
$this->queryBuilder->where($field, $value, $operator, $condition);
|
||||||
|
|
||||||
|
@ -41,101 +41,101 @@ trait ConditionTrait
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function and(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_EQUAL) : self
|
public function and(string|\Stringable $field, mixed $value, string $operator = Query\Where::OPERATOR_EQUAL) : self
|
||||||
{
|
{
|
||||||
return $this->where($field, $value, $operator);
|
return $this->where($field, $value, $operator);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function or(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_EQUAL) : self
|
public function or(string|\Stringable $field, mixed $value, string $operator = Query\Where::OPERATOR_EQUAL) : self
|
||||||
{
|
{
|
||||||
$this->queryBuilder->where($field, $value, $operator, Query\Where::CONDITION_OR);
|
$this->queryBuilder->where($field, $value, $operator, Query\Where::CONDITION_OR);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function notWhere(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_EQUAL) : self
|
public function notWhere(string|\Stringable $field, mixed $value, string $operator = Query\Where::OPERATOR_EQUAL) : self
|
||||||
{
|
{
|
||||||
$this->queryBuilder->where($field, $value, $operator, Query\Where::CONDITION_AND, true);
|
$this->queryBuilder->where($field, $value, $operator, Query\Where::CONDITION_AND, true);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function orNot(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_NOT_EQUAL) : self
|
public function orNot(string|\Stringable $field, mixed $value, string $operator = Query\Where::OPERATOR_NOT_EQUAL) : self
|
||||||
{
|
{
|
||||||
$this->queryBuilder->notWhere($field, $value, $operator, Query\Where::CONDITION_OR, true);
|
$this->queryBuilder->notWhere($field, $value, $operator, Query\Where::CONDITION_OR, true);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function having(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_EQUAL, $condition = Query\Where::CONDITION_AND) : self
|
public function having(string|\Stringable $field, mixed $value, string $operator = Query\Where::OPERATOR_EQUAL, $condition = Query\Where::CONDITION_AND) : self
|
||||||
{
|
{
|
||||||
$this->queryBuilder->having($field, $value, $operator, $condition);
|
$this->queryBuilder->having($field, $value, $operator, $condition);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function orHaving(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_EQUAL) : self
|
public function orHaving(string|\Stringable $field, mixed $value, string $operator = Query\Where::OPERATOR_EQUAL) : self
|
||||||
{
|
{
|
||||||
$this->queryBuilder->having($field, $value, $operator, Query\Where::CONDITION_OR);
|
$this->queryBuilder->having($field, $value, $operator, Query\Where::CONDITION_OR);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function notHaving(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_NOT_EQUAL) : self
|
public function notHaving(string|\Stringable $field, mixed $value, string $operator = Query\Where::OPERATOR_NOT_EQUAL) : self
|
||||||
{
|
{
|
||||||
$this->queryBuilder->having($field, $value, $operator, Query\Where::CONDITION_AND, true);
|
$this->queryBuilder->having($field, $value, $operator, Query\Where::CONDITION_AND, true);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function orNotHaving(string|\Stringable $field, $value) : self
|
public function orNotHaving(string|\Stringable $field, mixed $value) : self
|
||||||
{
|
{
|
||||||
$this->queryBuilder->having($field, $value, Query\Where::OPERATOR_NOT_EQUAL, Query\Where::CONDITION_OR, true);
|
$this->queryBuilder->having($field, $value, Query\Where::OPERATOR_NOT_EQUAL, Query\Where::CONDITION_OR, true);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function in(string|\Stringable $field, $value, string $operator = Query\Where::COMPARISON_IN) : self
|
public function in(string|\Stringable $field, mixed $value, string $operator = Query\Where::COMPARISON_IN) : self
|
||||||
{
|
{
|
||||||
$this->queryBuilder->where($field, $value, $operator);
|
$this->queryBuilder->where($field, $value, $operator);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function orIn(string|\Stringable $field, $value, string $operator = Query\Where::COMPARISON_IN) : self
|
public function orIn(string|\Stringable $field, mixed $value, string $operator = Query\Where::COMPARISON_IN) : self
|
||||||
{
|
{
|
||||||
$this->queryBuilder->where($field, $value, $operator, Query\Where::CONDITION_OR);
|
$this->queryBuilder->where($field, $value, $operator, Query\Where::CONDITION_OR);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function notIn(string|\Stringable $field, $value) : self
|
public function notIn(string|\Stringable $field, mixed $value) : self
|
||||||
{
|
{
|
||||||
$this->queryBuilder->where($field, $value, Query\Where::COMPARISON_IN, Query\Where::CONDITION_AND, true);
|
$this->queryBuilder->where($field, $value, Query\Where::COMPARISON_IN, Query\Where::CONDITION_AND, true);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function orNotIn(string|\Stringable $field, $value) : self
|
public function orNotIn(string|\Stringable $field, mixed $value) : self
|
||||||
{
|
{
|
||||||
return $this->orNot($field, $value, Query\Where::COMPARISON_IN, Query\Where::CONDITION_OR, true);
|
return $this->orNot($field, $value, Query\Where::COMPARISON_IN, Query\Where::CONDITION_OR, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function like(string|\Stringable $field, $value) : self
|
public function like(string|\Stringable $field, mixed $value) : self
|
||||||
{
|
{
|
||||||
$this->where($field, $value, Query\Where::OPERATOR_LIKE);
|
$this->where($field, $value, Query\Where::OPERATOR_LIKE);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function orLike(string|\Stringable $field, $value) : self
|
public function orLike(string|\Stringable $field, mixed $value) : self
|
||||||
{
|
{
|
||||||
$this->or($field, $value, Query\Where::OPERATOR_LIKE);
|
$this->or($field, $value, Query\Where::OPERATOR_LIKE);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function notLike(string|\Stringable $field, $value) : self
|
public function notLike(string|\Stringable $field, mixed $value) : self
|
||||||
{
|
{
|
||||||
$this->notWhere($field, $value, Query\Where::OPERATOR_LIKE);
|
$this->notWhere($field, $value, Query\Where::OPERATOR_LIKE);
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ trait ConditionTrait
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeQueryFragment(/* Query\Fragment | stringable | array */ $fragment) : self
|
public function removeQueryFragment(Query\Fragment|\Stringable|string|array $fragment) : self
|
||||||
{
|
{
|
||||||
foreach((array) $fragment as $item) {
|
foreach((array) $fragment as $item) {
|
||||||
$this->queryBuilder->removeFragment($item);
|
$this->queryBuilder->removeFragment($item);
|
||||||
|
|
Loading…
Reference in New Issue