1
|
|
|
<?php namespace Pz\Doctrine\Rest\Action; |
2
|
|
|
|
3
|
|
|
use Doctrine\Common\Collections\Criteria; |
4
|
|
|
use Pz\Doctrine\Rest\BuilderChain\CriteriaChain; |
5
|
|
|
use Pz\Doctrine\Rest\QueryParser\FilterableQueryParser; |
6
|
|
|
use Pz\Doctrine\Rest\QueryParser\PropertyQueryParser; |
7
|
|
|
use Pz\Doctrine\Rest\RestRequestAbstract; |
8
|
|
|
use Pz\Doctrine\Rest\RestResponse; |
9
|
|
|
|
10
|
|
|
class IndexAction extends RestActionAbstract |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Entity alias. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $rootAlias; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param RestRequestAbstract $request |
21
|
|
|
* |
22
|
|
|
* @return RestResponse |
23
|
|
|
*/ |
24
|
3 |
|
public function handle(RestRequestAbstract $request) |
25
|
|
|
{ |
26
|
3 |
|
$request->authorize($this->repository()->getClassName()); |
27
|
2 |
|
$chain = CriteriaChain::create($this->criteriaBuilders($request)); |
28
|
|
|
|
29
|
2 |
|
$criteria = new Criteria(null, |
30
|
2 |
|
$request->getOrderBy(), |
31
|
2 |
|
$request->getStart(), |
32
|
2 |
|
$request->getLimit() |
33
|
|
|
); |
34
|
|
|
|
35
|
2 |
|
$qb = $this->repository() |
36
|
2 |
|
->createQueryBuilder($this->repository()->alias()) |
37
|
2 |
|
->addCriteria($chain->process($criteria)); |
38
|
|
|
|
39
|
2 |
|
return $this->response()->index($request, $qb); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param RestRequestAbstract $request |
44
|
|
|
* |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
2 |
|
protected function criteriaBuilders(RestRequestAbstract $request) |
48
|
|
|
{ |
49
|
|
|
return [ |
50
|
2 |
|
new PropertyQueryParser($request, $this->getQueryProperty()), |
|
|
|
|
51
|
2 |
|
new FilterableQueryParser($request, $this->getFilterable()), |
52
|
|
|
]; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Param that can be filtered if query is string. |
57
|
|
|
* |
58
|
|
|
* @return null|string |
59
|
|
|
*/ |
60
|
2 |
|
protected function getQueryProperty() |
61
|
|
|
{ |
62
|
2 |
|
return null; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get list of filterable entity properties. |
67
|
|
|
* |
68
|
|
|
* @return array |
69
|
|
|
*/ |
70
|
2 |
|
protected function getFilterable() |
71
|
|
|
{ |
72
|
2 |
|
return []; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.