1 | <?php |
||
18 | class Priority |
||
19 | { |
||
20 | /** |
||
21 | * An array containing all the entities added |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $_all_general = array(); |
||
25 | |||
26 | /** |
||
27 | * An array containing all the entities that should go *after* another one |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $_all_after = array(); |
||
31 | |||
32 | /** |
||
33 | * An array containing all the entities that should go *before* another one |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $_all_before = array(); |
||
37 | |||
38 | /** |
||
39 | * An array containing all the entities that should go at the end of the list |
||
40 | * @var array |
||
41 | */ |
||
42 | protected $_all_end = array(); |
||
43 | |||
44 | /** |
||
45 | * An array containing all the entities that should go at the beginning |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $_all_begin = array(); |
||
49 | |||
50 | /** |
||
51 | * The highest priority assigned at a certain moment for $_all_general |
||
52 | * @var int |
||
53 | */ |
||
54 | protected $_general_highest_priority = 0; |
||
55 | |||
56 | /** |
||
57 | * The highest priority assigned at a certain moment for $_all_end |
||
58 | * @var int |
||
59 | */ |
||
60 | protected $_end_highest_priority = 10000; |
||
61 | |||
62 | /** |
||
63 | * The highest priority assigned at a certain moment for $_all_begin |
||
64 | * Highest priority at "begin" is sort of tricky, because the value is negative |
||
65 | * @var int |
||
66 | */ |
||
67 | protected $_begin_highest_priority = -10000; |
||
68 | |||
69 | /** |
||
70 | * Array of sorted entities |
||
71 | * @var array |
||
72 | */ |
||
73 | protected $_sorted_entities = null; |
||
74 | |||
75 | /** |
||
76 | * Default priority |
||
77 | */ |
||
78 | const STDPRIORITY = 0; |
||
79 | |||
80 | /** |
||
81 | * Add a new entity to the pile |
||
82 | * |
||
83 | * @param string $entity name of a entity |
||
84 | * @param int|null $priority an integer defining the priority of the entity. |
||
85 | */ |
||
86 | 11 | public function add($entity, $priority = null) |
|
93 | |||
94 | /** |
||
95 | * Add an entity to the pile before another existing entity |
||
96 | * |
||
97 | * @param string $entity the name of a entity |
||
98 | * @param string $following the name of the entity before which $entity must be added |
||
99 | */ |
||
100 | public function addBefore($entity, $following) |
||
104 | |||
105 | /** |
||
106 | * Add a entity to the pile after another existing entity |
||
107 | * |
||
108 | * @param string $entity the name of a entity |
||
109 | * @param string $previous the name of the entity after which $entity must be added |
||
110 | */ |
||
111 | public function addAfter($entity, $previous) |
||
115 | |||
116 | /** |
||
117 | * Add a entity at the end of the pile |
||
118 | * |
||
119 | * @param string $entity name of a entity |
||
120 | * @param int|null $priority an integer defining the priority of the entity. |
||
121 | */ |
||
122 | public function addEnd($entity, $priority = null) |
||
129 | |||
130 | /** |
||
131 | * Add a entity at the beginning of the pile |
||
132 | * |
||
133 | * @param string $entity name of a entity |
||
134 | * @param int|null $priority an integer defining the priority of the entity. |
||
135 | */ |
||
136 | 7 | public function addBegin($entity, $priority = null) |
|
143 | |||
144 | /** |
||
145 | * Remove a entity by name |
||
146 | * |
||
147 | * @param string $entity the name of a entity |
||
148 | */ |
||
149 | 5 | public function remove($entity) |
|
172 | |||
173 | /** |
||
174 | * Remove all the entities added up to the moment the function is called |
||
175 | */ |
||
176 | public function removeAll() |
||
187 | |||
188 | /** |
||
189 | * The function sorts the entities according to the priority and saves the |
||
190 | * result in $_sorted_entities |
||
191 | * |
||
192 | * @return array the sorted entities with priority |
||
193 | */ |
||
194 | 4 | public function sort() |
|
279 | |||
280 | /** |
||
281 | * Check if at least one entity has been added |
||
282 | * |
||
283 | * @return bool true if at least one entity has been added |
||
284 | * @todo at that moment _all_after and _all_before are not considered because they may not be "forced" |
||
285 | */ |
||
286 | 4 | public function hasEntities() |
|
297 | |||
298 | /** |
||
299 | * Return the entities that have been loaded |
||
300 | */ |
||
301 | public function getEntities() |
||
305 | |||
306 | /** |
||
307 | * Return the entities that have been loaded |
||
308 | */ |
||
309 | 3 | public function getSortedEntities() |
|
313 | } |
||
314 |