|
2 | 2 |
|
3 | 3 | namespace Whitecube\LaravelFlexibleContent;
|
4 | 4 |
|
5 |
| -use Whitecube\LaravelFlexibleContent\Contracts\Layout as LayoutInterface; |
| 5 | +use ArrayAccess; |
6 | 6 | use Illuminate\Support\Str;
|
7 | 7 | use Illuminate\Database\Eloquent\Concerns\HasAttributes;
|
| 8 | +use Illuminate\Database\Eloquent\Concerns\HidesAttributes; |
| 9 | +use Whitecube\LaravelFlexibleContent\Contracts\Layout as LayoutInterface; |
8 | 10 |
|
9 |
| -class Layout implements LayoutInterface |
| 11 | +class Layout implements LayoutInterface, ArrayAccess |
10 | 12 | {
|
11 | 13 | use HasAttributes;
|
| 14 | + use HidesAttributes; |
12 | 15 |
|
13 | 16 | /**
|
14 | 17 | * A short unique name for this Layout, usually used by front-end components
|
@@ -134,4 +137,124 @@ public function make(?string $id = null, array $attributes = []) : LayoutInterfa
|
134 | 137 | ->attributes($attributes, true)
|
135 | 138 | ->limit($this->limit);
|
136 | 139 | }
|
| 140 | + |
| 141 | + /** |
| 142 | + * Get the value indicating whether the IDs are incrementing (they are not since this is not a model). |
| 143 | + * |
| 144 | + * @return bool |
| 145 | + */ |
| 146 | + public function getIncrementing() |
| 147 | + { |
| 148 | + return false; |
| 149 | + } |
| 150 | + |
| 151 | + /** |
| 152 | + * Determine if the layout uses timestamps (it doesn't since this is not a model). |
| 153 | + * |
| 154 | + * @return bool |
| 155 | + */ |
| 156 | + public function usesTimestamps() |
| 157 | + { |
| 158 | + return false; |
| 159 | + } |
| 160 | + |
| 161 | + /** |
| 162 | + * Check if relation exists (it doesn't since this is not a model). |
| 163 | + * |
| 164 | + * @return bool |
| 165 | + */ |
| 166 | + protected function relationLoaded() |
| 167 | + { |
| 168 | + return false; |
| 169 | + } |
| 170 | + |
| 171 | + /** |
| 172 | + * Dynamically retrieve attributes on the layout. |
| 173 | + * |
| 174 | + * @param string $attribute |
| 175 | + * @return mixed |
| 176 | + */ |
| 177 | + public function __get($attribute) |
| 178 | + { |
| 179 | + return $this->getAttribute($attribute); |
| 180 | + } |
| 181 | + |
| 182 | + /** |
| 183 | + * Dynamically set attributes on the layout. |
| 184 | + * |
| 185 | + * @param string $attribute |
| 186 | + * @param mixed $value |
| 187 | + * @return void |
| 188 | + */ |
| 189 | + public function __set($attribute, $value) |
| 190 | + { |
| 191 | + $this->setAttribute($attribute, $value); |
| 192 | + } |
| 193 | + |
| 194 | + /** |
| 195 | + * Determine if an attribute exists on the layout. |
| 196 | + * |
| 197 | + * @param string $attribute |
| 198 | + * @return bool |
| 199 | + */ |
| 200 | + public function __isset($attribute) |
| 201 | + { |
| 202 | + return $this->offsetExists($attribute); |
| 203 | + } |
| 204 | + |
| 205 | + /** |
| 206 | + * Unset an attribute on the layout. |
| 207 | + * |
| 208 | + * @param string $attribute |
| 209 | + * @return void |
| 210 | + */ |
| 211 | + public function __unset($attribute) |
| 212 | + { |
| 213 | + $this->offsetUnset($attribute); |
| 214 | + } |
| 215 | + |
| 216 | + /** |
| 217 | + * Determine if the given attribute exists. |
| 218 | + * |
| 219 | + * @param mixed $attribute |
| 220 | + * @return bool |
| 221 | + */ |
| 222 | + public function offsetExists($attribute) |
| 223 | + { |
| 224 | + return ! is_null($this->getAttribute($attribute)); |
| 225 | + } |
| 226 | + |
| 227 | + /** |
| 228 | + * Get the value for a given offset. |
| 229 | + * |
| 230 | + * @param mixed $attribute |
| 231 | + * @return mixed |
| 232 | + */ |
| 233 | + public function offsetGet($attribute) |
| 234 | + { |
| 235 | + return $this->getAttribute($attribute); |
| 236 | + } |
| 237 | + |
| 238 | + /** |
| 239 | + * Set the value for a given offset. |
| 240 | + * |
| 241 | + * @param mixed $attribute |
| 242 | + * @param mixed $value |
| 243 | + * @return void |
| 244 | + */ |
| 245 | + public function offsetSet($attribute, $value) |
| 246 | + { |
| 247 | + $this->setAttribute($attribute, $value); |
| 248 | + } |
| 249 | + |
| 250 | + /** |
| 251 | + * Unset the value for a given offset. |
| 252 | + * |
| 253 | + * @param mixed $attribute |
| 254 | + * @return void |
| 255 | + */ |
| 256 | + public function offsetUnset($attribute) |
| 257 | + { |
| 258 | + unset($this->attributes[$attribute]); |
| 259 | + } |
137 | 260 | }
|
0 commit comments