Created
August 16, 2017 07:46
-
-
Save iedmrc/17bbcb9bbee04b96fdb6d104fe04bbf9 to your computer and use it in GitHub Desktop.
Compile blade template string to (bare) php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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