implement ArrayAccess interface for plugins

This commit is contained in:
printempw 2016-12-24 23:06:56 +08:00
parent 043dabaccf
commit 33b89db7f5

View File

@ -2,6 +2,7 @@
namespace App\Services; namespace App\Services;
use ArrayAccess;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Illuminate\Contracts\Support\Arrayable; use Illuminate\Contracts\Support\Arrayable;
@ -12,7 +13,7 @@ use Illuminate\Contracts\Support\Arrayable;
* @property string $title * @property string $title
* @property array $author * @property array $author
*/ */
class Plugin implements Arrayable class Plugin implements Arrayable, ArrayAccess
{ {
/** /**
* The directory of this plugin. * The directory of this plugin.
@ -182,6 +183,51 @@ class Plugin implements Arrayable
return $this->path; 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. * Generates an array result for the object.
* *