32 lines
900 B
PHP
32 lines
900 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Support;
|
|
|
|
function base_path(string $path = ''): string
|
|
{
|
|
return dirname(__DIR__, 2) . ($path === '' ? '' : '/' . ltrim($path, '/'));
|
|
}
|
|
|
|
function storage_path(string $path = ''): string
|
|
{
|
|
return base_path('storage' . ($path === '' ? '' : '/' . ltrim($path, '/')));
|
|
}
|
|
|
|
function e(string|int $value): string
|
|
{
|
|
return htmlspecialchars((string) $value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
|
}
|
|
|
|
/** Render within an isolated scope so data cannot overwrite the template path. */
|
|
function view(string $name, array $data = []): void
|
|
{
|
|
if (!preg_match('/^[a-zA-Z0-9_-]+$/D', $name)) {
|
|
throw new \InvalidArgumentException('Invalid view name.');
|
|
}
|
|
(static function (string $__file, array $__data): void {
|
|
extract($__data, EXTR_SKIP);
|
|
require $__file;
|
|
})(base_path('resources/views/' . $name . '.php'), $data);
|
|
}
|