- Some small bugfixes done

This commit is contained in:
Dave M. 2023-03-23 14:56:13 +00:00
parent fa8adcace1
commit 58bdce0ea8
5 changed files with 28 additions and 9 deletions

View File

@ -6,7 +6,7 @@
"authors": [ "authors": [
{ {
"name": "Dave Mc Nicoll", "name": "Dave Mc Nicoll",
"email": "mcndave@gmail.com" "email": "info@mcnd.ca"
} }
], ],
"require": { "require": {

View File

@ -193,5 +193,8 @@ class SQLite implements AdapterInterface {
return (int) in_array($string, explode(',', $string_list)); return (int) in_array($string, explode(',', $string_list));
}, 2); }, 2);
$pdo->sqliteCreateFunction('day', fn($date) => ( new \DateTime($date) )->format('d'), 1);
$pdo->sqliteCreateFunction('month', fn($date) => ( new \DateTime($date) )->format('m'), 1);
$pdo->sqliteCreateFunction('year', fn($date) => ( new \DateTime($date) )->format('Y'), 1);
} }
} }

View File

@ -56,7 +56,7 @@ class EntityField implements WhereRawParameter
$definition = new FieldDefinition($adapter, $field); $definition = new FieldDefinition($adapter, $field);
return implode(" ", [ return implode(" ", [
$definition->getSqlName(), $adapter->escapeIdentifier($definition->getSqlName(), AdapterInterface::IDENTIFIER_FIELD),
$definition->getSqlType(), $definition->getSqlType(),
$definition->getSqlParams(), $definition->getSqlParams(),
]); ]);

View File

@ -49,6 +49,11 @@ class EntityCollection extends \ArrayObject {
return $this->filtersCollection($callback, true, false)->toArray(); return $this->filtersCollection($callback, true, false)->toArray();
} }
public function filtersCount(Callable $callback) : array
{
return $this->filtersCollection($callback, true, false)->count();
}
public function filtersOne(Callable $callback) : ? object public function filtersOne(Callable $callback) : ? object
{ {
foreach($this->filters($callback, true) as $item) { foreach($this->filters($callback, true) as $item) {
@ -209,7 +214,7 @@ class EntityCollection extends \ArrayObject {
return $list; return $list;
} }
public function unique(/*stringable|callable */ $field, bool $strict = false) : self public function unique(\Stringable|callable $field, bool $strict = false) : self
{ {
$list = []; $list = [];
$obj = new static(); $obj = new static();
@ -390,14 +395,16 @@ class EntityCollection extends \ArrayObject {
return $this; return $this;
} }
public function sort(callable $callback, $function = "uasort") : self public function sort(null|callable $callback = null, $function = "uasort") : self
{ {
$callback ??= fn($e1, $e2) => $e1 <=> $e2;
call_user_func_array([ $this, $function ], [ $callback ]); call_user_func_array([ $this, $function ], [ $callback ]);
return $this; return $this;
} }
public function rsort(callable $callback, $function = "uasort") : self public function rsort(null|callable $callback = null, $function = "uasort") : self
{ {
return $this->sort(...func_get_args())->reverse(); return $this->sort(...func_get_args())->reverse();
} }

View File

@ -22,16 +22,18 @@ class Repository
public ? ConnectionAdapter $adapter; public ? ConnectionAdapter $adapter;
protected Query\QueryBuilderInterface $queryBuilder;
protected EntityResolver $entityResolver;
public string $alias; public string $alias;
public string $entityClass; public string $entityClass;
public array $events = []; public array $events = [];
protected Query\QueryBuilderInterface $queryBuilder;
protected EntityResolver $entityResolver;
protected array $joined = [];
public function __construct(string $entity, string $alias = self::DEFAULT_ALIAS, ConnectionAdapter $adapter = null) { public function __construct(string $entity, string $alias = self::DEFAULT_ALIAS, ConnectionAdapter $adapter = null) {
$this->entityClass = $entity; $this->entityClass = $entity;
$this->alias = $alias; $this->alias = $alias;
@ -592,6 +594,13 @@ class Repository
# @TODO Apply FILTER annotation to this too ! # @TODO Apply FILTER annotation to this too !
foreach(array_filter((array) $fields) as $item) { foreach(array_filter((array) $fields) as $item) {
if ( isset($this->joined[$item]) ) {
continue;
}
else {
$this->joined[$item] = true;
}
$annotation = $this->entityResolver->searchFieldAnnotation($item, [ Attribute\Property\Join::class, Join::class ]) ?: $annotation = $this->entityResolver->searchFieldAnnotation($item, [ Attribute\Property\Join::class, Join::class ]) ?:
$this->entityResolver->searchFieldAnnotation($item, [ Attribute\Property\Relation::class, Relation::class ]); $this->entityResolver->searchFieldAnnotation($item, [ Attribute\Property\Relation::class, Relation::class ]);