Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like DataGrid often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DataGrid, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
15 | class DataGrid extends Nette\Application\UI\Control |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * @var callable[] |
||
20 | */ |
||
21 | public $onRedraw; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | * @todo Tell about this on github |
||
26 | */ |
||
27 | public static $icon_prefix = 'fa fa-'; |
||
28 | |||
29 | /** |
||
30 | * When set to TRUE, datagrid throws an exception |
||
31 | * when tring to get related entity within join and entity does not exist |
||
32 | * @var bool |
||
33 | */ |
||
34 | public $strict_entity_property = FALSE; |
||
35 | |||
36 | /** |
||
37 | * @var int |
||
38 | * @persistent |
||
39 | */ |
||
40 | public $page = 1; |
||
41 | |||
42 | /** |
||
43 | * @var int |
||
44 | * @persistent |
||
45 | */ |
||
46 | public $per_page; |
||
47 | |||
48 | /** |
||
49 | * @var array |
||
50 | * @persistent |
||
51 | */ |
||
52 | public $sort = []; |
||
53 | |||
54 | /** |
||
55 | * @var array |
||
56 | * @persistent |
||
57 | */ |
||
58 | public $filter = []; |
||
59 | |||
60 | /** |
||
61 | * @var Callable[] |
||
62 | */ |
||
63 | public $onRender = []; |
||
64 | |||
65 | /** |
||
66 | * @var Callable[] |
||
67 | */ |
||
68 | protected $rowCallback; |
||
69 | |||
70 | /** |
||
71 | * @var array |
||
72 | */ |
||
73 | protected $items_per_page_list = [10, 20, 50]; |
||
74 | |||
75 | /** |
||
76 | * @var string |
||
77 | */ |
||
78 | protected $template_file; |
||
79 | |||
80 | /** |
||
81 | * @var Column\IColumn[] |
||
82 | */ |
||
83 | protected $columns = []; |
||
84 | |||
85 | /** |
||
86 | * @var Column\Action[] |
||
87 | */ |
||
88 | protected $actions = []; |
||
89 | |||
90 | /** |
||
91 | * @var GroupAction\GroupActionCollection |
||
92 | */ |
||
93 | protected $group_action_collection; |
||
94 | |||
95 | /** |
||
96 | * @var Filter\Filter[] |
||
97 | */ |
||
98 | protected $filters = []; |
||
99 | |||
100 | /** |
||
101 | * @var Export\Export[] |
||
102 | */ |
||
103 | protected $exports = []; |
||
104 | |||
105 | /** |
||
106 | * @var DataModel |
||
107 | */ |
||
108 | protected $dataModel; |
||
109 | |||
110 | /** |
||
111 | * @var DataFilter |
||
112 | */ |
||
113 | protected $dataFilter; |
||
114 | |||
115 | /** |
||
116 | * @var string |
||
117 | */ |
||
118 | protected $primary_key = 'id'; |
||
119 | |||
120 | /** |
||
121 | * @var bool |
||
122 | */ |
||
123 | protected $do_paginate = TRUE; |
||
124 | |||
125 | /** |
||
126 | * @var bool |
||
127 | */ |
||
128 | protected $csv_export = TRUE; |
||
129 | |||
130 | /** |
||
131 | * @var bool |
||
132 | */ |
||
133 | protected $csv_export_filtered = TRUE; |
||
134 | |||
135 | /** |
||
136 | * @var bool |
||
137 | */ |
||
138 | protected $sortable = FALSE; |
||
139 | |||
140 | /** |
||
141 | * @var string |
||
142 | */ |
||
143 | protected $sortable_handler = 'sort!'; |
||
144 | |||
145 | /** |
||
146 | * @var string |
||
147 | */ |
||
148 | protected $original_template; |
||
149 | |||
150 | /** |
||
151 | * @var array |
||
152 | */ |
||
153 | protected $redraw_item; |
||
154 | |||
155 | /** |
||
156 | * @var mixed |
||
157 | */ |
||
158 | protected $translator; |
||
159 | |||
160 | /** |
||
161 | * @var bool |
||
162 | */ |
||
163 | protected $force_filter_active; |
||
164 | |||
165 | /** |
||
166 | * @var callable |
||
167 | */ |
||
168 | protected $tree_view_children_callback; |
||
169 | |||
170 | /** |
||
171 | * @var string |
||
172 | */ |
||
173 | protected $tree_view_has_children_column; |
||
174 | |||
175 | /** |
||
176 | * @var bool |
||
177 | */ |
||
178 | protected $outer_filter_rendering = FALSE; |
||
179 | |||
180 | /** |
||
181 | * @var array |
||
182 | */ |
||
183 | protected $columns_export_order = []; |
||
184 | |||
185 | /** |
||
186 | * @var bool |
||
187 | */ |
||
188 | private $remember_state = TRUE; |
||
189 | |||
190 | /** |
||
191 | * @var bool |
||
192 | */ |
||
193 | private $refresh_url = TRUE; |
||
194 | |||
195 | /** |
||
196 | * @var Nette\Http\SessionSection |
||
197 | */ |
||
198 | private $grid_session; |
||
199 | |||
200 | /** |
||
201 | * @var array |
||
202 | */ |
||
203 | private $items_detail = []; |
||
204 | |||
205 | /** |
||
206 | * @var array |
||
207 | */ |
||
208 | private $row_conditions = [ |
||
209 | 'group_action' => FALSE, |
||
210 | 'action' => [] |
||
211 | ]; |
||
212 | |||
213 | |||
214 | /** |
||
215 | * @param Nette\ComponentModel\IContainer|NULL $parent |
||
216 | * @param string $name |
||
217 | */ |
||
218 | public function __construct(Nette\ComponentModel\IContainer $parent = NULL, $name = NULL) |
||
224 | |||
225 | |||
226 | /** |
||
227 | * {inheritDoc} |
||
228 | * @return void |
||
229 | */ |
||
230 | public function attached($presenter) |
||
246 | |||
247 | |||
248 | /** |
||
249 | * Find some unique session key name |
||
250 | * @return string |
||
251 | */ |
||
252 | public function getSessionSectionName() |
||
256 | |||
257 | |||
258 | /** |
||
259 | * Render template |
||
260 | * @return void |
||
261 | */ |
||
262 | public function render() |
||
336 | |||
337 | |||
338 | /** |
||
339 | * @param callable $callback |
||
340 | * @return static |
||
341 | */ |
||
342 | public function setRowCallback(callable $callback) |
||
347 | |||
348 | |||
349 | /** |
||
350 | * Return current paginator class |
||
351 | * @return NULL|Components\DataGridPaginator\DataGridPaginator |
||
352 | */ |
||
353 | public function getPaginator() |
||
361 | |||
362 | |||
363 | /** |
||
364 | * @param string $primary_key |
||
365 | */ |
||
366 | public function setPrimaryKey($primary_key) |
||
372 | |||
373 | |||
374 | /** |
||
375 | * Set Grid data source |
||
376 | * @param DataSource\IDataSource|array|\DibiFluent $source |
||
377 | * @return DataGrid |
||
378 | */ |
||
379 | public function setDataSource($source) |
||
415 | |||
416 | |||
417 | /** |
||
418 | * Is filter active? |
||
419 | * @return boolean |
||
420 | */ |
||
421 | public function isFilterActive() |
||
427 | |||
428 | |||
429 | /** |
||
430 | * Tell that filter is active from whatever reasons |
||
431 | * return self |
||
432 | */ |
||
433 | public function setFilterActive() |
||
439 | |||
440 | |||
441 | /** |
||
442 | * If we want to sent some initial filter |
||
443 | * @param array $filter |
||
444 | */ |
||
445 | public function setFilter(array $filter) |
||
451 | |||
452 | |||
453 | /** |
||
454 | * Set options of select "items_per_page" |
||
455 | * @param array $items_per_page_list |
||
456 | */ |
||
457 | public function setItemsPerPageList(array $items_per_page_list) |
||
463 | |||
464 | |||
465 | /** |
||
466 | * Set custom template file to render |
||
467 | * @param string $template_file |
||
468 | */ |
||
469 | public function setTemplateFile($template_file) |
||
475 | |||
476 | |||
477 | /** |
||
478 | * Get DataGrid template file |
||
479 | * @return string |
||
480 | */ |
||
481 | public function getTemplateFile() |
||
485 | |||
486 | |||
487 | /** |
||
488 | * Get DataGrid original template file |
||
489 | * @return string |
||
490 | */ |
||
491 | public function getOriginalTemplateFile() |
||
495 | |||
496 | |||
497 | /** |
||
498 | * Order Grid to "be paginated" |
||
499 | * @param bool $do |
||
500 | */ |
||
501 | public function setPagination($do) |
||
507 | |||
508 | |||
509 | /** |
||
510 | * Tell whether Grid is paginated |
||
511 | * @return bool |
||
512 | */ |
||
513 | public function isPaginated() |
||
517 | |||
518 | |||
519 | /** |
||
520 | * Set grido to be sortable |
||
521 | * @param bool $sortable |
||
522 | */ |
||
523 | public function setSortable($sortable = TRUE) |
||
533 | |||
534 | |||
535 | /** |
||
536 | * Set sortable handle |
||
537 | * @param string $handle |
||
538 | */ |
||
539 | public function setSortableHandler($handler = 'sort!') |
||
545 | |||
546 | |||
547 | /** |
||
548 | * Tell whether DataGrid is sortable |
||
549 | * @return bool |
||
550 | */ |
||
551 | public function isSortable() |
||
555 | |||
556 | /** |
||
557 | * Return sortable handle name |
||
558 | * @return string |
||
559 | */ |
||
560 | public function getSortableHandler() |
||
564 | |||
565 | |||
566 | /** |
||
567 | * Is tree view set? |
||
568 | * @return boolean |
||
569 | */ |
||
570 | public function isTreeView() |
||
574 | |||
575 | |||
576 | /** |
||
577 | * Setting tree view |
||
578 | * @param callable $get_children_callback |
||
579 | * @param string $tree_view_has_children_column |
||
580 | */ |
||
581 | public function setTreeView($get_children_callback, $tree_view_has_children_column = 'has_children') |
||
606 | |||
607 | |||
608 | /******************************************************************************** |
||
609 | * Columns * |
||
610 | ********************************************************************************/ |
||
611 | |||
612 | |||
613 | /** |
||
614 | * Add text column with no other formating |
||
615 | * @param string $key |
||
616 | * @param string $name |
||
617 | * @param string|null $column |
||
618 | * @return Column\Column |
||
619 | */ |
||
620 | public function addColumnText($key, $name, $column = NULL) |
||
627 | |||
628 | |||
629 | /** |
||
630 | * Add column with link |
||
631 | * @param string $key |
||
632 | * @param string $name |
||
633 | * @param string|null $column |
||
634 | * @return Column\Column |
||
635 | */ |
||
636 | public function addColumnLink($key, $name, $href = NULL, $column = NULL, array $params = NULL) |
||
648 | |||
649 | |||
650 | /** |
||
651 | * Add column with possible number formating |
||
652 | * @param string $key |
||
653 | * @param string $name |
||
654 | * @param string|null $column |
||
655 | * @return Column\Column |
||
656 | */ |
||
657 | public function addColumnNumber($key, $name, $column = NULL) |
||
664 | |||
665 | |||
666 | /** |
||
667 | * Add column with date formating |
||
668 | * @param string $key |
||
669 | * @param string $name |
||
670 | * @param string|null $column |
||
671 | * @return Column\Column |
||
672 | */ |
||
673 | public function addColumnDateTime($key, $name, $column = NULL) |
||
680 | |||
681 | |||
682 | /** |
||
683 | * Return existing column |
||
684 | * @param string $key |
||
685 | * @return Column\Column |
||
686 | * @throws DataGridException |
||
687 | */ |
||
688 | public function getColumn($key) |
||
696 | |||
697 | |||
698 | /** |
||
699 | * Remove column |
||
700 | * @param string $key |
||
701 | * @return void |
||
702 | */ |
||
703 | public function removeColumn($key) |
||
707 | |||
708 | |||
709 | /** |
||
710 | * Check whether given key already exists in $this->columns |
||
711 | * @param string $key |
||
712 | * @throws DataGridException |
||
713 | */ |
||
714 | protected function addColumnCheck($key) |
||
720 | |||
721 | |||
722 | /******************************************************************************** |
||
723 | * Actions * |
||
724 | ********************************************************************************/ |
||
725 | |||
726 | |||
727 | /** |
||
728 | * Create action |
||
729 | * @param string $key |
||
730 | * @param string $name |
||
731 | * @param string $href |
||
732 | * @param array|null $params |
||
733 | */ |
||
734 | public function addAction($key, $name = '', $href = NULL, array $params = NULL) |
||
745 | |||
746 | |||
747 | /** |
||
748 | * Get existing action |
||
749 | * @param string $key |
||
750 | * @return Column\Action |
||
751 | * @throws DataGridException |
||
752 | */ |
||
753 | public function getAction($key) |
||
761 | |||
762 | |||
763 | /** |
||
764 | * Remove action |
||
765 | * @param string $key |
||
766 | * @return void |
||
767 | */ |
||
768 | public function removeAction($key) |
||
772 | |||
773 | |||
774 | /** |
||
775 | * Check whether given key already exists in $this->filters |
||
776 | * @param string $key |
||
777 | * @throws DataGridException |
||
778 | */ |
||
779 | protected function addActionCheck($key) |
||
785 | |||
786 | |||
787 | /******************************************************************************** |
||
788 | * Filters * |
||
789 | ********************************************************************************/ |
||
790 | |||
791 | |||
792 | /** |
||
793 | * Add filter fot text search |
||
794 | * @param string $key |
||
795 | * @param string $name |
||
796 | * @param array|string $columns |
||
797 | * @throws DataGridException |
||
798 | */ |
||
799 | public function addFilterText($key, $name, $columns = NULL) |
||
811 | |||
812 | |||
813 | /** |
||
814 | * Add select box filter |
||
815 | * @param string $key |
||
816 | * @param string $name |
||
817 | * @param array $options |
||
818 | * @param string $column |
||
819 | * @throws DataGridException |
||
820 | */ |
||
821 | View Code Duplication | public function addFilterSelect($key, $name, $options, $column = NULL) |
|
833 | |||
834 | |||
835 | /** |
||
836 | * Add datepicker filter |
||
837 | * @param string $key |
||
838 | * @param string $name |
||
839 | * @param string $column |
||
840 | * @throws DataGridException |
||
841 | */ |
||
842 | public function addFilterDate($key, $name, $column = NULL) |
||
854 | |||
855 | |||
856 | /** |
||
857 | * Add range filter (from - to) |
||
858 | * @param string $key |
||
859 | * @param string $name |
||
860 | * @param string $column |
||
861 | * @throws DataGridException |
||
862 | */ |
||
863 | View Code Duplication | public function addFilterRange($key, $name, $column = NULL, $name_second = '-') |
|
875 | |||
876 | |||
877 | /** |
||
878 | * Add datepicker filter (from - to) |
||
879 | * @param string $key |
||
880 | * @param string $name |
||
881 | * @param string $column |
||
882 | * @throws DataGridException |
||
883 | */ |
||
884 | View Code Duplication | public function addFilterDateRange($key, $name, $column = NULL, $name_second = '-') |
|
896 | |||
897 | |||
898 | /** |
||
899 | * Check whether given key already exists in $this->filters |
||
900 | * @param string $key |
||
901 | * @throws DataGridException |
||
902 | */ |
||
903 | protected function addFilterCheck($key) |
||
909 | |||
910 | |||
911 | /** |
||
912 | * Fill array of Filter\Filter[] with values from $this->filter persistent parameter |
||
913 | * Fill array of Column\Column[] with values from $this->sort persistent parameter |
||
914 | * @return Filter\Filter[] $this->filters === Filter\Filter[] |
||
915 | */ |
||
916 | public function assableFilters() |
||
944 | |||
945 | |||
946 | /** |
||
947 | * Try to restore session stuff |
||
948 | * @return void |
||
949 | */ |
||
950 | public function findSessionFilters() |
||
978 | |||
979 | |||
980 | /** |
||
981 | * Remove filter |
||
982 | * @param string $key |
||
983 | * @return void |
||
984 | */ |
||
985 | public function removeFilter($key) |
||
989 | |||
990 | |||
991 | /******************************************************************************** |
||
992 | * Exports * |
||
993 | ********************************************************************************/ |
||
994 | |||
995 | |||
996 | /** |
||
997 | * Add export of type callback |
||
998 | * @param string $text |
||
999 | * @param callable $callback |
||
1000 | * @param boolean $filtered |
||
1001 | */ |
||
1002 | public function addExportCallback($text, $callback, $filtered = FALSE) |
||
1010 | |||
1011 | |||
1012 | /** |
||
1013 | * Add already implemented csv export |
||
1014 | * @param string $text |
||
1015 | * @param string $csv_file_name |
||
1016 | */ |
||
1017 | public function addExportCsv($text, $csv_file_name) |
||
1021 | |||
1022 | |||
1023 | /** |
||
1024 | * Add already implemented csv export, but for filtered data |
||
1025 | * @param string $text |
||
1026 | * @param string $csv_file_name |
||
1027 | */ |
||
1028 | public function addExportCsvFiltered($text, $csv_file_name) |
||
1032 | |||
1033 | |||
1034 | /** |
||
1035 | * Add export to array |
||
1036 | * @param Export\Export $export |
||
1037 | */ |
||
1038 | protected function addToExports(Export\Export $export) |
||
1046 | |||
1047 | |||
1048 | /******************************************************************************** |
||
1049 | * Group actions * |
||
1050 | ********************************************************************************/ |
||
1051 | |||
1052 | |||
1053 | /** |
||
1054 | * Add group actino |
||
1055 | * @param string $title |
||
1056 | * @param array $options |
||
1057 | */ |
||
1058 | public function addGroupAction($title, $options = []) |
||
1062 | |||
1063 | |||
1064 | /** |
||
1065 | * Get collection of all group actions |
||
1066 | * @return GroupAction\GroupActionCollection |
||
1067 | */ |
||
1068 | public function getGroupActionCollection() |
||
1076 | |||
1077 | |||
1078 | /******************************************************************************** |
||
1079 | * Signals * |
||
1080 | ********************************************************************************/ |
||
1081 | |||
1082 | |||
1083 | /** |
||
1084 | * Handler for changind page (just refresh site with page as persistent paramter set) |
||
1085 | * @param int $page |
||
1086 | * @return void |
||
1087 | */ |
||
1088 | public function handlePage($page) |
||
1098 | |||
1099 | |||
1100 | /** |
||
1101 | * Handler for sorting |
||
1102 | * @return void |
||
1103 | */ |
||
1104 | public function handleSort(array $sort) |
||
1114 | |||
1115 | |||
1116 | /** |
||
1117 | * handler for reseting the filter |
||
1118 | * @return void |
||
1119 | */ |
||
1120 | public function handleResetFilter() |
||
1137 | |||
1138 | |||
1139 | /** |
||
1140 | * Handler for export |
||
1141 | * @param int $id Key for particular export class in array $this->exports |
||
1142 | * @return void |
||
1143 | */ |
||
1144 | public function handleExport($id) |
||
1188 | |||
1189 | |||
1190 | /** |
||
1191 | * Handler for getting children of parent item (e.g. category) |
||
1192 | * @param int $parent |
||
1193 | * @return void |
||
1194 | */ |
||
1195 | View Code Duplication | public function handleGetChildren($parent) |
|
1212 | |||
1213 | |||
1214 | /** |
||
1215 | * Handler for getting item detail |
||
1216 | * @param mixed $id |
||
1217 | * @return void |
||
1218 | */ |
||
1219 | View Code Duplication | public function handleGetItemDetail($id) |
|
1233 | |||
1234 | |||
1235 | /** |
||
1236 | * Handler for inline editing |
||
1237 | * @param mixed $id |
||
1238 | * @param mixed $key |
||
1239 | * @return void |
||
1240 | */ |
||
1241 | public function handleEdit($id, $key) |
||
1248 | |||
1249 | |||
1250 | /** |
||
1251 | * Redraw $this |
||
1252 | * @return void |
||
1253 | */ |
||
1254 | public function reload($snippets = []) |
||
1277 | |||
1278 | |||
1279 | /** |
||
1280 | * Redraw just one row via ajax |
||
1281 | * @param int $id |
||
1282 | * @param mixed $primary_where_column |
||
1283 | * @return void |
||
1284 | */ |
||
1285 | public function redrawItem($id, $primary_where_column = NULL) |
||
1294 | |||
1295 | |||
1296 | /******************************************************************************** |
||
1297 | * Components * |
||
1298 | ********************************************************************************/ |
||
1299 | |||
1300 | |||
1301 | /** |
||
1302 | * Paginator factory |
||
1303 | * @return Components\DataGridPaginator\DataGridPaginator |
||
1304 | */ |
||
1305 | public function createComponentPaginator() |
||
1318 | |||
1319 | |||
1320 | /** |
||
1321 | * PerPage form factory |
||
1322 | * @return Form |
||
1323 | */ |
||
1324 | public function createComponentPerPage() |
||
1350 | |||
1351 | |||
1352 | /** |
||
1353 | * FilterAndGroupAction form factory |
||
1354 | * @return Form |
||
1355 | */ |
||
1356 | public function createComponentFilter() |
||
1386 | |||
1387 | |||
1388 | /** |
||
1389 | * Set $this->filter values after filter form submitted |
||
1390 | * @param Form $form |
||
1391 | * @return void |
||
1392 | */ |
||
1393 | public function filterSucceeded(Form $form) |
||
1419 | |||
1420 | |||
1421 | /******************************************************************************** |
||
1422 | * Support functions * |
||
1423 | ********************************************************************************/ |
||
1424 | |||
1425 | |||
1426 | public function resetExportsLinks() |
||
1432 | |||
1433 | |||
1434 | /** |
||
1435 | * Get parameter per_page |
||
1436 | * @return int |
||
1437 | */ |
||
1438 | public function getPerPage() |
||
1448 | |||
1449 | |||
1450 | /** |
||
1451 | * Get associative array of items_per_page_list |
||
1452 | * @return array |
||
1453 | */ |
||
1454 | public function getItemsPerPageList() |
||
1466 | |||
1467 | |||
1468 | /** |
||
1469 | * Get primary key of datagrid data source |
||
1470 | * @return string |
||
1471 | */ |
||
1472 | public function getPrimaryKey() |
||
1476 | |||
1477 | |||
1478 | /** |
||
1479 | * Get set of set columns |
||
1480 | * @return Column\IColumn[] |
||
1481 | */ |
||
1482 | public function getColumns() |
||
1486 | |||
1487 | |||
1488 | /** |
||
1489 | * Has datagrid some group actions? |
||
1490 | * @return boolean |
||
1491 | */ |
||
1492 | public function hasGroupActions() |
||
1496 | |||
1497 | |||
1498 | /** |
||
1499 | * Get translator for datagrid |
||
1500 | * @return Nette\Localization\ITranslator |
||
1501 | */ |
||
1502 | public function getTranslator() |
||
1510 | |||
1511 | |||
1512 | /** |
||
1513 | * Set datagrid translator |
||
1514 | * @param Nette\Localization\ITranslator $translator |
||
1515 | */ |
||
1516 | public function setTranslator(Nette\Localization\ITranslator $translator) |
||
1522 | |||
1523 | |||
1524 | /** |
||
1525 | * Should be datagrid filters rendered separately? |
||
1526 | * @param boolean $out |
||
1527 | */ |
||
1528 | public function setOuterFilterRendering($out = TRUE) |
||
1534 | |||
1535 | |||
1536 | /** |
||
1537 | * Are datagrid filters rendered separately? |
||
1538 | * @return boolean |
||
1539 | */ |
||
1540 | public function hasOuterFilterRendering() |
||
1544 | |||
1545 | |||
1546 | /** |
||
1547 | * Set order of datagrid columns |
||
1548 | * @param array $order |
||
1549 | */ |
||
1550 | public function setColumnsOrder($order) |
||
1568 | |||
1569 | |||
1570 | /** |
||
1571 | * Columns order may be different for export and normal grid |
||
1572 | * @param array $order |
||
1573 | */ |
||
1574 | public function setColumnsExportOrder($order) |
||
1578 | |||
1579 | |||
1580 | /** |
||
1581 | * Should datagrid remember its filters/pagination/etc using session? |
||
1582 | * @param bool $remember |
||
1583 | */ |
||
1584 | public function setRememberState($remember = TRUE) |
||
1590 | |||
1591 | |||
1592 | /** |
||
1593 | * Should datagrid refresh url using history API? |
||
1594 | * @param bool $refresh |
||
1595 | */ |
||
1596 | public function setRefreshUrl($refresh = TRUE) |
||
1603 | |||
1604 | |||
1605 | /** |
||
1606 | * Get session data if functionality is enabled |
||
1607 | * @param string $key |
||
1608 | * @return mixed |
||
1609 | */ |
||
1610 | public function getSessionData($key = NULL) |
||
1618 | |||
1619 | |||
1620 | /** |
||
1621 | * Save session data - just if it is enabled |
||
1622 | * @param string $key |
||
1623 | * @param mixed $value |
||
1624 | * @return void |
||
1625 | */ |
||
1626 | public function saveSessionData($key, $value) |
||
1633 | |||
1634 | |||
1635 | /** |
||
1636 | * Delete session data |
||
1637 | * @return void |
||
1638 | */ |
||
1639 | public function deleteSesssionData($key) |
||
1643 | |||
1644 | |||
1645 | /** |
||
1646 | * Get items detail parameters |
||
1647 | * @return array |
||
1648 | */ |
||
1649 | public function getItemsDetail() |
||
1653 | |||
1654 | |||
1655 | /** |
||
1656 | * Items can have thair detail - toggled |
||
1657 | * @param mixed $detail callable|string|bool |
||
1658 | */ |
||
1659 | public function setItemsDetail($detail = TRUE, $primary_where_column = NULL) |
||
1698 | |||
1699 | |||
1700 | /** |
||
1701 | * Get cont of columns |
||
1702 | * @return int |
||
1703 | */ |
||
1704 | public function getColumnsCount() |
||
1718 | |||
1719 | |||
1720 | public function allowRowsGroupAction(callable $condition) |
||
1724 | |||
1725 | |||
1726 | public function allowRowsAction($key, callable $condition) |
||
1730 | |||
1731 | |||
1732 | public function getRowCondition($name, $key = NULL) |
||
1746 | |||
1747 | } |
||
1748 | |||
1753 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: