add(static::wantHtml($el)); } return $html; } else { // TODO: Should we add a dedicated Exception class? throw new IcingaException( 'String, Html Element or Array of such expected, got "%s"', Html::getPhpTypeName($any) ); } } public static function canBeRenderedAsString($any) { return is_string($any) || is_int($any) || is_null($any) || is_float($any); } /** * @param $any * @return string */ public static function getPhpTypeName($any) { if (is_object($any)) { return get_class($any); } else { return gettype($any); } } /** * @param $name * @param $arguments * @return HtmlElement */ public static function __callStatic($name, $arguments) { $attributes = array_shift($arguments); $content = null; if ($attributes instanceof ValidHtml || is_string($attributes)) { $content = $attributes; $attributes = null; } elseif (is_array($attributes)) { if (empty($attributes)) { $attributes = null; } elseif (is_int(key($attributes))) { $content = $attributes; $attributes = null; } } if (!empty($arguments)) { if (null === $content) { $content = $arguments; } else { $content = [$content, $arguments]; } } return HtmlElement::create($name, $attributes, $content); } /** * @param Exception|string $error * @return string */ public static function renderError($error) { if ($error instanceof Exception) { $file = preg_split('/[\/\\\]/', $error->getFile(), -1, PREG_SPLIT_NO_EMPTY); $file = array_pop($file); $msg = sprintf( '%s (%s:%d)', $error->getMessage(), $file, $error->getLine() ); } elseif (is_string($error)) { $msg = $error; } else { $msg = 'Got an invalid error'; // TODO: translate? } $output = sprintf( // TODO: translate? Be careful when doing so, it must be failsafe! "
%s\n", static::escapeForHtml($msg) ); if (static::showTraces()) { $output .= sprintf( "
%s\n", static::escapeForHtml($error->getTraceAsString()) ); } $output .= "