Пример #1
0
 public function __set($fieldName, $value)
 {
     // Check if the property is public
     try {
         $R = new \ReflectionClass($this);
         $property = $R->getProperty($fieldName);
     } catch (\ReflectionException $e) {
         // Property doesn't exist, call the stupid parent
         return parent::__set($fieldName, $value);
     }
     if ($property->isPublic()) {
         // Again, call your parents
         return parent::__set($fieldName, $value);
     } else {
         // Property exists, and it's private / protected
         try {
             // Maybe there is a setter for this one?
             $nameArr = explode('_', $fieldName);
             $methodName = 'set';
             foreach ($nameArr as $vv) {
                 $methodName .= ucwords($vv);
             }
             $method = $R->getMethod($methodName);
             // Okay, no exception, let's call it
             return $this->{$methodName}($value);
         } catch (\ReflectionException $up) {
             // Just let it go through
             throw $up;
         }
     }
 }
Пример #2
0
 public function __set($property, $value)
 {
     if (is_object($property) || is_array($property)) {
         return parent::__set($property, $value);
     }
     $this->_dataAccess[$property] = $value;
 }
Пример #3
0
 /**
  * Magic method to use attribute in snake_case
  * For example $ex->a_method = $value is same as $ex->setAMethod($value)
  * @param string $property The property in snake_case
  * @param array $params The value that will be passed to set method
  * @return mixed Call the method if it exists, otherwise call parent __set() method
  */
 public function __set($property, $params)
 {
     $method = 'set' . Phalcon\Text::camelize($property);
     if (method_exists($this, $method)) {
         return $this->{$method}($params);
     }
     parent::__set($property, $params);
 }