From 33b89db7f5d14c9b9f20e036c7ddacebf12645e3 Mon Sep 17 00:00:00 2001 From: printempw Date: Sat, 24 Dec 2016 23:06:56 +0800 Subject: [PATCH] implement ArrayAccess interface for plugins --- app/Services/Plugin.php | 48 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/app/Services/Plugin.php b/app/Services/Plugin.php index 5b5abe51..886415e0 100644 --- a/app/Services/Plugin.php +++ b/app/Services/Plugin.php @@ -2,6 +2,7 @@ namespace App\Services; +use ArrayAccess; use Illuminate\Support\Arr; use Illuminate\Support\Str; use Illuminate\Contracts\Support\Arrayable; @@ -12,7 +13,7 @@ use Illuminate\Contracts\Support\Arrayable; * @property string $title * @property array $author */ -class Plugin implements Arrayable +class Plugin implements Arrayable, ArrayAccess { /** * The directory of this plugin. @@ -182,6 +183,51 @@ class Plugin implements Arrayable return $this->path; } + /** + * Determine if the given option option exists. + * + * @param string $key + * @return bool + */ + public function offsetExists($key) + { + return Arr::has($this->packageInfo, $key); + } + + /** + * Get a option option. + * + * @param string $key + * @return mixed + */ + public function offsetGet($key) + { + return $this->packageInfoAttribute($key); + } + + /** + * Set a option option. + * + * @param string $key + * @param mixed $value + * @return void + */ + public function offsetSet($key, $value) + { + return Arr::set($this->packageInfo, $key, $value); + } + + /** + * Unset a option option. + * + * @param string $key + * @return void + */ + public function offsetUnset($key) + { + unset($this->packageInfo[$key]); + } + /** * Generates an array result for the object. *