Exemple #1
0
 /**
  * Should not by called directly
  * @param string $name
  * @param mixed $value
  * @return void
  */
 public function __set($name, $value)
 {
     //name starts with underscore -> no magic functionality
     if (\strpos($name, '_') === 0) {
         $_name = \substr($name, 1);
     } else {
         $_name = FALSE;
     }
     //primary key
     if ($name == 'id' || $name == $this->_reflection->primaryKey || $name == $this->_reflection->getPrimaryKeyColumn()) {
         $this->_setId($value);
         return;
     }
     //parents
     if (isset($this->_reflection->parents[$name])) {
         if ($value === NULL || \is_object($value) && $value instanceof $this->_reflection->parents[$name]) {
             $this->_parents[$name] = $value;
             return;
         }
         throw new Exception("Property {$name} must be entity of class " . $this->_reflection->parents[$name]);
     }
     //singles
     if (isset($this->_reflection->singles[$name])) {
         if ($value === NULL || \is_object($value) && $value instanceof $this->_reflection->singles[$name]) {
             $this->_singles[$name] = $value;
             return;
         }
         throw new Exception("Property {$name} must be entity of class " . $this->_reflection->singles[$name]);
     }
     //children
     if (isset($this->_reflection->children[$name])) {
         if ($value === NULL || \is_object($value) && $value instanceof \IDataSource) {
             $this->_children[$name] = $value;
             return;
         }
         throw new Exception("Property {$name} must implement interface IDataSource.");
     }
     /***** values *****/
     if ($_name && isset($this->_reflection->columns[$_name]) && !isset($this->_reflection->parents[$_name])) {
         return $this->_setValue($this->_reflection->columns[$_name], $value);
     }
     if (\method_exists($this, $m_name = Helpers::setter($name))) {
         //set{Name}
         return $this->{$m_name}($value);
     }
     if (isset($this->_reflection->columns[$name]) && !isset($this->_reflection->parents[$name])) {
         return $this->_setValue($this->_reflection->columns[$name], $value);
     }
     //inheritance
     if ($this->_reflection->isExtendingEntity()) {
         $this->_parents[self::EXTENDED]->{$name} = $value;
         return;
     }
     $class = \get_called_class();
     throw new Exception("Undeclared property {$class}->{$name}.");
 }