mirror of
https://github.com/PhyreApps/PhyrePanel.git
synced 2024-11-25 09:00:27 +00:00
39 lines
949 B
PHP
39 lines
949 B
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Support\Facades\Blade;
|
|
|
|
class PhyreBlade
|
|
{
|
|
public static function render($file, $data = [])
|
|
{
|
|
$namespace = '';
|
|
if (strpos($file, '::') !== false) {
|
|
[$namespace, $file] = explode('::', $file);
|
|
}
|
|
|
|
$file = str_replace('.', '/', $file);
|
|
// Replace last / with .
|
|
$file = preg_replace('/\/([^\/]*)$/', '.$1', $file);
|
|
|
|
$hints = app()->view->getFinder()->getHints();
|
|
if (isset($hints[$namespace])) {
|
|
$path = $hints[$namespace][0] . '/' . $file;
|
|
} else {
|
|
$viewsPath = app()->view->getFinder()->getPaths()[0];
|
|
$path = $viewsPath . '/' . $file;
|
|
}
|
|
|
|
if (!is_file($path)) {
|
|
throw new \Exception('File not found: ' . $path);
|
|
}
|
|
|
|
$content = file_get_contents($path);
|
|
|
|
$compiled = Blade::render($content, $data);
|
|
|
|
return $compiled;
|
|
|
|
}
|
|
}
|