Skip to content

Commit

Permalink
Compiler::compile() class name is required
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 29, 2015
1 parent 93a78cf commit cdf25b7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/Latte/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public function addMacro($name, IMacro $macro)
* @param Token[]
* @return string
*/
public function compile(array $tokens, $className = NULL)
public function compile(array $tokens, $className)
{
$this->templateId = substr(lcg_value(), 2, 10);
$this->templateId = substr(md5($className), 0, 10);
$this->tokens = $tokens;
$output = '';
$this->output = & $output;
Expand Down Expand Up @@ -130,7 +130,7 @@ public function compile(array $tokens, $className = NULL)

$output = $this->expandTokens($output);
$output = "<?php\n"
. 'class ' . ($className ?: 'Template') . " extends Latte\\Template {\n"
. 'class ' . $className . " extends Latte\\Template {\n"
. "function render() {\n"
. 'foreach ($this->params as $__k => $__v) $$__k = $__v; unset($__k, $__v);'
. '?>' . $output . "<?php\n}}";
Expand Down
2 changes: 1 addition & 1 deletion tests/Latte/Compiler.htmlNode.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ class MockMacro implements IMacro
$parser = new Parser;
$compiler = new Compiler;
$compiler->addMacro('foo', new MockMacro);
$compiler->compile($parser->parse('<div a b=123 c = abc d="text" e=\'xxx\' f={foo 1/} b="456" g="a{foo 2/}b"> {foo 3/}'));
$compiler->compile($parser->parse('<div a b=123 c = abc d="text" e=\'xxx\' f={foo 1/} b="456" g="a{foo 2/}b"> {foo 3/}'), 'Template');
2 changes: 1 addition & 1 deletion tests/Latte/Compiler.macroMethodsCallingOrder.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ $macro = new MockMacro;
$parser = new Parser;
$compiler = new Compiler;
$compiler->addMacro('foo', $macro);
$compiler->compile($parser->parse($latte));
$compiler->compile($parser->parse($latte), 'Template');

Assert::same( array(
'initialize',
Expand Down

0 comments on commit cdf25b7

Please sign in to comment.