Skip to content

Commit f117ea4

Browse files
authored
Support SelectQuery (#44)
1 parent bc770fc commit f117ea4

36 files changed

+221
-95
lines changed

.gitattributes

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,16 @@
2121
*.gif binary
2222
*.ttf binary
2323

24-
# Ignore some meta files when creating an archive of this repository
25-
/.github export-ignore
26-
/.editorconfig export-ignore
27-
/.gitattributes export-ignore
28-
/.gitignore export-ignore
29-
/.phpunit-watcher.yml export-ignore
30-
/.styleci.yml export-ignore
31-
/infection.json.dist export-ignore
32-
/phpunit.xml.dist export-ignore
33-
/psalm.xml export-ignore
34-
/tests export-ignore
35-
/docs export-ignore
24+
# Exclude development and metadata files from distribution archive
25+
* export-ignore
26+
/src/ -export-ignore
27+
/src/** -export-ignore
28+
/tests/ -export-ignore
29+
/tests/** -export-ignore
30+
/composer.json -export-ignore
31+
/README.md -export-ignore
32+
/CHANGELOG.md -export-ignore
33+
/LICENSE.md -export-ignore
3634

3735
# Avoid merge conflicts in CHANGELOG
3836
# https://about.gitlab.com/2015/02/10/gitlab-reduced-merge-conflicts-by-90-percent-with-changelog-placeholders/

.github/workflows/bc.yml_

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ jobs:
3030
os: >-
3131
['ubuntu-latest']
3232
php: >-
33-
['8.3']
33+
['8.4']

.github/workflows/composer-require-checker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ jobs:
3131
os: >-
3232
['ubuntu-latest']
3333
php: >-
34-
['8.1', '8.2', '8.3', '8.4']
34+
['8.1', '8.2', '8.3', '8.4', '8.5']

.github/workflows/mssql.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
- 8.2
3535
- 8.3
3636
- 8.4
37+
- 8.5
3738

3839
mssql:
3940
- server: 2022-latest

.github/workflows/mutation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
os: >-
2828
['ubuntu-latest']
2929
php: >-
30-
['8.4']
30+
['8.5']
3131
min-covered-msi: 100
3232
secrets:
3333
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}

.github/workflows/mysql.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jobs:
4141
- 8.2
4242
- 8.3
4343
- 8.4
44+
- 8.5
4445

4546
mysql:
4647
- 5.7

.github/workflows/pgsql.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jobs:
4141
- 8.2
4242
- 8.3
4343
- 8.4
44+
- 8.5
4445

4546
pgsql:
4647
- 9

.github/workflows/sqlite.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
- 8.2
3838
- 8.3
3939
- 8.4
40+
- 8.5
4041

4142
steps:
4243
- name: Checkout.

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@
3232
"prefer-stable": true,
3333
"minimum-stability": "dev",
3434
"require": {
35-
"php": "8.1 - 8.4",
35+
"php": "8.1 - 8.5",
3636
"ext-mbstring": "*",
3737
"cycle/database": "^2.11",
3838
"cycle/orm": "^2.9",
39-
"yiisoft/data": "dev-master"
39+
"yiisoft/data": "^2.0"
4040
},
4141
"require-dev": {
4242
"maglnet/composer-require-checker": "^4.7",
4343
"phpunit/phpunit": "^10.5",
4444
"rector/rector": "^2.1.5",
4545
"roave/infection-static-analysis-plugin": "^1.35",
4646
"spatie/phpunit-watcher": "^1.24",
47-
"vimeo/psalm": "^5.26.1 || ^6.10.3",
47+
"vimeo/psalm": "^5.26.1 || ^6.14.1",
4848
"vlucas/phpdotenv": "^5.6"
4949
},
5050
"autoload": {

src/Reader/EntityReader.php

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Yiisoft\Data\Cycle\Reader\FilterHandler\LikeHandler\LikeHandlerFactory;
1515
use Yiisoft\Data\Reader\DataReaderInterface;
1616
use Yiisoft\Data\Reader\Filter\All;
17-
use Yiisoft\Data\Reader\FilterHandlerInterface;
1817
use Yiisoft\Data\Reader\FilterInterface;
1918
use Yiisoft\Data\Reader\Sort;
2019
use Yiisoft\Data\Cycle\Reader\Cache\CachedCollection;
@@ -40,11 +39,14 @@ final class EntityReader implements DataReaderInterface
4039
private CachedCollection $itemsCache;
4140
private CachedCollection $oneItemCache;
4241
/**
43-
* @psalm-var array<class-string, FilterHandlerInterface & QueryBuilderFilterHandler> $handlers
42+
* @psalm-var array<class-string, QueryBuilderFilterHandler> $handlers
4443
*/
4544
private array $filterHandlers = [];
4645

47-
public function __construct(Select|SelectQuery $query)
46+
/**
47+
* @param QueryBuilderFilterHandler[] $extraFilterHandlers
48+
**/
49+
public function __construct(Select|SelectQuery $query, array $extraFilterHandlers = [])
4850
{
4951
$this->query = clone $query;
5052
$this->countCache = new CachedCount($this->query);
@@ -70,6 +72,7 @@ public function __construct(Select|SelectQuery $query)
7072
new FilterHandler\LessThanOrEqualHandler(),
7173
$likeHandler,
7274
new FilterHandler\NotHandler(),
75+
...$extraFilterHandlers,
7376
);
7477

7578
$this->filter = new All();
@@ -145,22 +148,6 @@ public function withFilter(FilterInterface $filter): static
145148
return $new;
146149
}
147150

148-
/**
149-
* @psalm-mutation-free
150-
*/
151-
#[\Override]
152-
public function withAddedFilterHandlers(FilterHandlerInterface ...$filterHandlers): static
153-
{
154-
$new = clone $this;
155-
/** @psalm-suppress ImpureMethodCall */
156-
$new->setFilterHandlers(...$filterHandlers);
157-
/** @psalm-suppress ImpureMethodCall */
158-
$new->resetCountCache();
159-
$new->itemsCache = new CachedCollection();
160-
$new->oneItemCache = new CachedCollection();
161-
return $new;
162-
}
163-
164151
#[\Override]
165152
public function count(): int
166153
{
@@ -207,13 +194,11 @@ public function getSql(): string
207194
return (string)($query instanceof Select ? $query->buildQuery() : $query);
208195
}
209196

210-
private function setFilterHandlers(FilterHandlerInterface ...$filterHandlers): void
197+
private function setFilterHandlers(QueryBuilderFilterHandler ...$filterHandlers): void
211198
{
212199
$handlers = [];
213200
foreach ($filterHandlers as $filterHandler) {
214-
if ($filterHandler instanceof QueryBuilderFilterHandler) {
215-
$handlers[$filterHandler->getFilterClass()] = $filterHandler;
216-
}
201+
$handlers[$filterHandler->getFilterClass()] = $filterHandler;
217202
}
218203
$this->filterHandlers = array_merge($this->filterHandlers, $handlers);
219204
}
@@ -238,7 +223,7 @@ private function buildSelectQuery(): SelectQuery|Select
238223

239224
private function makeFilterClosure(FilterInterface $filter): Closure
240225
{
241-
return function (QueryBuilder $select) use ($filter) {
226+
return function (QueryBuilder|SelectQuery $select) use ($filter) {
242227
if (!array_key_exists($filter::class, $this->filterHandlers)) {
243228
throw new NotSupportedFilterException($filter::class);
244229
}

0 commit comments

Comments
 (0)