- Still WIP on Api's wrapper
This commit is contained in:
		
							parent
							
								
									1927b43999
								
							
						
					
					
						commit
						8e0dce3e71
					
				| @ -68,7 +68,7 @@ abstract class Sql { | |||||||
|         return static::identifier($sql); |         return static::identifier($sql); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public static function escape($value) |     public static function escape($value) : mixed | ||||||
|     { |     { | ||||||
|         switch(true) { |         switch(true) { | ||||||
|             case is_object($value): |             case is_object($value): | ||||||
|  | |||||||
| @ -346,6 +346,18 @@ class EntityCollection extends \ArrayObject implements \JsonSerializable { | |||||||
|         return ( new $className() )->fromArray($dataset); |         return ( new $className() )->fromArray($dataset); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public function arrayToEntities(array $list, ? string /*stringable*/ $entityClass = null) : self | ||||||
|  |     { | ||||||
|  |         $collection = new static(); | ||||||
|  |         $collection->entityClass = $entityClass ?? $this->entityClass; | ||||||
|  | 
 | ||||||
|  |         foreach($list as $dataset) { | ||||||
|  |             $collection->append($this->arrayToEntity($dataset, $entityClass)); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return $collection; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public function jsonSerialize(): mixed |     public function jsonSerialize(): mixed | ||||||
|     { |     { | ||||||
|         return $this->toArray(); |         return $this->toArray(); | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ class OrderBy extends Fragment { | |||||||
|         return $this; |         return $this; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function add(string $field, ? string $direction = null) : self |     public function add(object|string $field, ? string $direction = null) : self | ||||||
|     { |     { | ||||||
|         $this->validateFieldType($field); |         $this->validateFieldType($field); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -2,6 +2,8 @@ | |||||||
| 
 | 
 | ||||||
| namespace Ulmus\Query; | namespace Ulmus\Query; | ||||||
| 
 | 
 | ||||||
|  | use Ulmus\Query; | ||||||
|  | 
 | ||||||
| interface QueryBuilderInterface | interface QueryBuilderInterface | ||||||
| { | { | ||||||
|     public function push(Fragment $queryFragment) : self; |     public function push(Fragment $queryFragment) : self; | ||||||
| @ -9,5 +11,5 @@ interface QueryBuilderInterface | |||||||
|     public function render(bool $skipToken = false) /* mixed */; |     public function render(bool $skipToken = false) /* mixed */; | ||||||
|     public function reset() : void; |     public function reset() : void; | ||||||
|     public function getFragment(string $class, int $index = 0) : ? Fragment; |     public function getFragment(string $class, int $index = 0) : ? Fragment; | ||||||
|     public function removeFragment(Fragment $fragment) : void; |     public function removeFragment(Query\Fragment|array|\Stringable|string $fragment) : void; | ||||||
| } | } | ||||||
| @ -278,7 +278,7 @@ class QueryBuilder implements Query\QueryBuilderInterface | |||||||
|         return $this; |         return $this; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function groupBy(string|\Stringable $field, ? string $direction = null) : self |     public function groupBy(string|object $field, ? string $direction = null) : self | ||||||
|     { |     { | ||||||
|         if ( null === $groupBy = $this->getFragment(Query\GroupBy::class) ) { |         if ( null === $groupBy = $this->getFragment(Query\GroupBy::class) ) { | ||||||
|             $groupBy = new Query\GroupBy(); |             $groupBy = new Query\GroupBy(); | ||||||
|  | |||||||
| @ -532,7 +532,7 @@ class Repository | |||||||
|         return $this; |         return $this; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function orderBy(string|\Stringable $field, ? string $direction = null) : self |     public function orderBy(string|object $field, ? string $direction = null) : self | ||||||
|     { |     { | ||||||
|         $this->queryBuilder->orderBy($field, $direction); |         $this->queryBuilder->orderBy($field, $direction); | ||||||
| 
 | 
 | ||||||
| @ -550,7 +550,13 @@ class Repository | |||||||
|     public function orders(array $orderList) : self |     public function orders(array $orderList) : self | ||||||
|     { |     { | ||||||
|         foreach($orderList as $field => $direction) { |         foreach($orderList as $field => $direction) { | ||||||
|             $this->orderBy($field, $direction); |             if (is_numeric($field)) { | ||||||
|  |                 $this->orderBy($direction); | ||||||
|  |             } | ||||||
|  |             else { | ||||||
|  |                 # Associative array with direction
 | ||||||
|  |                 $this->orderBy($field, $direction); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return $this; |         return $this; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user