예제 #1
0
 /**
  * undocumented function
  *
  * @param   Compiler
  * @return  void
  **/
 public function __construct(Compiler $compiler)
 {
     $this->compiler = $compiler;
     foreach ($this->functions as $volt => $func) {
         if (is_string($func)) {
             $compiler->addFunction($volt, $func);
         } else {
             $compiler->addFunction($volt, $this->{$func});
         }
     }
 }
예제 #2
0
 /**
  * @param VoltCompiler $compiler
  */
 public static function install($compiler)
 {
     foreach (get_class_methods(get_called_class()) as $method) {
         if ($method != __METHOD__) {
             $compiler->addFunction(Text::uncamelize($method), function ($resolvedArgs, $exprArgs) use($method) {
                 return get_called_class() . '::' . $method . '(' . $resolvedArgs . ')';
             });
         }
     }
 }
예제 #3
0
 public function testVoltUsersFunctions()
 {
     $this->specify("Custom functions should work", function () {
         $volt = new Compiler();
         //Single string function
         $volt->addFunction('random', 'mt_rand');
         //Function with closure
         $volt->addFunction('shuffle', function ($arguments, $exprArguments) {
             return 'str_shuffle(' . $arguments . ')';
         });
         $volt->addFunction('strtotime', 'strtotime');
         $compilation = $volt->compileString('{{ random() }}');
         expect($compilation)->equals('<?= mt_rand() ?>');
         $compilation = $volt->compileString('{{ shuffle("hello") }}');
         expect($compilation)->equals('<?= str_shuffle(\'hello\') ?>');
         $compilation = $volt->compileString('{{ strtotime("now") }}');
         expect($compilation)->equals("<?= strtotime('now') ?>");
     });
 }
예제 #4
0
 public function testVoltUsersFunctions()
 {
     $volt = new Compiler();
     //Single string function
     $volt->addFunction('random', 'mt_rand');
     //Function with closure
     $volt->addFunction('shuffle', function ($arguments, $exprArguments) {
         return 'str_shuffle(' . $arguments . ')';
     });
     $compilation = $volt->compileString('{{ random() }}');
     $this->assertEquals($compilation, '<?php echo mt_rand(); ?>');
     $compilation = $volt->compileString('{{ shuffle("hello") }}');
     $this->assertEquals($compilation, '<?php echo str_shuffle(\'hello\'); ?>');
 }
예제 #5
0
파일: Engine.php 프로젝트: skullab/area51
 public function getVoltCompiler()
 {
     $volt = new VoltCompiler();
     $volt->setOptions(array('stat' => true, 'compileAlways' => true));
     require CORE_PATH . 'config/volt.functions.php';
     foreach ($voltFunctions as $macro => $function) {
         $volt->addFunction($macro, $function);
     }
     return $volt;
 }