Ejemplo n.º 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});
         }
     }
 }
Ejemplo n.º 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 . ')';
             });
         }
     }
 }
Ejemplo n.º 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') ?>");
     });
 }
Ejemplo n.º 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\'); ?>');
 }
Ejemplo n.º 5
0
 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;
 }