| @@ 83-106 (lines=24) @@ | ||
| 80 | * |
|
| 81 | * @return $this |
|
| 82 | */ |
|
| 83 | public function push(string $name, $pushValue) |
|
| 84 | { |
|
| 85 | if (! is_array($pushValue)) { |
|
| 86 | $pushValue = [$pushValue]; |
|
| 87 | } |
|
| 88 | ||
| 89 | if (! $this->has($name)) { |
|
| 90 | $this->put($name, $pushValue); |
|
| 91 | ||
| 92 | return $this; |
|
| 93 | } |
|
| 94 | ||
| 95 | $oldValue = $this->get($name); |
|
| 96 | ||
| 97 | if (! is_array($oldValue)) { |
|
| 98 | $oldValue = [$oldValue]; |
|
| 99 | } |
|
| 100 | ||
| 101 | $newValue = array_merge($oldValue, $pushValue); |
|
| 102 | ||
| 103 | $this->put($name, $newValue); |
|
| 104 | ||
| 105 | return $this; |
|
| 106 | } |
|
| 107 | ||
| 108 | /** |
|
| 109 | * Prepend a new value in an array. |
|
| @@ 116-139 (lines=24) @@ | ||
| 113 | * |
|
| 114 | * @return $this |
|
| 115 | */ |
|
| 116 | public function prepend(string $name, $prependValue) |
|
| 117 | { |
|
| 118 | if (! is_array($prependValue)) { |
|
| 119 | $prependValue = [$prependValue]; |
|
| 120 | } |
|
| 121 | ||
| 122 | if (! $this->has($name)) { |
|
| 123 | $this->put($name, $prependValue); |
|
| 124 | ||
| 125 | return $this; |
|
| 126 | } |
|
| 127 | ||
| 128 | $oldValue = $this->get($name); |
|
| 129 | ||
| 130 | if (! is_array($oldValue)) { |
|
| 131 | $oldValue = [$oldValue]; |
|
| 132 | } |
|
| 133 | ||
| 134 | $newValue = array_merge($prependValue, $oldValue); |
|
| 135 | ||
| 136 | $this->put($name, $newValue); |
|
| 137 | ||
| 138 | return $this; |
|
| 139 | } |
|
| 140 | ||
| 141 | /** |
|
| 142 | * Get a value from the store. |
|