/** * 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); }
/** * {@inheritdoc} */ public function offsetGet($offset) { return $this->variables->fetch($offset); }