Abstract Class luya\cms\base\BlockConfigElement
Inheritance | luya\cms\base\BlockConfigElement |
---|---|
Subclasses | luya\cms\base\BlockCfg, luya\cms\base\BlockVar |
Available since version | 1.0.0 |
Source Code | https://github.com/luyadev/luya-module-cms/blob/master/src/base/BlockConfigElement.php |
Config Element abstraction.
In order to make sure all config() elements has same values, this class implement check routines for
- {{\luya\cms\base\BlockCfg}}
- {{\luya\cms\base\BlockVar}}
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$item | luya\cms\base\BlockConfigElement |
Protected Properties
Property | Type | Description | Defined By |
---|---|---|---|
$id | luya\cms\base\BlockConfigElement |
Public Methods
Method | Description | Defined By |
---|---|---|
__construct() | luya\cms\base\BlockConfigElement | |
toArray() | Extract the data from the element. | luya\cms\base\BlockConfigElement |
Protected Methods
Method | Description | Defined By |
---|---|---|
get() | Get the element value. | luya\cms\base\BlockConfigElement |
has() | Has the config element an element or not. | luya\cms\base\BlockConfigElement |
Property Details
Method Details
public void __construct ( array $item ) | ||
$item | array |
The element config with all fields. |
throws | Exception |
---|
public function __construct(array $item)
{
$this->item = $item;
if (!$this->has(['var', 'label', 'type'])) {
throw new Exception('Required attributes in config var element is missing. var, label and type are required.');
}
$this->id = md5($this->get('var').uniqid());
}
Get the element value.
protected string get ( $key, $default = null ) | ||
$key | string | |
$default | mixed |
protected function get($key, $default = null)
{
if (!$this->has($key)) {
return $default;
}
return $this->item[$key];
}
Has the config element an element or not.
protected boolean has ( $key ) | ||
$key | string |
protected function has($key)
{
if (!is_array($key)) {
return (array_key_exists($key, $this->item));
}
foreach ($key as $value) {
if (!array_key_exists($value, $this->item)) {
return false;
}
}
return true;
}