__get() public method

Dynamically retrieve attributes on the model.
public __get ( string $key ) : mixed
$key string
return mixed
Beispiel #1
0
 public function __get($key)
 {
     if ($this->isEloquent()) {
         return $this->data->__get($key);
     }
     return object_get($this->data, $key);
 }
Beispiel #2
0
 /**
  * Magic method to return the meta data like the post original fields
  * 
  * @param string $key
  * @return string
  */
 public function __get($key)
 {
     if (!isset($this->{$key})) {
         return $this->meta->{$key};
     }
     return parent::__get($key);
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function __get($key)
 {
     if (array_key_exists($key, $this->aliases)) {
         $key = $this->aliases[$key];
     }
     return parent::__get($key);
 }
 public function __get($key)
 {
     if (in_array($key, $this->translatable)) {
         return $this->getTranslatable($key);
     }
     return parent::__get($key);
 }
Beispiel #5
0
 /**
  * A hack to allow avatar_url to be called on the result of Auth::user().
  *
  * @param  string $key The variable to get
  * @return mixed
  */
 public function __get($key)
 {
     if ($key === 'avatar_url') {
         return $this->getPresenter()->avatar_url;
     }
     return parent::__get($key);
 }
Beispiel #6
0
 public function __get($key)
 {
     // Получить армию.
     if ($key == 'army') {
         return $this->castle ? $this->castle->army : null;
     }
     return parent::__get($key);
 }
 public function __get($key)
 {
     if (array_key_exists($key, $this->personableAliases)) {
         return $this->{$this->personableAliases[$key]};
     } else {
         return parent::__get($key);
     }
 }
Beispiel #8
0
 public function __get($key)
 {
     $columns = $this->getTableColumns();
     if (array_key_exists($key, $this->attributes) || $this->hasGetMutator($key) || $this->relationLoaded($key) || method_exists($this, $key) || in_array($key, $columns)) {
         return parent::__get($key);
     }
     return $this->getMeta($key);
 }
 public function __get($name)
 {
     switch ($name) {
         case 'fullname':
             return "{$this->name} {$this->last_name}";
             break;
     }
     return parent::__get($name);
 }
 public function __get($key)
 {
     if ($key == 'email') {
         if ($this->employee != null) {
             return $this->employee->email;
         } else {
             return $this->getAttribute('email');
         }
     } else {
         return parent::__get($key);
     }
 }
 public function __get($key)
 {
     if ($key == 'imageURL') {
         return '/images/page/' . $this->page->id . '/' . $this->id . '.png';
     } else {
         if ($key == 'thumbURL') {
             return '/images/page/' . $this->page->id . '/' . $this->id . '.thumbnail.png';
         } else {
             return parent::__get($key);
         }
     }
 }
 public function __get($key)
 {
     if ($key == 'imageURL') {
         return '/images/slider/' . $this->slider->id . '/' . $this->id . '.png';
     } else {
         if ($key == 'thumbURL') {
             return '/images/slider/' . $this->slider->id . '/' . $this->id . '.thumbnail.png';
         } else {
             if ($key == 'height') {
                 return $this->image->height;
             } else {
                 return parent::__get($key);
             }
         }
     }
 }
 /**
  * Give the user access to the translated fields from the main model.
  *
  * @param string $key
  * @return mixed|null
  */
 public function __get($key)
 {
     if (!in_array($key, $this->translatable)) {
         return parent::__get($key);
     }
     return !empty($this->translations->first()) ? $this->translations->first()->getAttribute($key) : null;
 }
Beispiel #14
0
 public function __get($key)
 {
     try {
         $class = get_class($this);
         if (isset($class::$relationsData) && array_key_exists($key, $class::$relationsData)) {
             if (!isset($this->relations[$key])) {
                 $relations = $this->{$key}();
                 $this->relations[$key] = $relations->getResults();
             }
             return $this->relations[$key];
         }
         return parent::__get($key);
     } catch (NullMorphException $e) {
         return null;
     }
 }
Beispiel #15
0
 public function __get($name)
 {
     if (preg_match('/pretty_(\\w+_at)/', $name, $matches)) {
         $field = $matches[1];
         $timestamp = $this->{$field};
         if ($timestamp and is_a($timestamp, \Carbon\Carbon::class)) {
             return $timestamp->format('Y-m-d H:i');
         }
     }
     return parent::__get($name);
 }
Beispiel #16
0
 public function __get($key)
 {
     // Получить состояние отряда...
     if ($key == 'state') {
         $now = Carbon::now();
         $end = $this->crusade_end_at;
         // конец похода
         $start = $this->crusade_at;
         // начало похода
         $battle = $this->battle_at;
         // время битвы
         $crusade = isset($start) && isset($battle) && $start->lt($battle);
         // поход существует?
         if ($crusade && isset($end) && $now->lt($end)) {
             $state = 'comeback';
         } elseif ($crusade && !isset($end) && $now->gte($battle)) {
             $state = 'assault';
         } elseif ($crusade && !isset($end) && $now->lt($battle) && $now->gte($start)) {
             $state = 'crusade';
         } else {
             $state = 'idle';
         }
         return $state;
     }
     // Получить подробное человеческое описание состояния отряда...
     if ($key == 'hstate') {
         $state = $this->state;
         switch ($state) {
             case 'comeback':
                 $hstate = "Вернется из похода {$this->crusade_end_at->format('d.m.Y H:i')}";
                 break;
             case 'assault':
                 $hstate = 'Штурмует вражеский замок';
                 break;
             case 'crusade':
                 $hstate = "В походе на {$this->goal->name}. Сражение {$this->battle_at->format('d.m.Y H:i')}";
                 break;
             default:
                 $hstate = 'Бездействует';
         }
         return $hstate;
     }
     // Получить пользователя.
     if ($key == 'user') {
         return $this->army ? $this->army->castle ? $this->army->castle->user : null : null;
     }
     return parent::__get($key);
 }
 public function __get($key)
 {
     if ($this->hasHook($hook = 'get_' . $key)) {
         return $this->call($hook, []);
     }
     return parent::__get($key);
 }
 public function __get($key)
 {
     if ($this->hasHook($key)) {
         return $this->call($key, []);
     }
     return parent::__get($key);
     // TODO: Change the autogenerated stub
 }
Beispiel #19
0
 /**
  * Override getter so we can fetch metadata from properties.
  * @param string $key
  * @return mixed
  */
 public function __get($key)
 {
     $value = parent::__get($key);
     // Get identifier for the resource model.
     //        if ($key == 'identifier' && is_null($value)) {
     //            $resourceModel = $this->getResourceModel();
     //            if ($resourceModel && $resourceModel instanceof AdminModel) {
     //                return $resourceModel->getIdentifier();
     //            }
     //        }
     // If we don't have a value try to find it in metadata
     if (is_null($value) && $key != 'meta') {
         if (isset($this->meta[$key])) {
             $value = $this->meta[$key];
         }
     }
     return $value;
 }
Beispiel #20
0
 /**
  * Get a localized attribute
  *
  * @param string $key The attribute
  *
  * @return mixed
  */
 public function __get($key)
 {
     // If the relation has been loaded already, return it
     if (array_key_exists($key, $this->relations)) {
         return $this->relations[$key];
     }
     // If the model supports the locale, load and return it
     if (in_array($key, $this->getAvailable())) {
         $relation = $this->hasOne($this->getLangClass())->whereLang($key);
         if ($relation->getResults() === null) {
             $relation = $this->hasOne($this->getLangClass())->whereLang(Config::get('polyglot::fallback'));
         }
         return $this->relations[$key] = $relation->getResults();
     }
     // If the attribute is set to be automatically localized
     if ($this->polyglot) {
         if (in_array($key, $this->polyglot)) {
             /**
              * If query executed with join and a property is already there
              */
             if (isset($this->attributes[$key])) {
                 return $this->attributes[$key];
             }
             $lang = Lang::getLocale();
             return $this->{$lang} ? $this->{$lang}->{$key} : null;
         }
     }
     return parent::__get($key);
 }
Beispiel #21
0
 /**
  * Magic getter!
  *
  * @param string $key
  * @return int|mixed
  */
 public function __get($key)
 {
     // Получить размер всех отрядов армии...
     if ($key == 'sizeOfSquads') {
         $size = 0;
         foreach ($this->squads()->getResults() as $s) {
             $size += $s->size;
         }
         return $size;
     }
     // Получить силу армии...
     if ($key == 'strength') {
         return $this->size + $this->sizeOfSquads;
     }
     // Получить пользователя.
     if ($key == 'user') {
         return $this->castle ? $this->castle->user : null;
     }
     return parent::__get($key);
 }
Beispiel #22
0
 public function __get($key)
 {
     //pkdebug("KEY", $key);
     # This seems pretty obvious - why don't Eloquent do it?
     if (!$key) {
         return null;
     }
     $name = removeEndStr($key, static::$displayValueSuffix);
     if ($name && in_array($name, static::getDisplayValueFields(), 1)) {
         return $this->displayValue($name);
     }
     if (in_array($key, static::getMethodsAsAttributeNames(), true)) {
         return $this->{$key}();
     }
     //if ($name) pkdebug("Name: [$name] valfields",static::getDisplayValueFields());
     return parent::__get($key);
 }
Beispiel #23
0
 public function __get($key)
 {
     if ($this->present()) {
         if ($this->present()->has($key)) {
             return $this->present()->{$key};
         }
     }
     return parent::__get($key);
 }
Beispiel #24
0
 /**
  * Mustard uses camel case for class properties, and snake case for
  * database columns.
  *
  * @param string $property
  *
  * @return mixed
  */
 public function __get($property)
 {
     return parent::__get(snake_case($property));
 }
 /**
  * Return model's attribute
  * @param $method (eg. 'getId')
  * @return mixed
  */
 protected function get($method)
 {
     $key = $this->match(lcfirst(substr($method, 3)));
     return $this->model->__get($key);
 }
Beispiel #26
0
 /**
  * Dynamically retrieve attributes.
  *
  * @param  string $key
  * @return mixed
  */
 public function __get($key)
 {
     // Resolve relationship dynamically
     if ($relationship = $this->getDynamicRelationship($key)) {
         return $relationship;
     }
     // Dynamically retrieve the encryptable attribute
     $value = $this->getDynamicEncrypted($key);
     if (is_null($value) || !is_string($value)) {
         // Fallback to the default Eloquent dynamic getter
         $value = parent::__get($key);
     }
     // Dynamically juggle the attribute.
     // This is always called so that even decrypted values
     // can be casted after decrypting.
     return $this->getDynamicJuggle($key, $value);
 }