Prado\TComponent::__set PHP Метод

__set() публичный Метод

Do not call this method. This is a PHP magic method that we override to allow using the following syntax to set a property or attach an event handler. $this->PropertyName=$value; $this->jsPropertyName=$value; // $value will be treated as a JavaScript literal $this->EventName=$handler; $this->fxEventName=$handler; //global event listener When behaviors are enabled, this will also set a behaviors properties and events.
public __set ( $name, $value )
    public function __set($name, $value)
    {
        if (method_exists($this, $setter = 'set' . $name)) {
            if (strncasecmp($name, 'js', 2) === 0 && $value && !$value instanceof TJavaScriptLiteral) {
                $value = new TJavaScriptLiteral($value);
            }
            return $this->{$setter}($value);
        } else {
            if (method_exists($this, $jssetter = 'setjs' . $name)) {
                if ($value && !$value instanceof TJavaScriptString) {
                    $value = new TJavaScriptString($value);
                }
                return $this->{$jssetter}($value);
            } else {
                if (strncasecmp($name, 'on', 2) === 0 && method_exists($this, $name) || strncasecmp($name, 'fx', 2) === 0) {
                    return $this->attachEventHandler($name, $value);
                } else {
                    if ($this->_m !== null && $this->_m->getCount() > 0 && $this->_behaviorsenabled) {
                        $sets = 0;
                        foreach ($this->_m->toArray() as $behavior) {
                            if ((!$behavior instanceof IBehavior || $behavior->getEnabled()) && (property_exists($behavior, $name) || $behavior->canSetProperty($name) || $behavior->hasEvent($name))) {
                                $behavior->{$name} = $value;
                                $sets++;
                            }
                        }
                        if ($sets) {
                            return $value;
                        }
                    }
                }
            }
        }
        if (method_exists($this, 'get' . $name) || method_exists($this, 'getjs' . $name)) {
            throw new TInvalidOperationException('component_property_readonly', get_class($this), $name);
        } else {
            throw new TInvalidOperationException('component_property_undefined', get_class($this), $name);
        }
    }

Usage Example

Пример #1
0
 /**
  * Magic method for writing properties.
  * This method is overriden to provide write access to the foreign objects via
  * the key names declared in the RELATIONS array.
  * @param string property name
  * @param mixed property value.
  * @since 3.1.2
  */
 public function __set($name, $value)
 {
     if ($this->hasRecordRelation($name) && !$this->canSetProperty($name)) {
         $this->{$name} = $value;
     } else {
         parent::__set($name, $value);
     }
 }