- Added a default searchRequest() method to entityTrait
This commit is contained in:
1 parent
d01624b8aa
commit
338b599d39
2 files changed
+72
-5
No files matched your search
+53
-1
@@ -3,7 +3,12 @@
|
||||
namespace Ulmus;
|
||||
|
||||
use Notes\Attribute\Ignore;
|
||||
use Ulmus\{ Repository, Query, Common\EntityResolver, Common\EntityField };
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Ulmus\{
|
||||
Common\EntityResolver,
|
||||
Common\EntityField,
|
||||
SearchRequest\SearchRequestInterface,
|
||||
SearchRequest\SearchRequestPaginationTrait};
|
||||
use Ulmus\Annotation\Classes\{ Method, Table, Collation, };
|
||||
use Ulmus\Annotation\Property\{ Field, Filter, FilterJoin, Relation, OrderBy, Where, OrWhere, Join, Virtual, On, WithJoin, };
|
||||
use Ulmus\Annotation\Property\Field\{ PrimaryKey, Id, ForeignKey, CreatedAt, UpdatedAt, Datetime as DateTime, Date, Time, Bigint, Tinyint, Text, Mediumtext, Longtext, Blob, Mediumblob, Longblob, };
|
||||
@@ -313,4 +318,51 @@ trait EntityTrait {
|
||||
return static::field($item, $alias);
|
||||
}, $fields));
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public static function searchRequest(...$arguments) : SearchRequestInterface
|
||||
{
|
||||
return new class() implements SearchRequestInterface
|
||||
{
|
||||
use SearchRequestPaginationTrait;
|
||||
|
||||
public function fromRequest(ServerRequestInterface $request) : self
|
||||
{
|
||||
$get = new \ArrayObject(array_filter($request->getQueryParams(), function($i) { return $i !== ""; }));
|
||||
|
||||
$this->page = $get->offsetExists('page') ? $get['page'] : 1;
|
||||
$this->limit = 100;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function filter(Repository $repository) : Repository
|
||||
{
|
||||
return $repository;
|
||||
}
|
||||
|
||||
public function wheres() : iterable
|
||||
{
|
||||
return array_filter([
|
||||
], fn($i) => ! is_null($i) ) + [ ];
|
||||
}
|
||||
|
||||
public function likes(): iterable
|
||||
{
|
||||
return array_filter([
|
||||
], fn($i) => ! is_null($i) ) + [];
|
||||
}
|
||||
|
||||
public function groups(): iterable
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function orders(): iterable
|
||||
{
|
||||
return array_filter([
|
||||
], fn($e) => ! is_null($e) && $e !== "" );
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user