¨4.0.1¨
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace Modules\Setting;
|
||||
|
||||
use ArrayAccess;
|
||||
use Illuminate\Support\Collection;
|
||||
use Modules\Setting\Entities\Setting;
|
||||
|
||||
class Repository implements ArrayAccess
|
||||
@@ -10,20 +11,22 @@ class Repository implements ArrayAccess
|
||||
/**
|
||||
* Collection of all settings.
|
||||
*
|
||||
* @var \Illuminate\Support\Collection
|
||||
* @var Collection
|
||||
*/
|
||||
private $settings;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new repository instance.
|
||||
*
|
||||
* @param \Illuminate\Support\Collection $settings
|
||||
* @param Collection $settings
|
||||
*/
|
||||
public function __construct($settings)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all settings.
|
||||
*
|
||||
@@ -34,33 +37,12 @@ class Repository implements ArrayAccess
|
||||
return $this->settings->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting for the given key.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key, $default = null)
|
||||
{
|
||||
return $this->settings->get($key) ?: $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the given settings.
|
||||
*
|
||||
* @param array $settings
|
||||
* @return void
|
||||
*/
|
||||
public function set($settings = [])
|
||||
{
|
||||
Setting::setMany($settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if an setting is exists.
|
||||
* Determine if a setting is exists.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function offsetExists($key)
|
||||
@@ -68,44 +50,25 @@ class Repository implements ArrayAccess
|
||||
return $this->settings->has($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting for the given key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function offsetGet($key)
|
||||
{
|
||||
return $this->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a key / value setting pair.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet($key, $value)
|
||||
{
|
||||
$this->set([$key => $value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset a setting by the given key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return \Illuminate\Support\Collection
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function offsetUnset($key)
|
||||
{
|
||||
return $this->settings->forget($key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get setting for the given key.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($key)
|
||||
@@ -113,15 +76,71 @@ class Repository implements ArrayAccess
|
||||
return $this->offsetGet($key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set a key / value setting pair.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __set($key, $value)
|
||||
{
|
||||
$this->offsetSet($key, $value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get setting for the given key.
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function offsetGet($key)
|
||||
{
|
||||
return $this->get($key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get setting for the given key.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key, $default = null)
|
||||
{
|
||||
return $this->settings->get($key) ?: $default;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set a key / value setting pair.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet($key, $value)
|
||||
{
|
||||
$this->set([$key => $value]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the given settings.
|
||||
*
|
||||
* @param array $settings
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set($settings = [])
|
||||
{
|
||||
Setting::setMany($settings);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user