Class luya\cms\base\BlockCfg

Inheritanceluya\cms\base\BlockCfg » luya\cms\base\BlockConfigElement
Available since version1.0.0
Source Code https://github.com/luyadev/luya-module-cms/blob/master/src/base/BlockCfg.php

Block CFG variables ensurence.

Public Properties

Hide inherited properties

Property Type Description Defined By
$item luya\cms\base\BlockConfigElement

Protected Properties

Hide inherited properties

Property Type Description Defined By
$id luya\cms\base\BlockConfigElement

Protected Methods

Hide inherited 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

Hide inherited methods

__construct() public method
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() protected method

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];
}

            
has() protected method

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;
}

            
toArray() public method

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),
    ];
}