1 | <?php |
||
5 | trait HasElementNames |
||
6 | { |
||
7 | /** |
||
8 | * Grid name. |
||
9 | * |
||
10 | * @var string |
||
11 | */ |
||
12 | protected $name; |
||
13 | |||
14 | /** |
||
15 | * HTML element names. |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $elementNames = [ |
||
20 | 'grid_row' => 'grid-row', |
||
21 | 'grid_select_all' => 'grid-select-all', |
||
22 | 'grid_per_page' => 'grid-per-pager', |
||
23 | 'grid_batch' => 'grid-batch', |
||
24 | 'export_selected' => 'export-selected', |
||
25 | 'selected_rows' => 'selectedRows', |
||
26 | ]; |
||
27 | |||
28 | /** |
||
29 | * Set name to grid. |
||
30 | * |
||
31 | * @param string $name |
||
32 | * @return $this |
||
33 | */ |
||
34 | public function setName($name) |
||
44 | |||
45 | /** |
||
46 | * Get name of grid. |
||
47 | * |
||
48 | * @return string |
||
49 | */ |
||
50 | public function getName() |
||
54 | |||
55 | /** |
||
56 | * @return string |
||
57 | */ |
||
58 | public function getGridRowName() |
||
62 | |||
63 | /** |
||
64 | * @return string |
||
65 | */ |
||
66 | public function getSelectAllName() |
||
70 | |||
71 | /** |
||
72 | * @return string |
||
73 | */ |
||
74 | public function getPerPageName() |
||
78 | |||
79 | /** |
||
80 | * @return string |
||
81 | */ |
||
82 | public function getGridBatchName() |
||
86 | |||
87 | /** |
||
88 | * @return string |
||
89 | */ |
||
90 | public function getExportSelectedName() |
||
94 | |||
95 | /** |
||
96 | * @return string |
||
97 | */ |
||
98 | public function getSelectedRowsName() |
||
108 | |||
109 | /** |
||
110 | * @return string |
||
111 | */ |
||
112 | protected function elementNameWithPrefix($name) |
||
122 | } |
||
123 |
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.