コード例 #1
0
 /**
  * When accessing a property of a decorated entry
  * object first check to see if the key represents
  * a streams field. If it does then return the field
  * type's presenter object. Otherwise handle normally.
  *
  * @param  $key
  * @return mixed
  */
 public function __get($key)
 {
     if ($assignment = $this->object->getAssignment($key)) {
         $type = $assignment->getFieldType();
         if ($assignment->isTranslatable() && ($locale = config('app.locale'))) {
             $entry = $this->object->translateOrDefault($locale);
             $type->setLocale($locale);
         } else {
             $entry = $this->object;
         }
         $type->setEntry($entry);
         if (method_exists($type, 'getRelation')) {
             return $type->decorate($entry->getRelationValue(camel_case($key)));
         }
         $type->setValue($entry->getFieldValue($key));
         return $type->getPresenter();
     }
     return $this->__getDecorator()->decorate(parent::__get($key));
 }