Abstract Class luya\cms\base\BlockConfigElement

Inheritanceluya\cms\base\BlockConfigElement
Subclassesluya\cms\base\BlockCfg, luya\cms\base\BlockVar
Available since version1.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

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

Public Methods

Hide inherited methods

Method Description Defined By
__construct() luya\cms\base\BlockConfigElement
toArray() Extract the data from the element. 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

Property Details

Hide inherited properties

$id protected property
protected $id null
$item public property
public $item = []

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

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

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 abstract method

Extract the data from the element.

public abstract array toArray ( )

                abstract public function toArray();