Contao\Widget::__set PHP Method

__set() public method

Set an object property
public __set ( string $strKey, mixed $varValue )
$strKey string The property name
$varValue mixed The property value
    public function __set($strKey, $varValue)
    {
        switch ($strKey) {
            case 'id':
                $this->strId = $varValue;
                break;
            case 'name':
                $this->strName = $varValue;
                break;
            case 'label':
                $this->strLabel = $varValue;
                break;
            case 'value':
                $this->varValue = \StringUtil::deserialize($varValue);
                // Decrypt the value if it is encrypted
                if ($this->arrConfiguration['encrypt']) {
                    $this->varValue = \Encryption::decrypt($this->varValue);
                }
                break;
            case 'class':
                if ($varValue != '' && strpos($this->strClass, $varValue) === false) {
                    $this->strClass = trim($this->strClass . ' ' . $varValue);
                }
                break;
            case 'prefix':
                $this->strPrefix = $varValue;
                break;
            case 'template':
                $this->strTemplate = $varValue;
                break;
            case 'wizard':
                $this->strWizard = $varValue;
                break;
            case 'autocomplete':
            case 'autocorrect':
            case 'autocapitalize':
            case 'spellcheck':
                if (is_bool($varValue)) {
                    $varValue = $varValue ? 'on' : 'off';
                }
                // Do not add a break; statement here
            // Do not add a break; statement here
            case 'alt':
            case 'style':
            case 'accesskey':
            case 'onblur':
            case 'onchange':
            case 'onclick':
            case 'ondblclick':
            case 'onfocus':
            case 'onmousedown':
            case 'onmousemove':
            case 'onmouseout':
            case 'onmouseover':
            case 'onmouseup':
            case 'onkeydown':
            case 'onkeypress':
            case 'onkeyup':
            case 'onselect':
                $this->arrAttributes[$strKey] = $varValue;
                break;
            case 'tabindex':
                if ($varValue > 0) {
                    $this->arrAttributes['tabindex'] = $varValue;
                }
                break;
            case 'disabled':
            case 'readonly':
                $this->blnSubmitInput = $varValue ? false : true;
                // Do not add a break; statement here
            // Do not add a break; statement here
            case 'autofocus':
                if ($varValue) {
                    $this->arrAttributes[$strKey] = $strKey;
                } else {
                    unset($this->arrAttributes[$strKey]);
                }
                break;
            case 'required':
                if ($varValue) {
                    $this->strClass = trim($this->strClass . ' mandatory');
                }
                // Do not add a break; statement here
            // Do not add a break; statement here
            case 'mandatory':
            case 'nospace':
            case 'allowHtml':
            case 'storeFile':
            case 'useHomeDir':
            case 'storeValues':
            case 'trailingSlash':
            case 'spaceToUnderscore':
            case 'doNotTrim':
                $this->arrConfiguration[$strKey] = $varValue ? true : false;
                break;
            case 'forAttribute':
                $this->blnForAttribute = $varValue;
                break;
            case 'dataContainer':
                $this->objDca = $varValue;
                break;
            case strncmp($strKey, 'ng-', 3) === 0:
            case strncmp($strKey, 'data-', 5) === 0:
                $this->arrAttributes[$strKey] = $varValue;
                break;
            default:
                $this->arrConfiguration[$strKey] = $varValue;
                break;
        }
    }

Usage Example

Example #1
0
 /**
  * Add specific attributes
  *
  * @param string $strKey
  * @param mixed  $varValue
  */
 public function __set($strKey, $varValue)
 {
     switch ($strKey) {
         case 'options':
             $this->arrOptions = \StringUtil::deserialize($varValue);
             break;
         default:
             parent::__set($strKey, $varValue);
             break;
     }
 }
All Usage Examples Of Contao\Widget::__set