decorate() 공개 메소드

* If this variable implements Robbo\Presenter\PresentableInterface then turn it into a presenter.
public decorate ( $value )
$value
예제 #1
0
 /**
  * Get the value.
  *
  * @return string
  */
 public function getValue()
 {
     $object = $this->decorator->decorate($this->entry);
     if ($object instanceof FilePresenter) {
         return $object->readableSize();
     }
 }
예제 #2
0
 /**
  * Handle the event.
  *
  * @param ViewComposed $event
  */
 public function handle(ViewComposed $event)
 {
     $view = $event->getView();
     if ($data = array_merge($view->getFactory()->getShared(), $view->getData())) {
         foreach ($data as $key => $value) {
             $view[$key] = $this->decorator->decorate($value);
         }
     }
 }
 /**
  * Handle the command.
  *
  * @param Decorator $decorator
  * @return LinkCollection
  */
 public function handle(Decorator $decorator)
 {
     $links = $this->group->getLinks();
     $this->dispatch(new SetCurrentLink($links));
     $this->dispatch(new SetActiveLinks($links));
     return $decorator->decorate($links);
 }
예제 #4
0
 /**
  * Handle the command.
  *
  * @param  Decorator $decorator
  * @param  Parser    $parser
  * @return array
  */
 public function handle(Decorator $decorator, Parser $parser)
 {
     $data = [];
     $data['form'] = $this->builder->getFormPresenter();
     $data['fields'] = $decorator->decorate($this->builder->getFormFields());
     $data['subject'] = $parser->parse($this->builder->getOption('subject', 'Contact Request'), $this->builder->getFormValues()->all());
     return $data;
 }
예제 #5
0
 public function testPresentablesToPresenters()
 {
     $from = array('string' => 'string', 'array' => array('test' => 'test'), 'presentable' => new PresentableStub(), 'recurseMe' => array(array('presentable' => new PresentableStub())), 'collection' => new Collection(array('presentable' => new PresentableStub())));
     $decorator = new Decorator();
     $to = $decorator->decorate($from);
     $this->assertSame($from['string'], $to['string']);
     $this->assertSame($from['array'], $to['array']);
     $this->assertInstanceOf('Robbo\\Presenter\\Presenter', $to['presentable']);
     $this->assertInstanceOf('Robbo\\Presenter\\Presenter', $to['presentable']->presentableObject);
     $this->assertInstanceOf('Robbo\\Presenter\\Presenter', $to['presentable']->getPresentableObject());
     $this->assertInstanceOf('Robbo\\Presenter\\Presenter', $to['recurseMe'][0]['presentable']);
     $this->assertInstanceOf('Robbo\\Presenter\\Presenter', $to['collection']['presentable']);
 }
예제 #6
0
 /**
  * Return the item value.
  *
  * @param  TreeBuilder     $builder
  * @param                  $entry
  * @return View|mixed|null
  */
 public function make(TreeBuilder $builder, $entry)
 {
     $value = $builder->getTreeOption('item_value', 'entry.title');
     /*
      * If the entry is an instance of EntryInterface
      * then try getting the field value from the entry.
      */
     if ($entry instanceof EntryInterface && $entry->getField($value)) {
         if ($entry->assignmentIsRelationship($value)) {
             $value = $entry->{camel_case($value)}->getTitle();
         } else {
             $value = $entry->getFieldValue($value);
         }
     }
     /*
      * If the value matches a field with a relation
      * then parse the string using the eager loaded entry.
      */
     if (preg_match("/^entry.([a-zA-Z\\_]+)/", $value, $match)) {
         $fieldSlug = camel_case($match[1]);
         if (method_exists($entry, $fieldSlug) && $entry->{$fieldSlug}() instanceof Relation) {
             $entry = $this->decorator->decorate($entry);
             $value = data_get(compact('entry'), str_replace("entry.{$match[1]}.", 'entry.' . camel_case($match[1]) . '.', $value));
         }
     }
     /*
      * Decorate the entry object before
      * sending to decorate so that data_get()
      * can get into the presenter methods.
      */
     $entry = $this->decorator->decorate($entry);
     /*
      * If the value matches a method in the presenter.
      */
     if (preg_match("/^entry.([a-zA-Z\\_]+)/", $value, $match)) {
         if (method_exists($entry, camel_case($match[1]))) {
             $value = $entry->{camel_case($match[1])}();
         }
     }
     /*
      * By default we can just pass the value through
      * the evaluator utility and be done with it.
      */
     $value = $this->evaluator->evaluate($value, compact('builder', 'entry'));
     /*
      * Lastly, prepare the entry to be
      * parsed into the string.
      */
     if ($entry instanceof Arrayable) {
         $entry = $entry->toArray();
     } else {
         $entry = null;
     }
     /*
      * Parse the value with the entry.
      */
     $value = $this->parser->render($builder->getTreeOption('item_wrapper', '{value}'), compact('value', 'entry'));
     /*
      * If the value looks like a language
      * key then try translating it.
      */
     if (str_is('*.*.*::*', $value)) {
         $value = trans($value);
     }
     return $value;
 }
예제 #7
0
 /**
  * Get the value.
  *
  * @return string
  */
 public function getValue()
 {
     /* @var EntryPresenter $object */
     $object = $this->decorator->decorate($this->entry);
     return $object->viewLink();
 }
 /**
  * Create a new VariableRepository instance.
  *
  * @param VariableModel $model
  * @param Decorator     $decorator
  */
 public function __construct(VariableModel $model, Decorator $decorator)
 {
     $this->model = $decorator->decorate($model->firstOrNew([]));
 }
예제 #9
0
 /**
  * Decorate an object with a presenter.
  *
  * @param  mixed $value
  * @return mixed
  */
 public function decorate($value)
 {
     return $this->presenterDecorator->decorate($value);
 }