Changeset 9076

Show
Ignore:
Timestamp:
12/20/05 16:07:14 (3 years ago)
Author:
jlz
Message:

Hack to support the traditional style variable context rules.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/sandbox/mrfc0022/midgard_style_engine.php

    r9075 r9076  
    126126} 
    127127 
     128class traditional_midgard_style_engine extends standard_midgard_style_engine { 
     129 
     130    function traditional_midgard_style_engine(&$context) { 
     131        $this->standard_midgard_style_engine($context); 
     132    }   
     133 
     134        function compile($element) { 
     135                $prefix = ""; 
     136                $variables = array(); 
     137        $tokens = token_get_all($element); 
     138        foreach ($tokens as $token) { 
     139                if (is_array($token) && $token[0] == T_VARIABLE 
     140                    && substr($token[1], 0, 2) != '$_') { 
     141                            $variables[$token[1]] = 1; 
     142                } 
     143        } 
     144        foreach ($variables as $variable => $foo) { 
     145                $prefix .="global $variable;"; 
     146        } 
     147        return $prefix . parent::compile($element); 
     148        } 
     149 
     150} 
     151 
    128152?> 
  • trunk/src/sandbox/mrfc0022/midgard_style_engine_test.php

    r9075 r9076  
    9090} 
    9191 
     92class traditional_midgard_style_engine_test extends PHPUnit_TestCase { 
     93 
     94        var $engine; 
     95 
     96    function traditional_midgard_style_engine_context_test($name) { 
     97        $this->PHPUnit_TestCase($name); 
     98    } 
     99 
     100    function setUp() { 
     101        $elements = array( 
     102            "test" => "<(init)><(print)><(increment)><(print)>", 
     103            "init" => "<?php \$x = 0; ?>", 
     104            "print" => "<?php echo \$x; ?>", 
     105            "increment" => "<?php \$x += 1; ?>" 
     106        ); 
     107        $context =& new simple_midgard_style_context($elements); 
     108        $this->engine =& new traditional_midgard_style_engine($context); 
     109    } 
     110 
     111    function tearDown() { 
     112        unset($this->engine); 
     113    } 
     114 
     115    function try_render($element) { 
     116        ob_start(); 
     117                $this->engine->render($element); 
     118        return ob_get_clean(); 
     119    } 
     120 
     121        function test_render() { 
     122                $this->assertEquals("01", $this->try_render("<(test)>")); 
     123        } 
     124 
     125} 
     126 
    92127?> 
  • trunk/src/sandbox/mrfc0022/runtests.php

    r9071 r9076  
    2929$suite->addTestSuite("chained_midgard_style_context_test"); 
    3030$suite->addTestSuite("standard_midgard_style_engine_test"); 
     31$suite->addTestSuite("traditional_midgard_style_engine_test"); 
    3132$result = PHPUnit::run($suite); 
    3233