protected function parseErrors()
 {
     if ($this->content && isset($this->content->message)) {
         if (isset($this->content->parameters)) {
             $engine = new StringTemplate\Engine(self::LEFT_ERROR_DELIMITER, self::RIGHT_ERROR_DELIMITER);
             $error = $engine->render($this->content->message, (array) $this->content->parameters);
         } else {
             $error = $this->content->message;
         }
         $this->addError($error);
     }
 }
Esempio n. 2
0
 /**
  * Parse data into the target recursively.
  *
  * @param        $target
  * @param  array $data
  * @return mixed
  */
 public function parse($target, array $data = [])
 {
     $data = $this->prepareData($data);
     /*
      * If the target is an array
      * then parse it recursively.
      */
     if (is_array($target)) {
         foreach ($target as $key => &$value) {
             $value = $this->parse($value, $data);
         }
     }
     /*
      * if the target is a string and is in a parsable
      * format then parse the target with the payload.
      */
     if (is_string($target) && str_contains($target, ['{', '}'])) {
         $target = $this->parser->render($target, $data);
     }
     return $target;
 }
 /**
  * Make a route path.
  *
  * @param       $name
  * @param       $entry
  * @param array $parameters
  * @return mixed|null|string
  */
 public function make($name, $entry, array $parameters = [])
 {
     if (!($route = $this->routes->getByName($name))) {
         return null;
     }
     if ($entry instanceof Presenter) {
         $entry = $entry->getObject();
     }
     if ($entry instanceof Arrayable) {
         $entry = $entry->toArray();
     }
     return '/' . $this->addQueryString($this->parser->render($route->uri(), $entry), $parameters);
 }
Esempio n. 4
0
 public function getHttpdConf(ImportEvent $event)
 {
     $httpd = file_get_contents(__DIR__ . '/data/apache.conf.txt');
     $conf = $this->engine->render($httpd, array_merge($this->config->getPublicVars(), ['path' => realpath($this->bootLoader->getBaseDir() . '/public')]));
     $event->setContent(['conf' => $conf]);
 }
Esempio n. 5
0
 public function testRenderWithObjectValues()
 {
     $engine = new Engine();
     $this->assertEquals('foo', $engine->render('{value}', array('value' => new ObjectMock())));
 }
Esempio n. 6
0
 /**
  * Prepare URL for the operation
  * @param ApiVersion $version Version of API used for client
  */
 public function prepare(ApiVersion $version)
 {
     $strSubs = new StringTemplate\Engine();
     $this->setPath($strSubs->render(self::API_URI_FORMAT, ["basepath" => self::BASE_PATH, "version" => $version->getVersion()]));
 }
Esempio n. 7
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;
 }
 public function renderUploadMultiple($previewTemplate, $name, $value = null, $options = [])
 {
     $options = $this->appendClassToOptions('rk-uploader-field', $options);
     $options = $this->appendClassToOptions('rk-uploader-multiple-field', $options);
     $options = $this->appendClassToOptions('hidden', $options);
     $options = $this->provideOptionToHtml('url', $options);
     $options = $this->provideOptionToHtml('type', $options);
     $fileValue = $this->getValueAttribute($name, $value);
     $files = strlen($fileValue) > 0 ? explode(':', $fileValue) : [];
     $previewItemsTemplate = '';
     $templateEngine = new Engine();
     foreach ($files as $file) {
         $previewItemsTemplate .= $templateEngine->render($previewTemplate, ['fileSrc' => $this->fileSrc($file), 'filename' => $file]);
     }
     $template = $this->theme->getUploadMultipleTemplate($previewItemsTemplate);
     $itemTemplate = '<script type="text/x-template" id="rk-item-template">' . $previewTemplate . '</script>';
     return $templateEngine->render($template, ['fileSrc' => $this->fileSrc($fileValue), 'fileField' => $this->file(null, ['multiple'])]) . $this->text($name, $value, $options) . $itemTemplate;
 }
Esempio n. 9
0
 public function readData($replacements)
 {
     return $this->engine->render($this->data, $replacements);
 }
 /**
  * Render a string
  *
  * @param string $template The template content to render
  * @param array $locals The variable to use in template
  * @return string
  */
 public function render($template, array $locals = array())
 {
     return $this->engine->render($template, $locals);
 }