Last active
August 29, 2015 13:56
-
-
Save anton000/9063757 to your computer and use it in GitHub Desktop.
PHP v8js based hoganjs pre compiler
This file contains hidden or 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 | |
V8Js::registerExtension('hogan-compiler.js',file_get_contents('hogan-2.0.0.js'),array(),false); | |
class HoganCompiler extends V8Js | |
{ | |
public $template; | |
private $expose; | |
private $result; | |
private static $__instance = NULL; | |
public function __construct(){ | |
parent::__construct('myobj',array(), array('hogan-compiler.js')); | |
$this->expose = $this; //expose object to v8 | |
} | |
public function setResult($result){ | |
$this->result = $result; | |
} | |
public function compile(){ | |
$this->executeString('myobj.expose.setResult(Hogan.compile(myobj.template,{ asString: 1 }));'); | |
//echo $this->executeString('var_dump(this)'); | |
return $this->result; | |
} | |
public static function getInstance(){ | |
if(self::$__instance == NULL) self::$__instance = new HoganCompiler(); | |
return self::$__instance; | |
} | |
public function __clone() | |
{ | |
trigger_error('Clone is not allowed.', E_USER_ERROR); | |
} | |
public function __wakeup() | |
{ | |
trigger_error('Unserializing is not allowed.', E_USER_ERROR); | |
} | |
} | |
$hogan = HoganCompiler::getInstance(); | |
$hogan->template = "Hello {{world}} Test!"; | |
echo $hogan->compile(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment