Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
namespace App\Services;
use App\Contracts\IConferenceService;
use Symfony\Component\Debug\Exception\FatalThrowableError;
class CustomViewCompiler
{
public function getBladeResult($name, $bladeContents, array $data = [], $flushCache = false)
{
$viewPath = storage_path('custom_views/' . $name . '.php');
if($flushCache || !file_exists($viewPath))
{
$dirname = dirname($viewPath);
if(!file_exists($dirname)) {
mkdir($dirname, 0777, true);
}
file_put_contents($viewPath, \Blade::compileString($bladeContents));
}
$data['currentEvent'] = $this->event;
return $this->getIncludeResult($viewPath, $data);
}
private function getIncludeResult($file, array $data)
{
$obLevel = ob_get_level();
ob_start();
try {
extract($data, EXTR_SKIP);
include $file;
}
catch (\Exception $e)
{
while (ob_get_level() > $obLevel)
{
ob_end_clean();
}
throw $e;
}
catch (\Throwable $e)
{
while (ob_get_level() > $obLevel)
{
ob_end_clean();
}
throw new FatalThrowableError($e);
}
return ob_get_clean();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.