Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | n/a |
0 / 0 |
|
0.00% |
0 / 13 |
CRAP | |
0.00% |
0 / 103 |
|
| helpers | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 14 |
|||
| esc | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 6 |
|||
| normalize_whitespaces | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| is_cli | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 3 |
|||
| view | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| current_url | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| current_route | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| route_url | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 12 |
|||
| lang | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 3 |
|||
| cache | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| session | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| old | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 6 |
|||
| url_title | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 17 |
|||
| <?php | |
| if ( ! function_exists('helpers')) { | |
| /** | |
| * Loads helper files. | |
| * | |
| * @param array|string $helper | |
| * | |
| * @return array A list of all loaded files | |
| */ | |
| function helpers($helper) : array | |
| { | |
| if (is_array($helper)) { | |
| $files = []; | |
| foreach ($helper as $item) { | |
| $files[] = helpers($item); | |
| } | |
| return array_merge(...$files); | |
| } | |
| $files = App::locator()->findFiles("Helpers/{$helper}"); | |
| foreach ($files as $file) { | |
| require_once $file; | |
| } | |
| return $files; | |
| } | |
| } | |
| if ( ! function_exists('esc')) { | |
| /** | |
| * Escape special characters to HTML entities. | |
| * | |
| * @param string|null $text The text to be escaped | |
| * @param string $encoding | |
| * | |
| * @return string The escaped text | |
| */ | |
| function esc(?string $text, string $encoding = 'UTF-8') : string | |
| { | |
| $text = (string) $text; | |
| return empty($text) | |
| ? $text | |
| : htmlspecialchars($text, \ENT_QUOTES | \ENT_HTML5, $encoding); | |
| } | |
| } | |
| if ( ! function_exists('normalize_whitespaces')) { | |
| function normalize_whitespaces(string $string) : string | |
| { | |
| return trim(preg_replace('/\s+/', ' ', $string)); | |
| } | |
| } | |
| if ( ! function_exists('is_cli')) { | |
| /** | |
| * Indicates if the current request is a command line request. | |
| * | |
| * @return bool TRUE if is a CLI request, otherwise FALSE | |
| */ | |
| function is_cli() : bool | |
| { | |
| return \PHP_SAPI === 'cli' || defined('STDIN'); | |
| } | |
| } | |
| if ( ! function_exists('view')) { | |
| /** | |
| * Renders a view. | |
| * | |
| * @param string $path View path | |
| * @param array $data Data passed to the view | |
| * @param string $instance | |
| * | |
| * @return string The rendered view contents | |
| */ | |
| function view(string $path, array $data = [], string $instance = 'default') : string | |
| { | |
| return App::view($instance)->render($path, $data); | |
| } | |
| } | |
| if ( ! function_exists('current_url')) { | |
| function current_url() : string | |
| { | |
| return App::request()->getURL(); | |
| } | |
| } | |
| if ( ! function_exists('current_route')) { | |
| function current_route() : Framework\Routing\Route | |
| { | |
| return App::router()->getMatchedRoute(); | |
| } | |
| } | |
| if ( ! function_exists('route_url')) { | |
| function route_url(string $name, array $path_params = [], array $origin_params = []) : string | |
| { | |
| $route = App::router()->getNamedRoute($name); | |
| if ($route === null) { | |
| throw new OutOfBoundsException("Named route not found: {$name}"); | |
| } | |
| if (empty($origin_params) | |
| && $route->getOrigin() === App::router()->getMatchedRoute()->getOrigin() | |
| ) { | |
| $origin_params = App::router()->getMatchedOriginParams(); | |
| } | |
| return $route->getURL($origin_params, $path_params); | |
| } | |
| } | |
| if ( ! function_exists('lang')) { | |
| function lang(string $line, $args = [], string $locale = null) : ?string | |
| { | |
| return App::language()->lang($line, $args, $locale); | |
| } | |
| } | |
| if ( ! function_exists('cache')) { | |
| function cache(string $instance = 'default') : Framework\Cache\Cache | |
| { | |
| return App::cache($instance); | |
| } | |
| } | |
| if ( ! function_exists('session')) { | |
| function session() : Framework\Session\Session | |
| { | |
| return App::session(); | |
| } | |
| } | |
| if ( ! function_exists('old')) { | |
| function old(string $key = null, bool $escape = true) | |
| { | |
| session(); | |
| return $escape | |
| ? esc(App::request()->getRedirectData($key)) | |
| : App::request()->getRedirectData($key); | |
| } | |
| } | |
| function url_title(string $str, string $separator = '-', bool $lowercase = false) : string | |
| { | |
| $q_separator = preg_quote($separator, '#'); | |
| $trans = [ | |
| '&.+?;' => '', | |
| '[^\w\d _-]' => '', | |
| '\s+' => $separator, | |
| '(' . $q_separator . ')+' => $separator, | |
| ]; | |
| $str = strip_tags($str); | |
| foreach ($trans as $key => $val) { | |
| // $str = preg_replace('#'.$key.'#i'.( UTF8_ENABLED ? 'u' : ''), $val, $str); | |
| $str = preg_replace('#' . $key . '#iu', $val, $str); | |
| } | |
| if ($lowercase === true) { | |
| $str = mb_strtolower($str); | |
| } | |
| return trim(trim($str, $separator)); | |
| } |