Class luya\cms\base\BlockCfg
Inheritance | luya\cms\base\BlockCfg » luya\cms\base\BlockConfigElement |
---|---|
Available since version | 1.0.0 |
Source Code | https://github.com/luyadev/luya-module-cms/blob/master/src/base/BlockCfg.php |
Block CFG variables ensurence.
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() | luya\cms\base\BlockCfg |
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 |
Method Details
Defined in: luya\cms\base\BlockConfigElement::__construct()
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());
}
Defined in: luya\cms\base\BlockConfigElement::get()
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];
}
Defined in: luya\cms\base\BlockConfigElement::has()
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;
}
public void toArray ( ) |
public function toArray()
{
return [
'id' => $this->id,
'var' => $this->item['var'],
'label' => $this->item['label'],
'type' => $this->item['type'],
'placeholder' => $this->get('placeholder'),
'options' => $this->get('options'),
'initvalue' => $this->get('initvalue'),
'required' => $this->get('required', 0),
];
}