Author: Raymond Bosman Date: 2006-10-03 16:50:58 +0200 (Tue, 03 Oct 2006) New Revision: 3623
Log: - Cache to a hardcoded directory. The cache component is not used due to the overhead. - Dynamic blocks works for a bit. Modified: trunk/Template/src/parsers/ast_to_ast/implementations/ast_walker.php trunk/Template/src/parsers/ast_to_ast/implementations/cache.php trunk/Template/src/parsers/source_to_tst/implementations/cache.php trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_transformer.php trunk/Template/src/symbol_table.php trunk/Template/src/syntax_trees/ast/nodes/nop.php trunk/Template/src/syntax_trees/tst/nodes/cache.php trunk/Template/src/template.php trunk/Template/tests/regression_test.php Modified: trunk/Template/src/parsers/ast_to_ast/implementations/ast_walker.php =================================================================== --- trunk/Template/src/parsers/ast_to_ast/implementations/ast_walker.php 2006-10-03 08:33:57 UTC (rev 3622) +++ trunk/Template/src/parsers/ast_to_ast/implementations/ast_walker.php 2006-10-03 14:50:58 UTC (rev 3623) @@ -20,6 +20,7 @@ public $nodePath = array(); public $statements = array(); + public $offset = array(); public function __construct( ) { @@ -162,6 +163,7 @@ { array_unshift( $this->nodePath, $body ); array_unshift( $this->statements, 0); + array_unshift( $this->offset, 0); $b = clone( $body ); @@ -173,6 +175,7 @@ $body = $b; + array_shift( $this->offset ); array_shift( $this->statements ); array_shift( $this->nodePath ); } @@ -181,6 +184,7 @@ { array_unshift( $this->nodePath, $body ); array_unshift( $this->statements, 0); + array_unshift( $this->offset, 0); for( $i = 0; $i < sizeof( $body->statements ); $i++) { @@ -188,6 +192,7 @@ $this->acceptAndUpdate( $body->statements[$i] ); } + array_shift( $this->offset ); array_shift( $this->statements ); array_shift( $this->nodePath ); } Modified: trunk/Template/src/parsers/ast_to_ast/implementations/cache.php =================================================================== --- trunk/Template/src/parsers/ast_to_ast/implementations/cache.php 2006-10-03 08:33:57 UTC (rev 3622) +++ trunk/Template/src/parsers/ast_to_ast/implementations/cache.php 2006-10-03 14:50:58 UTC (rev 3623) @@ -1,6 +1,6 @@ <?php /** - * File containing the ezcTemplateAstToAstContextAppender + * File containing the ezcTemplateAstToAstCache * * @package Template * @version //autogen// @@ -9,6 +9,8 @@ * @access private */ /** + * An instance of this class 'walks' over the AST tree and inserts the cache implementation. + * * @package Template * @version //autogen// * @access private @@ -16,7 +18,7 @@ class ezcTemplateAstToAstCache extends ezcTemplateAstWalker { private $template = null; - private $uniqueID = null; + private $cacheName = null; public function __construct( $template ) { @@ -27,106 +29,272 @@ { } - public function visitRootAstNode( ezcTemplateRootAstNode &$type ) + /** + * Removes the old cache file + */ + protected function removeOldCache( $cachePath ) { - if( !$type->cacheTemplate ) + if( file_exists( $cachePath ) ) { - return; + unlink( $cachePath ); } + } - $this->uniqueID = uniqid(); - + /** + * Returns the ast tree: !file_exists( [$this->cacheName] ) + */ + protected function _notFileExistsCache() + { + return new ezcTemplateLogicalNegationOperatorAstNode( new ezcTemplateFunctionCallAstNode( "file_exists", array( new ezcTemplateLiteralAstNode( $this->cacheName ) ) ) ); + } - - // Need to make a tree duplication? - // To prevent tree madness.. - ////////////////////// - // Write: $c = - // $c = new ezcCacheStorageFilePlain("/tmp/cache/"); + /** + * Returns the ast tree: include( [$this->cacheName] ); + */ + protected function _includeCache() + { + return new ezcTemplateGenericStatementAstNode( new ezcTemplateFunctionCallAstNode( "include", array( new ezcTemplateLiteralAstNode( $this->cacheName ) ) ) ); + } - // if ( ( $data = $c->restore( "pizza" ) ) === false ) - // { - // $dataOfFirstItem = "Plain cache stored on " . date( 'Y-m-d, H:i:s' ); - // $c->store( "pizzaboer", $dataOfFirstItem ); - // } + /** + * Returns the ast tree: $fp = fopen( [$this->cacheName], "w"); + */ + protected function _fopenCacheFileWriteMode() + { + return new ezcTemplateGenericStatementAstNode( new ezcTemplateAssignmentOperatorAstNode( new ezcTemplateVariableAstNode("fp"), new ezcTemplateFunctionCallAstNode( "fopen", array( new ezcTemplateLiteralAstNode( $this->cacheName ), new ezcTemplateLiteralAstNode( "w") )) ) ); - // Create $cache = new ... - $createCacheLine = new ezcTemplateGenericStatementAstNode( new ezcTemplateAssignmentOperatorAstNode( new ezcTemplateVariableAstNode( "cache" ), new ezcTemplateNewAstNode ("ezcCacheStorageFilePlain", array( new ezcTemplateLiteralAstNode("/tmp/cache/") ) ) ) ); + } - $createDataLine = new ezcTemplateParenthesisAstNode( new ezcTemplateAssignmentOperatorAstNode( new ezcTemplateVariableAstNode( "data" ), new ezcTemplateObjectAccessOperatorAstNode( new ezcTemplateVariableAstNode( "cache"), new ezcTemplateFunctionCallAstNode( "restore", array(new ezcTemplateLiteralAstNode($this->uniqueID) ) ) ) ) ) ; + /** + * Returns the ast tree: fwrite( $fp, "<" . "?php\n" ); + */ + protected function _fwritePhpOpen() + { + return new ezcTemplateGenericStatementAstNode( new ezcTemplateFunctionCallAstNode( "fwrite", array( new ezcTemplateVariableAstNode("fp"), new ezcTemplateConcatOperatorAstNode( new ezcTemplateLiteralAstNode('<'), new ezcTemplateLiteralAstNode('?php\\n' ) ) ) ) ); + } + /** + * Returns the ast tree: <variable> = ""; + */ + protected function _assignEmptyString( $variable ) + { + return new ezcTemplateGenericStatementAstNode( new ezcTemplateAssignmentOperatorAstNode( new ezcTemplateVariableAstNode($variable), new ezcTemplateLiteralAstNode( "") ) ); + } - $compare = new ezcTemplateIdenticalOperatorAstNode( $createDataLine, new ezcTemplateLiteralAstNode( false) ); + /** + * Returns the ast tree: <variableDst> .= <variableSrc>; + */ + protected function _concatAssignVariable( $variableSrc, $variableDst ) + { + return new ezcTemplateGenericStatementAstNode( new ezcTemplateConcatAssignmentOperatorAstNode( new ezcTemplateVariableAstNode($variableDst), new ezcTemplateVariableAstNode($variableSrc) ) ); + } - $cb = new ezcTemplateConditionBodyAstNode(); - $cb->condition = $compare; + /** + * Returns the ast tree: <variableDst> = <variableSrc>; + */ + protected function _assignVariable( $variableSrc, $variableDst ) + { + return new ezcTemplateGenericStatementAstNode( new ezcTemplateAssignmentOperatorAstNode( new ezcTemplateVariableAstNode($variableDst), new ezcTemplateVariableAstNode($variableSrc) ) ); + } + + /** + * Returns the ast tree: fwriteLiteral( $fp, <literal_value> ); + */ + protected function _fwriteLiteral( $literalValue ) + { + return new ezcTemplateGenericStatementAstNode( new ezcTemplateFunctionCallAstNode( "fwrite", array( new ezcTemplateVariableAstNode("fp"), new ezcTemplateLiteralAstNode( $literalValue ) ) ) ); + + } + + /** + * Returns the ast tree: fwriteVariable( $fp, $<variableName> ); + */ + protected function _fwriteVariable( $variableName ) + { + return new ezcTemplateGenericStatementAstNode( new ezcTemplateFunctionCallAstNode( "fwrite", array( new ezcTemplateVariableAstNode("fp"), new ezcTemplateVariableAstNode( $variableName ) ) ) ); + } + + + /** + * Returns the ast tree: return $<variableName>; + */ + protected function _returnVariable( $variableName ) + { + return new ezcTemplateGenericStatementAstNode( new ezcTemplateReturnAstNode ( new ezcTemplateVariableAstNode( $variableName ) ) ); + } + + /** + * Returns one of the following ast trees, depending on the variables $concat and $fwritePhpClose: + * + * fwrite( $fp, "\\\<variableName> = " . var_export( <variableName>, true) . "; ?>" ); + * fwrite( $fp, "\\\<variableName> .= " . var_export( <variableName>, true) . ";" ); + * fwrite( $fp, "\\\<variableName> = " . var_export( <variableName>, true) . "; ?>" ); + * fwrite( $fp, "\\\<variableName> .= " . var_export( <variableName>, true) . ";" ); + */ + protected function _fwriteVarExportVariable( $variableName, $concat, $fwritePhpClose = false ) + { + return new ezcTemplateGenericStatementAstNode( new ezcTemplateFunctionCallAstNode( "fwrite", array(new ezcTemplateVariableAstNode("fp"), new ezcTemplateConcatOperatorAstNode( new ezcTemplateLiteralAstNode("\\\$".$variableName." ". ($concat ? ".=" : "=") ." "), new ezcTemplateConcatOperatorAstNode( new ezcTemplateFunctionCallAstNode( "var_export", array( new ezcTemplateVariableAstNode("$variableName"), new ezcTemplateLiteralAstNode(true) ) ), new ezcTemplateLiteralAstNode(";\\n" . ($fwritePhpClose ? " ?>" : "" )) ) ) ) ) ); + } + + /** + * Returns the ast tree that inserts comments. + */ + protected function _comment( $str ) + { + return new ezcTemplatePhpCodeAstNode( "// ". str_replace( "\n", "\n// ", $str ) . "\n" ); + } + + /** + * Returns the ast tree: fclose( $fp); + */ + protected function _fclose() + { + return new ezcTemplateGenericStatementAstNode( new ezcTemplateFunctionCallAstNode( "fclose", array( new ezcTemplateVariableAstNode( "fp" ) ) ) ) ; + } + + + /** + * This should be the first node found in the AST-tree. + */ + public function visitRootAstNode( ezcTemplateRootAstNode &$type ) + { + // Should the template be cached? + if( !$type->cacheTemplate ) + { + // No, ET phone home + return; + } + + $this->cacheName = "/tmp/cache/" . str_replace( '/', "-", $this->template->stream ); + + // Create the if statement that checks whether the cache file exists. + $if = new ezcTemplateIfAstNode(); + $if->conditions[] = $cb = new ezcTemplateConditionBodyAstNode(); + $cb->condition = $this->_notFileExistsCache(); $cb->body = new ezcTemplateBodyAstNode(); + + // Move the current statements under the 'if'. (Or: Create an if around the current statements) $cb->body->statements = $type->statements; - $if = new ezcTemplateIfAstNode(); - $if->conditions[] = $cb; + // Create the 'else' part. The else should 'include' (and execute) the cached file. + $if->conditions[] = $else = new ezcTemplateConditionBodyAstNode(); + $else->body = new ezcTemplateBodyAstNode(); + $else->body->statements = array(); + $else->body->statements[] = $this->_includeCache(); + // The current statements are already moved to the if node, Don't need them here. $type->statements = array(); - $type->statements[] = $createCacheLine; + + // Of course we need the if-statement we just created. $type->statements[] = $if; + // Create the statements that belong (on top) inside the if-body. + $statements = array(); + $statements[] = $this->_fopenCacheFileWriteMode(); // $fp = fopen( $this->cache, "w" ); + $statements[] = $this->_fwritePhpOpen(); // fwrite( $fp, "<" . "?php\n" ); + $statements[] = $this->_assignEmptyString("total"); // $total = "" + $statements[] = $this->_fwriteLiteral("\\\$_ezcTemplate_output = '';\\n"); // fwrite( $fp, "\\\$_ezcTemplate_output = '';\\n" ); + // Insert the statements in the front of the statement array: $cb->body->statements + array_splice($cb->body->statements, 0, 0, $statements); + + // No need to increase the $this->offset counter, because the parent loops over it (included the new statements). parent::visitRootAstNode( $type ); - // return $data; - $type->statements[] = new ezcTemplateGenericStatementAstNode( new ezcTemplateReturnAstNode ( new ezcTemplateVariableAstNode( "data") ) ); + // Append an additional return $_ezcTemplate_output; (The previous is gone in the if statements.) + //XXX: Need to copy the previous one. + $type->statements[] = $this->_returnVariable("_ezcTemplate_output"); + } - - return; - } - public function visitReturnAstNode( ezcTemplateReturnAstNode $return ) { - // Write the to cache. - // $cache->store( "template_identifier", $data ); + // These statements should be added above the return-statement. + $statements = array(); - $a = new ezcTemplateGenericStatementAstNode( new ezcTemplateObjectAccessOperatorAstNode( new ezcTemplateVariableAstNode( "cache"), new ezcTemplateFunctionCallAstNode( "store", array(new ezcTemplateLiteralAstNode($this->uniqueID), new ezcTemplateVariableAstNode("_ezcTemplate_output") ) ) ) ); + //fwrite( $fp, "\\\$_ezcTemplate_output .= " . var_export( $ezcTemplate_output, true) . ";" ); + $statements[] = $this->_fwriteVarExportVariable( "_ezcTemplate_output", "true", true); - array_splice($this->nodePath[0]->statements, $this->statements[0], 0, array($a) ); + // $total .= $_ezcTemplate_output; + $statements[] = $this->_concatAssignVariable( "_ezcTemplate_output", "total"); + + // fclose($fp); + $statements[] = $this->_fclose(); + // $_ezcTemplate_output = $total; + $statements[] = $this->_assignVariable( "total", "_ezcTemplate_output" ); - /* + // Insert the statements at the current line. + array_splice($this->nodePath[0]->statements, $this->statements[0] + $this->offset[0], 0, $statements ); + $this->offset[0] += sizeof( $statements ); + } - echo ("Number: " . $this->statements[0] . "\n" ); - var_dump ($this->nodePath[0]->statements[$this->statements[0]]); + public function visitNopAstNode( ezcTemplateNopAstNode $node ) + { + // The nop-nodes may contain extra information regarding the {dynamic} blocks. + if( $node->type == ezcTemplateNopAstNode::TYPE_DYNAMIC_OPEN ) + { + // Write the variables introduced in the static part to the cache. + $symbolTable = ezcTemplateSymbolTable::getInstance(); + $symbols = $symbolTable->retrieveSymbolsWithType( array( ezcTemplateSymbolTable::VARIABLE, ezcTemplateSymbolTable::CYCLE ) ); - exit(); - foreach( $this->nodePath as $n ) + $newStatement = array(); + + // Initialize the values. + // XXX: Check also for the used variables. + foreach( $symbols as $symbol ) + { + $newStatement[] = $this->_fwriteVarExportVariable( $symbol, false, false ); + } + + $newStatement[] = $this->_comment(" ---> start {dynamic}"); + + // $total .= $_ezcTemplate_output + $newStatement[] = $this->_concatAssignVariable( "_ezcTemplate_output", "total"); + + // fwrite( $fp, "\\\<variableName> .= " . var_export( <variableName>, true) . ";" ); + $newStatement[] = $this->_fwriteVarExportVariable( "_ezcTemplate_output", true, false); + + // $_ezcTemplate_output = ""; + $newStatement[] = $this->_assignEmptyString("_ezcTemplate_output"); + + // $output .= $_ezcTemplate_output; + $newStatement[] = $this->_concatAssignVariable( "_ezcTemplate_output", "total"); + + // Place everything in the code block. + // XXX scan for quote: ' + $newStatement[] = new ezcTemplatePhpCodeAstNode( "\$code = '" ); + + // Insert the new statements. + array_splice($this->nodePath[0]->statements, $this->statements[0] + $this->offset[0], 0, $newStatement); + $this->offset[0] += sizeof( $newStatement ); + } + elseif( $node->type == ezcTemplateNopAstNode::TYPE_DYNAMIC_CLOSE ) { - echo get_class( $n ) . "\n"; - } - exit(); + + $newStatement = array(); + $newStatement[] = new ezcTemplatePhpCodeAstNode( "';\n" ); - var_dump( $return ); - */ - return; - - } + // fwrite( $fp, $code ); + $newStatement[] = $this->_fwriteVariable( "code" ); + // eval( $code ); + $newStatement[] = new ezcTemplateGenericStatementAstNode( + new ezcTemplateFunctionCallAstNode( "eval", array( new ezcTemplateVariableAstNode("code") ) ) ); + // $total .= _ezcTemplate_output + $newStatement[] = $this->_concatAssignVariable( "_ezcTemplate_output", "total" ); + // $ezcTemplate_output = ""; + $newStatement[] = $this->_assignEmptyString("_ezcTemplate_output"); -/* - public function visitOutputAstNode( ezcTemplateOutputAstNode $type ) - { - parent::visitOutputAstNode( $type ); + $newStatement[] = $this->_comment(" <--- stop {/dynamic}"); - if ( $type->isRaw ) - { - return $type; + array_splice($this->nodePath[0]->statements, $this->statements[0] + $this->offset[0], 0, $newStatement); + $this->offset[0] += sizeof($newStatement); } - return $this->context->transformOutput( $type->expression ); } - */ - - } ?> Modified: trunk/Template/src/parsers/source_to_tst/implementations/cache.php =================================================================== --- trunk/Template/src/parsers/source_to_tst/implementations/cache.php 2006-10-03 08:33:57 UTC (rev 3622) +++ trunk/Template/src/parsers/source_to_tst/implementations/cache.php 2006-10-03 14:50:58 UTC (rev 3623) @@ -31,11 +31,31 @@ */ protected function parseCurrent( ezcTemplateCursor $cursor ) { - /* + if ( $this->block->isClosingBlock ) { $this->findNextElement(); + if( $cursor->match( "dynamic" ) ) + { + $this->findNextElement( $cursor ); + + if (!$cursor->match( "}" ) ) + { + die ("Expected '}'"); + + } + + $cacheNode = new ezcTemplateCacheTstNode( $this->parser->source, $this->startCursor, $cursor ); + + $cacheNode->isClosingBlock = true; + $cacheNode->type = ezcTemplateCacheTstNode::TYPE_DYNAMIC_CLOSE; + $this->appendElement( $cacheNode); + return true; + } + + /* + $matches = $cursor->pregMatchComplete( "#^([a-zA-Z_][a-zA-Z0-9_-]*)(?:[^a-zA-Z])#i" ); if ( $matches === false ) return false; @@ -55,15 +75,16 @@ $this->appendElement( $cb ); return true; + */ } - */ + if( $cursor->match( "cache_template" ) ) { $cacheNode = new ezcTemplateCacheTstNode( $this->parser->source, $this->startCursor, $cursor ); + $cacheNode->type = ezcTemplateCacheTstNode::TYPE_TEMPLATE_CACHE; //$cacheNode->isClosingBlock = false; - $cacheNode->templateCache = true; $this->appendElement( $cacheNode); $this->findNextElement( $cursor ); @@ -76,11 +97,28 @@ return true; // Need to cache the template } + elseif( $cursor->match( "dynamic" ) ) + { + $cacheNode = new ezcTemplateCacheTstNode( $this->parser->source, $this->startCursor, $cursor ); + //$cacheNode->isClosingBlock = true; + $cacheNode->type = ezcTemplateCacheTstNode::TYPE_DYNAMIC_OPEN; + $this->appendElement( $cacheNode); + + $this->findNextElement( $cursor ); + if( !$cursor->match( "}" ) ) + { + die ("Expected an '}'"); + } + return true; + } + + + return false; // Check for the name of the custom block Modified: trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_transformer.php =================================================================== --- trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_transformer.php 2006-10-03 08:33:57 UTC (rev 3622) +++ trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_transformer.php 2006-10-03 14:50:58 UTC (rev 3623) @@ -270,14 +270,22 @@ public function visitCacheTstNode( ezcTemplateCacheTstNode $type ) { - if( $type->templateCache ) + if( $type->type === ezcTemplateCacheTstNode::TYPE_DYNAMIC_OPEN || $type->type === ezcTemplateCacheTstNode::TYPE_DYNAMIC_CLOSE ) { + //new ezcTemplateVirtualAstNode(); + $nop = new ezcTemplateNopAstNode(); + $nop->type = ($type->type === ezcTemplateCacheTstNode::TYPE_DYNAMIC_OPEN ? ezcTemplateNopAstNode::TYPE_DYNAMIC_OPEN : ezcTemplateNopAstNode::TYPE_DYNAMIC_CLOSE); + return $nop; + } + elseif( $type->type == ezcTemplateCacheTstNode::TYPE_TEMPLATE_CACHE ) + { // Modify the root node. $this->programNode->cacheTemplate = true; return new ezcTemplateNopAstNode(); } + } public function visitCycleControlTstNode( ezcTemplateCycleControlTstNode $cycle ) Modified: trunk/Template/src/symbol_table.php =================================================================== --- trunk/Template/src/symbol_table.php 2006-10-03 08:33:57 UTC (rev 3622) +++ trunk/Template/src/symbol_table.php 2006-10-03 14:50:58 UTC (rev 3623) @@ -119,6 +119,19 @@ return $this->symbols[ $symbol ]; } + public function retrieveSymbolsWithType( $typeArray ) + { + $total = array(); + + foreach( $typeArray as $type ) + { + // Search for all the keys in the array, and merge it. + $total = array_merge($total, array_keys( $this->symbols, $type ) ); + } + + return $total; + } + public function getErrorMessage() { return $this->errorMessage; Modified: trunk/Template/src/syntax_trees/ast/nodes/nop.php =================================================================== --- trunk/Template/src/syntax_trees/ast/nodes/nop.php 2006-10-03 08:33:57 UTC (rev 3622) +++ trunk/Template/src/syntax_trees/ast/nodes/nop.php 2006-10-03 14:50:58 UTC (rev 3623) @@ -18,6 +18,11 @@ */ class ezcTemplateNopAstNode extends ezcTemplateStatementAstNode { + const TYPE_DYNAMIC_OPEN = 10; + const TYPE_DYNAMIC_CLOSE = 11; + + public $type = 0; + /** */ public function __construct() Modified: trunk/Template/src/syntax_trees/tst/nodes/cache.php =================================================================== --- trunk/Template/src/syntax_trees/tst/nodes/cache.php 2006-10-03 08:33:57 UTC (rev 3622) +++ trunk/Template/src/syntax_trees/tst/nodes/cache.php 2006-10-03 14:50:58 UTC (rev 3623) @@ -17,10 +17,18 @@ */ class ezcTemplateCacheTstNode extends ezcTemplateExpressionTstNode { + const TYPE_NOT_SET = 0; + const TYPE_TEMPLATE_CACHE = 1; + const TYPE_DYNAMIC_OPEN = 10; + const TYPE_DYNAMIC_CLOSE = 11; + public $type = 0; + public $templateCache = false; + public $isClosingBlock = false; + /** * * @param ezcTemplateSource $source Modified: trunk/Template/src/template.php =================================================================== --- trunk/Template/src/template.php 2006-10-03 08:33:57 UTC (rev 3622) +++ trunk/Template/src/template.php 2006-10-03 14:50:58 UTC (rev 3623) @@ -72,6 +72,7 @@ 'compiledTemplatePath' => null, 'tstTree' => false, 'astTree' => false, + 'stream' => false, 'output' => "", ); @@ -100,6 +101,7 @@ case 'receive': case 'tstTree': case 'astTree': + case 'stream': case 'compiledTemplatePath': case 'output': return $this->properties[$name]; @@ -132,8 +134,9 @@ case 'receive': case 'tstTree': case 'astTree': + case 'stream': case 'output': - return true; + return isset( $name ); default: return false; } @@ -176,6 +179,7 @@ case 'astTree': case 'compiledTemplatePath': case 'output': + case 'stream': case 'receive': throw new ezcBasePropertyPermissionException( $name, ezcBasePropertyPermissionException::READ ); @@ -215,29 +219,28 @@ $this->properties["tstTree"] = false; $this->properties["astTree"] = false; + $this->properties["stream"] = false; - $stream = false; - - $stream = $location; - if ( $stream[0] != "/" ) // Is it a relative path? + $this->properties["stream"] = $location; + if ( $this->properties["stream"][0] != "/" ) // Is it a relative path? { - $stream = $config->templatePath ."/". $stream; + $this->properties["stream"] = $config->templatePath ."/". $this->properties["stream"]; } // lookup compiled code here - $compiled = ezcTemplateCompiledCode::findCompiled( $stream, $config->context, $this ); + $compiled = ezcTemplateCompiledCode::findCompiled( $this->properties["stream"], $config->context, $this ); $this->properties["compiledTemplatePath"] = $compiled->path; if ( !file_exists( $compiled->path ) || ( $config->checkModifiedTemplates && - file_exists( $stream ) && filemtime( $stream ) >= filemtime( $compiled->path ) ) + file_exists( $this->properties["stream"] ) && filemtime( $this->properties["stream"] ) >= filemtime( $compiled->path ) ) ) { $this->createDirectory( dirname( $compiled->path ) ); // get the compiled path. // use parser here - $source = new ezcTemplateSourceCode( $stream, $stream ); + $source = new ezcTemplateSourceCode( $this->properties["stream"], $this->properties["stream"] ); $source->load(); $parser = new ezcTemplateParser( $source, $this ); $this->properties["tstTree"] = $parser->parseIntoNodeTree(); @@ -258,7 +261,6 @@ $astToAst = new ezcTemplateAstToAstCache( $this ); $tstToAst->programNode->accept( $astToAst ); - $g = new ezcTemplateAstToPhpGenerator( $compiled->path ); // Write to the file. $tstToAst->programNode->accept( $g ); } Modified: trunk/Template/tests/regression_test.php =================================================================== --- trunk/Template/tests/regression_test.php 2006-10-03 08:33:57 UTC (rev 3622) +++ trunk/Template/tests/regression_test.php 2006-10-03 14:50:58 UTC (rev 3623) @@ -125,19 +125,31 @@ $template->send = include ($send); } + $out = array(); + $counter = 0; + try { - $out = $template->process( $base ); + $out[$counter] = $template->process( $base ); + + + ++$counter; + while( file_exists( substr( $directory, 0, -3 ) . ".out" . ($counter + 1) ) ) + { + $out[$counter] = $template->process( $base ); + $counter++; + } + } catch (Exception $e ) { - $out = $e->getMessage(); + $out[$counter] = $e->getMessage(); // Begin of the error message contains the full path. We replace this with 'mock' so that the // tests work on other systems as well. - if( strncmp( $out, $directory, strlen( $directory ) ) == 0 ) + if( strncmp( $out[$counter], $directory, strlen( $directory ) ) == 0 ) { - $out = "mock" . substr( $out, strlen( $directory ) ); + $out[$counter] = "mock" . substr( $out[$counter], strlen( $directory ) ); } } @@ -156,7 +168,7 @@ if ($char == "y" || $char == "Y" ) { - file_put_contents( $expected, $out ); + file_put_contents( $expected, $out[$counter] ); } } else @@ -164,7 +176,7 @@ $this->fail( $help ); } } - else if ( file_get_contents( $expected ) != $out ) + else if ( file_get_contents( $expected ) != $out[0] ) { $help = "The evaluated template <".$regressionDir . "/current.tmp> differs "; $help .= "from the expected output: <$expected>.\n\n"; @@ -182,7 +194,7 @@ $help .= "\n"; $help .= "The eval'ed output:\n"; - $help .= "----------\n".$out."----------\n"; + $help .= "----------\n".$out[0]."----------\n"; $help .= "\n"; $help .= "The expected output:\n"; @@ -212,7 +224,7 @@ if ($char == "y" || $char == "Y" ) { - file_put_contents( $expected, $out ); + file_put_contents( $expected, $out[0] ); } } else @@ -222,6 +234,28 @@ $this->fail( $help ); } + elseif( sizeof( $out ) > 1 ) + { + for( $i = 1; $i < sizeof( $out ); $i++ ) + { + $file = substr( $directory, 0, -3 ) . ".out" . ($i + 1); + if( file_get_contents( $file ) != $out[$i] ) + { + $help = "\nRun ". ($i + 1) . " returns a different value than expected.\n"; + $help .= "file: $file \n\n"; + + $help .= "The eval'ed output:\n"; + $help .= "----------\n".$out[$i]."----------\n"; + $help .= "\n"; + + $help .= "The expected output:\n"; + $help .= "----------\n" . file_get_contents( substr( $directory, 0, -3 ) . ".out" . ($i + 1) ) . "----------\n"; + $help .= "\n"; + + die ( $help ); + } + } + } else { // check the receive variables. -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components