1 | <?php |
||
25 | trait EntityListingMethods |
||
26 | { |
||
27 | |||
28 | /** |
||
29 | * @var int |
||
30 | */ |
||
31 | protected $rowsPerPage = 12; |
||
32 | |||
33 | /** |
||
34 | * @var Pagination |
||
35 | */ |
||
36 | protected $pagination; |
||
37 | |||
38 | /** |
||
39 | * @var EntityListingService |
||
40 | */ |
||
41 | protected $listingService; |
||
42 | |||
43 | /** |
||
44 | * @var string[] |
||
45 | */ |
||
46 | protected $searchFields; |
||
47 | |||
48 | /** |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $order; |
||
52 | |||
53 | /** |
||
54 | * Handle the request to display a list of entities |
||
55 | */ |
||
56 | 2 | public function index() |
|
69 | |||
70 | /** |
||
71 | * Get pagination for roes per page property |
||
72 | * |
||
73 | * @return Pagination |
||
74 | */ |
||
75 | 4 | protected function getPagination() |
|
87 | |||
88 | /** |
||
89 | * Get the entity listing service |
||
90 | * |
||
91 | * @return EntityListingService |
||
92 | */ |
||
93 | 4 | protected function getListingService() |
|
94 | { |
||
95 | 4 | if (null == $this->listingService) { |
|
96 | 2 | $this->listingService = new EntityListingService( |
|
97 | 2 | $this->getEntityClassName() |
|
98 | 1 | ); |
|
99 | 1 | } |
|
100 | 4 | return $this->listingService; |
|
101 | } |
||
102 | |||
103 | /** |
||
104 | * Get search filter |
||
105 | * |
||
106 | * @return SearchFilter |
||
107 | */ |
||
108 | 4 | protected function getSearchFilter() |
|
116 | |||
117 | /** |
||
118 | * Get the fields list to use on search filter |
||
119 | * |
||
120 | * @return array|\string[] |
||
121 | */ |
||
122 | 2 | protected function getSearchFields() |
|
133 | |||
134 | /** |
||
135 | * Gets updated HTTP request |
||
136 | * |
||
137 | * @return ServerRequestInterface|Request |
||
138 | */ |
||
139 | abstract public function getRequest(); |
||
140 | |||
141 | /** |
||
142 | * Get the current entity descriptor |
||
143 | * |
||
144 | * @return \Slick\Orm\Descriptor\EntityDescriptorInterface |
||
145 | */ |
||
146 | abstract protected function getEntityDescriptor(); |
||
147 | |||
148 | /** |
||
149 | * Get the plural name of the entity |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | abstract protected function getEntityNamePlural(); |
||
154 | } |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.