diff --git a/src/Attribute/Obj/Table.php b/src/Attribute/Obj/Table.php index 0cb734a..4c8e1b2 100644 --- a/src/Attribute/Obj/Table.php +++ b/src/Attribute/Obj/Table.php @@ -5,7 +5,7 @@ namespace Ulmus\Attribute\Obj; #[\Attribute(\Attribute::TARGET_CLASS)] class Table { public function __construct( - public string $name, + public ? string $name = null, public ? string $database = null, public ? string $schema = null, public ? string $adapter = null, diff --git a/src/Attribute/Property/Field/Bit.php b/src/Attribute/Property/Field/Bit.php new file mode 100644 index 0000000..5b94424 --- /dev/null +++ b/src/Attribute/Property/Field/Bit.php @@ -0,0 +1,18 @@ +getFragment(Query\Select::class) ) ) { $select->add($field); @@ -195,7 +195,7 @@ class QueryBuilder implements Query\QueryBuilderInterface return $this; } - public function where(/* 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, $value, string $operator = Query\Where::OPERATOR_EQUAL, string $condition = Query\Where::CONDITION_AND, bool $not = false) : self { # Empty IN case if ( [] === $value ) { @@ -217,12 +217,12 @@ class QueryBuilder implements Query\QueryBuilderInterface return $this; } - public function notWhere($field, $value, string $operator = Query\Where::CONDITION_AND) : self + public function notWhere(string|\Stringable $field, $value, string $operator = Query\Where::CONDITION_AND) : self { return $this->where($field, $value, $operator, true); } - public function having($field, $value, string $operator = Query\Where::OPERATOR_EQUAL, string $condition = Query\Where::CONDITION_AND, bool $not = false) : self + public function having(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_EQUAL, string $condition = Query\Where::CONDITION_AND, bool $not = false) : self { if ( $this->having ?? false ) { $having = $this->having; @@ -266,7 +266,7 @@ class QueryBuilder implements Query\QueryBuilderInterface return $this; } - public function orderBy(string $field, ? string $direction = null) : self + public function orderBy(string|\Stringable $field, ? string $direction = null) : self { if ( null === $orderBy = $this->getFragment(Query\OrderBy::class) ) { $orderBy = new Query\OrderBy(); @@ -278,7 +278,7 @@ class QueryBuilder implements Query\QueryBuilderInterface return $this; } - public function groupBy(string $field, ? string $direction = null) : self + public function groupBy(string|\Stringable $field, ? string $direction = null) : self { if ( null === $groupBy = $this->getFragment(Query\GroupBy::class) ) { $groupBy = new Query\GroupBy(); @@ -290,14 +290,14 @@ class QueryBuilder implements Query\QueryBuilderInterface return $this; } - public function join(string $type, /*string | QueryBuilder*/ $table, $field, $value, bool $outer = false, ? string $alias = null) : self + public function join(string $type, /*string | QueryBuilder*/ $table, mixed $field, mixed $value, bool $outer = false, ? string $alias = null) : self { $this->withJoin(...func_get_args()); return $this; } - public function withJoin(string $type, $table, $field, $value, bool $outer = false, ? string $alias = null) : Query\Join + public function withJoin(string $type, $table, mixed $field, mixed $value, bool $outer = false, ? string $alias = null) : Query\Join { $join = new Query\Join($this); diff --git a/src/Repository.php b/src/Repository.php index ee5b6e2..01d5420 100644 --- a/src/Repository.php +++ b/src/Repository.php @@ -316,7 +316,7 @@ class Repository $array = array_change_key_case($entity->toArray()); $dataset = array_change_key_case($entity->entityGetDataset(false, true)); -# dump($array, $dataset); + return array_udiff_assoc($oldValues ? $dataset : $array , $oldValues ? $array : $dataset, function($e1, $e2) { if ( is_array($e1) ) { if (is_array($e2)) { @@ -464,7 +464,7 @@ class Repository return $this; } - public function join(string $type, $table, $field, $value, ? string $alias = null, ? callable $callback = null) : self + public function join(string $type, $table, string|\Stringable $field, mixed $value, ? string $alias = null, ? callable $callback = null) : self { $join = $this->queryBuilder->withJoin($type, $this->escapeTable($table), $field, $value, false, $alias ? $this->escapeIdentifier($alias) : null); @@ -475,7 +475,7 @@ class Repository return $this; } - public function outerJoin(string $type, $table, $field, $value, ? string $alias = null, ? callable $callback = null) : self + public function outerJoin(string $type, $table, string|\Stringable $field, mixed $value, ? string $alias = null, ? callable $callback = null) : self { $join = $this->queryBuilder->withJoin($type, $this->escapeTable($table), $field, $value, true, $alias ? $this->escapeIdentifier($alias) : null); @@ -506,7 +506,7 @@ class Repository } - public function groupBy($field) : self + public function groupBy(string|\Stringable $field) : self { $this->queryBuilder->groupBy($field); @@ -522,7 +522,7 @@ class Repository return $this; } - public function orderBy($field, ? string $direction = null) : self + public function orderBy(string|\Stringable $field, ? string $direction = null) : self { $this->queryBuilder->orderBy($field, $direction); @@ -572,7 +572,7 @@ class Repository return $this; } - public function wherePrimaryKey($value) : self + public function wherePrimaryKey(mixed $value) : self { if ( null === $primaryKeyField = Ulmus::resolveEntity($this->entityClass)->getPrimaryKeyField() ) { throw new Exception\EntityPrimaryKeyUnknown("Entity has no field containing attributes 'primary_key'"); @@ -835,28 +835,28 @@ class Repository return Ulmus::datasetQueryBuilder($this->queryBuilder, $this->adapter); } - public function runQuery() /* : mixed */ + public function runQuery() : mixed { $this->finalizeQuery(); return Ulmus::runQuery($this->queryBuilder, $this->adapter); } - public function runInsertQuery() /* : mixed */ + public function runInsertQuery() : mixed { $this->finalizeQuery(); return Ulmus::runInsertQuery($this->queryBuilder, $this->adapter); } - public function runUpdateQuery() /* : mixed */ + public function runUpdateQuery() : mixed { $this->finalizeQuery(); return Ulmus::runUpdateQuery($this->queryBuilder, $this->adapter); } - public function runDeleteQuery() /* : mixed */ + public function runDeleteQuery() : mixed { $this->finalizeQuery(); diff --git a/src/Repository/ConditionTrait.php b/src/Repository/ConditionTrait.php index 38366c0..27847e6 100644 --- a/src/Repository/ConditionTrait.php +++ b/src/Repository/ConditionTrait.php @@ -25,7 +25,7 @@ trait ConditionTrait return $this; } - public function where($field, $value, string $operator = Query\Where::OPERATOR_EQUAL, $condition = Query\Where::CONDITION_AND) : self + public function where(string|\Stringable $field, $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($field, $value, string $operator = Query\Where::OPERATOR_EQUAL) : self + public function and(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_EQUAL) : self { return $this->where($field, $value, $operator); } - public function or($field, $value, string $operator = Query\Where::OPERATOR_EQUAL) : self + public function or(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_EQUAL) : self { $this->queryBuilder->where($field, $value, $operator, Query\Where::CONDITION_OR); return $this; } - public function notWhere($field, $value, string $operator = Query\Where::OPERATOR_EQUAL) : self + public function notWhere(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_EQUAL) : self { $this->queryBuilder->where($field, $value, $operator, Query\Where::CONDITION_AND, true); return $this; } - public function orNot($field, $value, string $operator = Query\Where::OPERATOR_NOT_EQUAL) : self + public function orNot(string|\Stringable $field, $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($field, $value, string $operator = Query\Where::OPERATOR_EQUAL, $condition = Query\Where::CONDITION_AND) : self + public function having(string|\Stringable $field, $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($field, $value, string $operator = Query\Where::OPERATOR_EQUAL) : self + public function orHaving(string|\Stringable $field, $value, string $operator = Query\Where::OPERATOR_EQUAL) : self { $this->queryBuilder->having($field, $value, $operator, Query\Where::CONDITION_OR); return $this; } - public function notHaving($field, $value, string $operator = Query\Where::OPERATOR_NOT_EQUAL) : self + public function notHaving(string|\Stringable $field, $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($field, $value) : self + public function orNotHaving(string|\Stringable $field, $value) : self { $this->queryBuilder->having($field, $value, Query\Where::OPERATOR_NOT_EQUAL, Query\Where::CONDITION_OR, true); return $this; } - public function in($field, $value, string $operator = Query\Where::COMPARISON_IN) : self + public function in(string|\Stringable $field, $value, string $operator = Query\Where::COMPARISON_IN) : self { $this->queryBuilder->where($field, $value, $operator); return $this; } - public function orIn($field, $value, string $operator = Query\Where::COMPARISON_IN) : self + public function orIn(string|\Stringable $field, $value, string $operator = Query\Where::COMPARISON_IN) : self { $this->queryBuilder->where($field, $value, $operator, Query\Where::CONDITION_OR); return $this; } - public function notIn($field, $value) : self + public function notIn(string|\Stringable $field, $value) : self { $this->queryBuilder->where($field, $value, Query\Where::COMPARISON_IN, true); return $this; } - public function orNotIn($field, $value) : self + public function orNotIn(string|\Stringable $field, $value) : self { return $this->orNot($field, $value, Query\Where::COMPARISON_IN, Query\Where::CONDITION_OR, true); } - public function like($field, $value) : self + public function like(string|\Stringable $field, $value) : self { $this->where($field, $value, Query\Where::OPERATOR_LIKE); return $this; } - public function orLike($field, $value) : self + public function orLike(string|\Stringable $field, $value) : self { $this->or($field, $value, Query\Where::OPERATOR_LIKE); return $this; } - public function notLike($field, $value) : self + public function notLike(string|\Stringable $field, $value) : self { $this->notWhere($field, $value, Query\Where::OPERATOR_LIKE);