Пример #1
0
 public function __get($name)
 {
     if ($this->hasAttribute($name)) {
         return $this->_attributes[$name];
     } else {
         return parent::__get($name);
     }
 }
Пример #2
0
 /**
  * PHP getter magic method.
  *
  * @param string $name
  *
  * @return mixed
  */
 public function __get($name)
 {
     if (in_array($name, $this->attributeNames())) {
         return $this->getAttribute($name);
     } else {
         return parent::__get($name);
     }
 }
 public function __get($name)
 {
     if (array_key_exists($name, $this->data)) {
         return $this->data[$name];
     } else {
         return parent::__get($name);
     }
 }
Пример #4
0
 public function __get($name)
 {
     if (isset($this->_attributes[$name])) {
         return $this->_attributes[$name];
     } elseif (in_array($name, $this->attributeNames())) {
         return null;
     } else {
         return parent::__get($name);
     }
 }
Пример #5
0
 /**
  * PHP getter magic method.
  * This method is overridden so that MongoDB document can be accessed like properties.
  * @param string property name
  * @return mixed property value
  * @see getAttribute
  */
 public function __get($name)
 {
     if ($name === 'id') {
         return $this->_document['_id'];
     } elseif (array_key_exists($name, $this->_document)) {
         return $this->_document[$name];
     } else {
         return parent::__get($name);
     }
 }
 public function __get($name)
 {
     if (strpos($name, '[')) {
         $basePropertyName = substr($name, 0, strpos($name, '['));
         $index = substr($name, strpos($name, '[') + 1);
         if (property_exists($this, $basePropertyName)) {
             return ArrayUtil::getNestedValue($this->{$basePropertyName}, $index);
         }
     }
     return parent::__get($name);
 }
Пример #7
0
 /**
  * (non-PHPdoc)
  * @see yii/framework/CComponent::__get()
  */
 public function __get($name)
 {
     if (isset($this->_attributes[$name])) {
         return $this->_attributes[$name];
     } elseif (isset($this->_related[$name])) {
         return $this->_related[$name];
     } elseif (array_key_exists($name, $this->relations())) {
         return $this->_related[$name] = $this->getRelated($name);
     } else {
         try {
             return parent::__get($name);
         } catch (CException $e) {
             return null;
         }
     }
 }
Пример #8
0
 /**
  * @see yii/framework/CComponent::__get()
  * @param string $name
  * @return mixed
  */
 public function __get($name)
 {
     if (isset($this->_attributes[$name])) {
         return $this->_attributes[$name];
     }
     if (isset($this->_related[$name])) {
         return $this->_related[$name];
     }
     if (array_key_exists($name, $this->relations())) {
         return $this->_related[$name] = $this->getRelated($name);
     }
     try {
         return parent::__get($name);
     } catch (CException $e) {
         $getter = 'get' . $name;
         if (method_exists($this, $getter)) {
             throw $e;
         } elseif (strncasecmp($name, 'on', 2) === 0 && method_exists($this, $name)) {
             throw $e;
         }
         return null;
     }
 }
Пример #9
0
 /**
  * PHP getter magic method.
  * This method is overridden so that attributes can be accessed like properties.
  * @param string $name property name
  * @return mixed property value
  */
 public function __get($name)
 {
     if (isset($this->_attributes[$name])) {
         return $this->_attributes[$name];
         //   	} else if(isset($this->_related[$name])) {
         //   			return $this->_related[$name];
     } else {
         return parent::__get($name);
     }
 }
Пример #10
0
 /**
  * @since v1.0.8
  */
 public function __get($name)
 {
     if ($this->hasEmbeddedDocuments() && isset(self::$_embeddedConfig[get_class($this)][$name])) {
         // Late creation of embedded documents on first access
         if (is_null($this->_embedded->itemAt($name))) {
             $docClassName = self::$_embeddedConfig[get_class($this)][$name];
             $doc = new $docClassName($this->getScenario());
             $doc->setOwner($this);
             $this->_embedded->add($name, $doc);
         }
         return $this->_embedded->itemAt($name);
     } else {
         return parent::__get($name);
     }
 }
Пример #11
0
 /**
  * PHP getter magic method.
  * This method is overridden so that node/relationship properties can be accessed.
  * @param string $name property name
  * @return mixed property value
  * @see getAttribute
  */
 public function __get($name)
 {
     if (isset($this->_attributes[$name])) {
         return $this->_attributes[$name];
     } else {
         if (isset($this->getMetaData()->properties[$name])) {
             return null;
         } else {
             return parent::__get($name);
         }
     }
 }
Пример #12
0
 /**
  * PHP getter magic method.
  * This method is overridden so that Resource Model attributes can be accessed like properties.
  * @param string $name property name
  * @return mixed property value
  * @see getAttribute
  */
 public function __get($name)
 {
     if (isset($this->_attributes[$name])) {
         return $this->_attributes[$name];
     } elseif ($this->getResourceSchema()->hasAttribute($name)) {
         return null;
     } elseif (isset($this->_linked[$name])) {
         return $this->_linked[$name];
     } elseif (isset($this->_links[$name])) {
         return $this->getLinked($name);
     } else {
         return parent::__get($name);
     }
 }
Пример #13
0
 /**
  * Волшебный геттер
  * @param type $name
  */
 public function __get($name)
 {
     // проверка на наличие маппинга свойства на поле БД
     $mapping = $this->fieldsMapping();
     if (array_key_exists($name, $mapping)) {
         $name = $mapping[$name];
     }
     // проверяем, не обычное ли это поле
     if (array_key_exists($name, $this->getRecord()->getItems())) {
         // обходной маневр для конвертации mysql-дат в отечественные
         $properties = $this->fieldsProperty();
         if (array_key_exists($name, $properties)) {
             $property = $properties[$name];
             if (array_key_exists("type", $property)) {
                 if ($property["type"] == FIELD_MYSQL_DATE) {
                     $value = $this->getRecord()->getItemValue($name);
                     if (strpos($value, "0000-00-00") !== false) {
                         return "";
                     }
                     return date($property["format"], strtotime($value));
                 }
             }
         }
         return $this->getRecord()->getItemValue($name);
     }
     // поле необычное.
     $relations = $this->relations();
     if (array_key_exists($name, $relations)) {
         $relation = $relations[$name];
         // разрешим не указывать
         if (!array_key_exists("storageProperty", $relation)) {
             $relation["storageProperty"] = "_" . $name;
         }
         if ($relation['relationPower'] == RELATION_HAS_ONE) {
             $private = $relation['storageProperty'];
             if (is_null($this->{$private})) {
                 $key_field = $relation['storageField'];
                 $key_value = $this->{$key_field};
                 $useManager = true;
                 if (array_key_exists("targetClass", $relation)) {
                     $targetClass = $relation["targetClass"];
                     $useManager = false;
                 } else {
                     $managerClass = $relation['managerClass'];
                     $managerGetter = $relation['managerGetObject'];
                 }
                 if ($useManager) {
                     $obj = $managerClass::$managerGetter($key_value);
                 } else {
                     $targetClass = "get" . mb_substr($targetClass, 1);
                     $obj = CBaseManager::$targetClass($key_value);
                 }
                 $this->{$private} = $obj;
             }
             return $this->{$private};
         } elseif ($relation['relationPower'] == RELATION_HAS_MANY) {
             $private = $relation['storageProperty'];
             /**
              * Проверим, вдруг разрешено использование кэш
              * и данные кэше уже есть
              */
             $useCache = false;
             if (array_key_exists("useCache", $relation)) {
                 $useCache = $relation["useCache"];
             }
             if ($useCache) {
                 $cacheKey = get_class($this) . "_property_" . $name . "_" . $this->getId();
                 if (CApp::getApp()->cache->hasCache($cacheKey)) {
                     $valueFromCache = CApp::getApp()->cache->get($cacheKey);
                     $this->{$private} = $valueFromCache;
                 }
             }
             if (is_null($this->{$private})) {
                 $table = $relation['storageTable'];
                 $condition = $relation['storageCondition'];
                 $useManager = true;
                 if (array_key_exists("targetClass", $relation)) {
                     $targetClass = $relation["targetClass"];
                     $useManager = false;
                 } else {
                     $managerClass = $relation['managerClass'];
                     $managerGetter = $relation['managerGetObject'];
                 }
                 $managerOrder = null;
                 if (array_key_exists("managerOrder", $relation)) {
                     $managerOrder = $relation['managerOrder'];
                 }
                 $this->{$private} = new CArrayList();
                 foreach (CActiveRecordProvider::getWithCondition($table, $condition, $managerOrder)->getItems() as $item) {
                     if ($useManager) {
                         $obj = $managerClass::$managerGetter($item->getId());
                     } else {
                         $obj = new $targetClass($item);
                     }
                     if (!is_null($obj)) {
                         if (is_object($obj)) {
                             $this->{$private}->add($obj->getId(), $obj);
                         } else {
                             $this->{$private}->add($this->{$private}->getCount(), $obj);
                         }
                     }
                 }
                 if ($useCache) {
                     CApp::getApp()->cache->set($cacheKey, $this->{$private}, 60);
                 }
             }
             return $this->{$private};
         } elseif ($relation['relationPower'] == RELATION_COMPUTED) {
             $private = $relation['storageProperty'];
             if (is_null($this->{$private})) {
                 $function = $relation['relationFunction'];
                 $this->{$private} = $this->{$function}();
             }
             return $this->{$private};
         } elseif ($relation['relationPower'] == RELATION_MANY_TO_MANY) {
             $private = $relation['storageProperty'];
             /**
              * Проверим, вдруг разрешено использование кэш
              * и данные кэше уже есть
              */
             $useCache = false;
             if (array_key_exists("useCache", $relation)) {
                 $useCache = $relation["useCache"];
             }
             if ($useCache) {
                 $cacheKey = get_class($this) . "_property_" . $name . "_" . $this->getId();
                 if (CApp::getApp()->cache->hasCache($cacheKey)) {
                     $valueFromCache = CApp::getApp()->cache->get($cacheKey);
                     $this->{$private} = $valueFromCache;
                 }
             }
             if (is_null($this->{$private})) {
                 $this->{$private} = new CArrayList();
                 $joinTable = $relation["joinTable"];
                 $rightKey = $relation["rightKey"];
                 $leftCondition = $relation["leftCondition"];
                 $useManager = true;
                 if (array_key_exists("targetClass", $relation)) {
                     $useManager = false;
                 } else {
                     $managerClass = $relation["managerClass"];
                     $managerGetter = $relation["managerGetObject"];
                 }
                 foreach (CActiveRecordProvider::getWithCondition($joinTable, $leftCondition)->getItems() as $item) {
                     $items = $item->getItems();
                     if ($useManager) {
                         $obj = $managerClass::$managerGetter($items[$rightKey]);
                     } else {
                         $method = "get" . mb_substr($relation["targetClass"], 1);
                         $obj = CBaseManager::$method($items[$rightKey]);
                     }
                     if (!is_null($obj)) {
                         $this->{$private}->add($obj->id, $obj);
                     }
                 }
                 if ($useCache) {
                     CApp::getApp()->cache->set($cacheKey, $this->{$private}, 60);
                 }
             }
             return $this->{$private};
         }
     }
     return parent::__get($name);
 }
Пример #14
0
 /**
  * PHP getter magic method.
  * This method is overridden so that AR attributes can be accessed like properties.
  * @param string $name property name
  * @return mixed property value
  * @see getAttribute
  */
 public function __get($name)
 {
     if (property_exists($this, $name)) {
         return $this->{$name};
     } else {
         if (isset($this->_attributes[$name])) {
             return $this->_attributes[$name];
         } else {
             if (isset($this->relations[$name])) {
                 return $this->relations[$name];
             } else {
                 if (isset($this->relations()[$name])) {
                     return $this->getRelated($name);
                 } else {
                     return parent::__get($name);
                 }
             }
         }
     }
 }
Пример #15
0
 /**
  * Returns a property value, an event handler list or a behavior based on its name.
  * Do not call this method. This is a PHP magic method that we override
  * to allow using the following syntax to read a property or obtain event handlers:
  * <pre>
  * $value=$component->propertyName;
  * $handlers=$component->eventName;
  * </pre>
  * @param string $name the property name or event name
  * @return mixed the property value, event handlers attached to the event, or the named behavior
  * @throws \CException if the property or event is not defined
  * @see __set
  */
 public function __get($name)
 {
     if (array_key_exists($name, $this->_attributes)) {
         return $this->_attributes[$name];
     } else {
         return parent::__get($name);
     }
 }
Пример #16
0
 /**
  * Returns a property value, an event handler list or a behavior based on its name.
  * 
  * @param string $name the property name or event name
  * 
  * @return mixed the property value, event handlers attached to the event, or the named behavior
  *
  * @throws CException if the property or event is not defined
  */
 public function __get($name)
 {
     try {
         return parent::__get($name);
     } catch (Exception $e) {
         if ($this->_lastEvent instanceof CEvent && $this->_lastEvent->canGetProperty($name)) {
             return $this->_lastEvent->{$name};
         } else {
             throw $e;
         }
     }
 }
Пример #17
0
 public function __get($name)
 {
     if (isset($this->_attributes[$name])) {
         return $this->_attributes[$name];
     } elseif (isset($this->getMetaData()->columns[$name])) {
         return null;
     } elseif (isset($this->_related[$name])) {
         return $this->_related[$name];
     } elseif (isset($this->getMetaData()->relations[$name])) {
         return $this->getRelated($name);
     } else {
         return parent::__get($name);
     }
 }
Пример #18
0
 public function __get($name)
 {
     if (isset($this->_attributes[$name])) {
         return isset($this->_values[$name]) ? $this->_values[$name] : '';
     } else {
         return parent::__get($name);
     }
 }