Created
September 19, 2012 21:10
-
-
Save arnaud-lb/3752280 to your computer and use it in GitHub Desktop.
Twig REPL
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
<?php | |
/** | |
* Twig REPL hack | |
* | |
* Arnaud Le Blanc <[email protected]> | |
*/ | |
require 'lib/Twig/Autoloader.php'; | |
Twig_Autoloader::register(); | |
$loader = new Twig_Loader_Array(array()); | |
$env = new Twig_Environment($loader); | |
$lineno = 0; | |
echo "$ "; | |
while (!feof(STDIN) && false !== $code = fgets(STDIN)) { | |
try { | |
$code = sprintf("{{ %s }}", trim($code)); | |
$loader->setTemplate('command line code', $code); | |
$env->display('command line code'); | |
echo "\n"; | |
} catch (Exception $e) { | |
printf("Error executing %s:\n", $code); | |
printf("%s: %s\n", get_class($e), $e->getMessage()); | |
} | |
echo "$ "; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: