1 | <?php namespace nyx\console\output\formatting\styles; |
||
15 | class Stack |
||
16 | { |
||
17 | /** |
||
18 | * @var interfaces\Style[] The Styles currently being processed. |
||
19 | */ |
||
20 | private $styles = []; |
||
21 | |||
22 | /** |
||
23 | * @var interfaces\Style The default Style used when the Stack is empty. |
||
24 | */ |
||
25 | private $default; |
||
26 | |||
27 | /** |
||
28 | * Constructs a new Output Formatting Styles Stack. |
||
29 | * |
||
30 | * @param interfaces\Style $default The default Style to be used when the Stack is empty. |
||
31 | */ |
||
32 | public function __construct(interfaces\Style $default = null) |
||
36 | |||
37 | /** |
||
38 | * Pushes a style onto the Stack. |
||
39 | * |
||
40 | * @param interfaces\Style $style |
||
41 | * @return $this |
||
42 | */ |
||
43 | public function push(interfaces\Style $style) : Stack |
||
49 | |||
50 | /** |
||
51 | * Pops a style from the Stack. |
||
52 | * |
||
53 | * @param interfaces\Style $searched An optional, specific Style to pop from the Stack. If it is not |
||
54 | * the current element in the Stack, the Stack will be sliced and |
||
55 | * all Styles present after this instance will also be popped off. |
||
56 | * @return interfaces\Style The popped Style. |
||
57 | * @throws \InvalidArgumentException When a Style was given but couldn't be found in the Stack. |
||
58 | */ |
||
59 | public function pop(interfaces\Style $searched = null) : interfaces\Style |
||
85 | |||
86 | /** |
||
87 | * Returns the current, topmost Style in the stack, or the default Style if none is stacked. |
||
88 | * |
||
89 | * @return interfaces\Style |
||
90 | */ |
||
91 | public function current() : interfaces\Style |
||
95 | |||
96 | /** |
||
97 | * Empties the Stack. |
||
98 | * |
||
99 | * @return $this |
||
100 | */ |
||
101 | public function reset() : Stack |
||
107 | |||
108 | /** |
||
109 | * Returns the count of the Styles in the Stack, not taking the default Style into account. |
||
110 | * |
||
111 | * @return int |
||
112 | */ |
||
113 | public function count() : int |
||
117 | |||
118 | /** |
||
119 | * Sets the default Style to be used when the Stack is empty. |
||
120 | * |
||
121 | * @param interfaces\Style $style |
||
122 | * @return $this |
||
123 | */ |
||
124 | public function setDefault(interfaces\Style $style) : Stack |
||
130 | |||
131 | /** |
||
132 | * Returns the default Style used when the Stack is empty. |
||
133 | * |
||
134 | * @return interfaces\Style |
||
135 | */ |
||
136 | public function getDefault() : interfaces\Style |
||
140 | } |
||
141 |