diff --git a/src/Common/PdoObject.php b/src/Common/PdoObject.php index a354c6a..3a85cfd 100644 --- a/src/Common/PdoObject.php +++ b/src/Common/PdoObject.php @@ -92,10 +92,6 @@ class PdoObject extends PDO { throw $e; } catch (\Throwable $e) { - if ( function_exists("debogueur") ) { - debogueur($statement, $parameters, $commit); - } - throw $e; } diff --git a/src/EntityCollection.php b/src/EntityCollection.php index 0058f41..1802787 100644 --- a/src/EntityCollection.php +++ b/src/EntityCollection.php @@ -8,6 +8,14 @@ class EntityCollection extends \ArrayObject { 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 { $idx = 0; diff --git a/src/Query/Where.php b/src/Query/Where.php index 11d9e58..6f7e0ec 100644 --- a/src/Query/Where.php +++ b/src/Query/Where.php @@ -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) { return new class($this->queryBuilder, $field, $value, $operator, $condition, $not) { - public $value; + public mixed $value; public bool $not = false; public string $field; public string $operator; @@ -85,7 +85,7 @@ class Where extends Fragment { 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->field = $field; $this->value = $value; @@ -122,8 +122,13 @@ class Where extends Fragment { if ( is_array($this->value) ) { $stack = []; - foreach($this->value as $item) { - $stack[] = $this->filterValue($item); + if ($this->value) { + foreach ($this->value as $item) { + $stack[] = $this->filterValue($item); + } + } + else { + $stack[] = $this->filterValue(false); } return "(" . implode(", ", $stack) . ")"; diff --git a/src/Query/WhereRawParameter.php b/src/Query/WhereRawParameter.php index ed876ba..a93aea6 100644 --- a/src/Query/WhereRawParameter.php +++ b/src/Query/WhereRawParameter.php @@ -4,4 +4,4 @@ namespace Ulmus\Query; -interface WhereRawParameter {} \ No newline at end of file +interface WhereRawParameter extends \Stringable {} \ No newline at end of file diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index 2b9de87..261bfcf 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -195,12 +195,12 @@ class QueryBuilder implements Query\QueryBuilderInterface 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 - if ( [] === $value ) { - return $this; - } + #if ( [] === $value ) { + # return $this; + #} if ( $this->where ?? false ) { $where = $this->where; @@ -217,12 +217,12 @@ class QueryBuilder implements Query\QueryBuilderInterface 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); } - 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 ) { $having = $this->having; @@ -476,7 +476,7 @@ class QueryBuilder implements Query\QueryBuilderInterface 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); @@ -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; } @@ -504,7 +504,7 @@ class QueryBuilder implements Query\QueryBuilderInterface return $this->render(); } - public function addParameter($value, string $key = null) : string + public function addParameter(mixed $value, string $key = null) : string { if ( $this->parent ?? false ) { return $this->parent->addParameter($value, $key); diff --git a/src/Repository/ConditionTrait.php b/src/Repository/ConditionTrait.php index e816ea4..a364c52 100644 --- a/src/Repository/ConditionTrait.php +++ b/src/Repository/ConditionTrait.php @@ -25,7 +25,7 @@ trait ConditionTrait 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); @@ -41,101 +41,101 @@ trait ConditionTrait 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); } - 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); } - 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); 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); 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); @@ -151,7 +151,7 @@ trait ConditionTrait 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) { $this->queryBuilder->removeFragment($item);