Beispiel #1
0
 /**
  * Renders the specified template file.
  *
  * @param string $file
  * @param array  $variables
  * @param array  $attributes
  *
  * @return string
  * @throws renderer\buckets\exceptions\StrictVariableException
  * @throws renderer\buckets\exceptions\VariableWriteException
  */
 public function render(string $file, array $variables = [], array $attributes = []) : string
 {
     foreach ($variables as $key => $value) {
         $this->variables->add($key, $value);
     }
     foreach ($attributes as $key => $value) {
         $this->attributes->add($key, $value);
     }
     return $this->engine->render($file, $this->sections, $this->variables, $this->attributes);
 }
Beispiel #2
0
 /**
  * Outputs a variable that can be converted into a string to the
  * template. If the variable value is equal to NULL.
  *
  * @param string $key
  * @param string $filters
  * @param string $default
  *
  * @return string
  * @throws buckets\exceptions\UndefinedVariableException
  */
 public function out(string $key, string $filters = '', string $default = '') : string
 {
     $value = $this->variables->fetch($key, false);
     if ($value === null) {
         return $default;
     }
     if (!is_string($value) && !is_numeric($value) && !(is_object($value) && !method_exists($value, '__toString'))) {
         throw new \UnexpectedValueException("Variable '{$key}' cannot be converted into a string.");
     }
     if (strlen($filters) > 0) {
         $value = $this->filter($value, $filters);
     }
     return $this->escape($value, Escaper::CONTEXT_HTML);
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function offsetGet($offset)
 {
     return $this->variables->fetch($offset);
 }