__set() public method

This method will check in the following order and act accordingly: - a property defined by a setter: set the property value - an event in the format of "on xyz": attach the handler to the event "xyz" - a behavior in the format of "as xyz": attach the behavior named as "xyz" - a property of a behavior: set the behavior property value Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $component->property = $value;.
See also: __get()
public __set ( string $name, mixed $value )
$name string the property name or the event name
$value mixed the property value
コード例 #1
0
 public function __set($name, $value)
 {
     if (is_int($name)) {
         $this->{$this->_containerName}[$name] = $value;
     } else {
         parent::__set($name, $value);
     }
 }
コード例 #2
0
ファイル: UniSender.php プロジェクト: omgdef/yii2-unisender
 /**
  * @inheritdoc
  */
 public function __set($name, $value)
 {
     if (property_exists($this->obj, $name)) {
         $this->obj->{$name} = $value;
         return;
     }
     parent::__set($name, $value);
 }
コード例 #3
0
ファイル: Crawler.php プロジェクト: macklus/yii2-crawler
 public function __set($name, $value)
 {
     if (!isset($this->{$name})) {
         $this->{$name} = $value;
         return true;
     } else {
         return parent::__set($name, $value);
     }
 }
コード例 #4
0
ファイル: SmsManager.php プロジェクト: strong2much/yii2-sms
 /**
  * Any requests to set or get attributes or call methods on this class that
  * are not found are redirected to the {@link IService} object.
  * @param string $name the attribute name
  * @param mixed $value the attribute value
  * @return mixed
  * @throws \Exception
  */
 public function __set($name, $value)
 {
     try {
         return parent::__set($name, $value);
     } catch (\Exception $e) {
         if (property_exists($this->_service, $name)) {
             $this->_service->{$name} = $value;
         } else {
             throw $e;
         }
     }
 }
コード例 #5
0
ファイル: Connection.php プロジェクト: yii2ext/redis
 /**
  * Sets value of a component property.
  * Do not call this method. This is a PHP magic method that we override
  * to allow using the following syntax to set a property
  * <pre>
  * $this->propertyName=$value;
  * </pre>
  * @param string $name the property name
  * @param mixed $value the property value
  * @return mixed
  * @throws \yii\base\UnknownPropertyException|\yii\base\InvalidCallException
  *         if the property is not defined or the property is read only.
  * @see __get
  */
 public function __set($name, $value)
 {
     $setter = 'set' . $name;
     if (property_exists($this->getClient(), $name)) {
         return $this->getClient()->{$name} = $value;
     } elseif (method_exists($this->getClient(), $setter)) {
         return $this->getClient()->{$setter}($value);
     }
     return parent::__set($name, $value);
 }
コード例 #6
0
 /**
  * @param string $name
  * @param mixed $value
  * @throws UnknownPropertyException
  */
 public function __set($name, $value)
 {
     $setter = 'set' . $name;
     if (method_exists($this->getZabbixObject(), $setter)) {
         $this->getZabbixObject()->{$setter}($value);
     } elseif (method_exists($this, $setter)) {
         parent::__set($name, $value);
     } elseif (method_exists($this, 'get' . $name)) {
         throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);
     } else {
         throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);
     }
 }