Correct errors from differening behaviour between 3.0 and 3.1

This commit is contained in:
Simon Welsh 2014-03-30 18:55:44 +13:00
parent c59cf624df
commit 6db96eac8f
3 changed files with 21 additions and 11 deletions

View File

@ -24,7 +24,7 @@ class SSViewerCacheBlockTest_VersionedModel extends DataObject implements TestOn
protected $entropy = 'default';
public static $extensions = array(
private static $extensions = array(
"Versioned('Stage', 'Live')"
);

View File

@ -2946,10 +2946,10 @@ class SSTemplateParser extends Parser implements TemplateParser {
// Embed the code necessary to evaluate the globalKey directly into the template,
// so that SSTemplateParser only needs to be called during template regeneration.
// Warning: If the global key is changed, it's necessary to flush the template cache.
$parser = new SSTemplateParser($globalKey);
$result = $parser->match_Template();
$parser = Injector::inst()->get('SSTemplateParser', false);
$result = $parser->compileString($globalKey, '', false, false);
if(!$result) throw new SSTemplateParseException('Unexpected problem parsing template', $parser);
$res['php'] .= $result['php'] . PHP_EOL;
$res['php'] .= $result . PHP_EOL;
}
$res['php'] .= 'return $val;' . PHP_EOL;
$res['php'] .= '};' . PHP_EOL;
@ -4703,9 +4703,10 @@ class SSTemplateParser extends Parser implements TemplateParser {
* @param $string The source of the template
* @param string $templateName The name of the template, normally the filename the template source was loaded from
* @param bool $includeDebuggingComments True is debugging comments should be included in the output
* @param bool $topTemplate True if this is a top template, false if it's just a template
* @return mixed|string The php that, when executed (via include or exec) will behave as per the template source
*/
public function compileString($string, $templateName = "", $includeDebuggingComments=false) {
public function compileString($string, $templateName = "", $includeDebuggingComments=false, $topTemplate = true) {
if (!trim($string)) {
$code = '';
}
@ -4719,7 +4720,11 @@ class SSTemplateParser extends Parser implements TemplateParser {
if(substr($string, 0,3) == pack("CCC", 0xef, 0xbb, 0xbf)) $this->pos = 3;
// Match the source against the parser
$result = $this->match_TopTemplate();
if ($topTemplate) {
$result = $this->match_TopTemplate();
} else {
$result = $this->match_Template();
}
if(!$result) throw new SSTemplateParseException('Unexpected problem parsing template', $this);
// Get the result

View File

@ -681,10 +681,10 @@ class SSTemplateParser extends Parser implements TemplateParser {
// Embed the code necessary to evaluate the globalKey directly into the template,
// so that SSTemplateParser only needs to be called during template regeneration.
// Warning: If the global key is changed, it's necessary to flush the template cache.
$parser = new SSTemplateParser($globalKey);
$result = $parser->match_Template();
$parser = Injector::inst()->get('SSTemplateParser', false);
$result = $parser->compileString($globalKey, '', false, false);
if(!$result) throw new SSTemplateParseException('Unexpected problem parsing template', $parser);
$res['php'] .= $result['php'] . PHP_EOL;
$res['php'] .= $result . PHP_EOL;
}
$res['php'] .= 'return $val;' . PHP_EOL;
$res['php'] .= '};' . PHP_EOL;
@ -1157,9 +1157,10 @@ class SSTemplateParser extends Parser implements TemplateParser {
* @param $string The source of the template
* @param string $templateName The name of the template, normally the filename the template source was loaded from
* @param bool $includeDebuggingComments True is debugging comments should be included in the output
* @param bool $topTemplate True if this is a top template, false if it's just a template
* @return mixed|string The php that, when executed (via include or exec) will behave as per the template source
*/
public function compileString($string, $templateName = "", $includeDebuggingComments=false) {
public function compileString($string, $templateName = "", $includeDebuggingComments=false, $topTemplate = true) {
if (!trim($string)) {
$code = '';
}
@ -1173,7 +1174,11 @@ class SSTemplateParser extends Parser implements TemplateParser {
if(substr($string, 0,3) == pack("CCC", 0xef, 0xbb, 0xbf)) $this->pos = 3;
// Match the source against the parser
$result = $this->match_TopTemplate();
if ($topTemplate) {
$result = $this->match_TopTemplate();
} else {
$result = $this->match_Template();
}
if(!$result) throw new SSTemplateParseException('Unexpected problem parsing template', $this);
// Get the result