Skip to content

Instantly share code, notes, and snippets.

@iedmrc
Created August 16, 2017 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iedmrc/17bbcb9bbee04b96fdb6d104fe04bbf9 to your computer and use it in GitHub Desktop.
Save iedmrc/17bbcb9bbee04b96fdb6d104fe04bbf9 to your computer and use it in GitHub Desktop.
Compile blade template string to (bare) php
/**
* Compile blade template string to (bare) php
* @param $value
* @param array $args
* @return string
* @throws \Exception
*/
public static function bladeCompile($value, array $args = array())
{
$generated = \Blade::compileString($value);
ob_start() and extract($args, EXTR_SKIP);
// We'll include the view contents for parsing within a catcher
// so we can avoid any WSOD errors. If an exception occurs we
// will throw it out to the exception handler.
try
{
eval('?>'.$generated);
}
// If we caught an exception, we'll silently flush the output
// buffer so that no partially rendered views get thrown out
// to the client and confuse the user with junk.
catch (\Exception $e)
{
ob_get_clean(); throw $e;
}
$content = ob_get_clean();
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment