Fix valid filename and length

This commit is contained in:
bzick 2016-06-10 15:51:23 +03:00
parent eef14ecf06
commit 7fffa19fa9
2 changed files with 12 additions and 24 deletions

View File

@ -64,6 +64,11 @@ class Fenom
public static $charset = "UTF-8";
/**
* @var int maximum length of compiled filename (use sha1 of name if bigger)
*/
public static $filename_length = 200;
/**
* @var int[] of possible options, as associative array
* @see setOptions
@ -1075,13 +1080,17 @@ class Fenom
if (is_array($tpl)) {
$hash = implode(".", $tpl) . ":" . $options;
foreach ($tpl as &$t) {
$t = str_replace(":", "_", basename($t));
$t = urlencode(str_replace(":", "_", basename($t)));
}
return $this->_compile_id . implode("~", $tpl) . "." . sprintf("%x.%x.php", crc32($hash), strlen($hash));
$tpl = implode("~", $tpl);
} else {
$hash = $tpl . ":" . $options;
return sprintf($this->_compile_id . "%s.%x.%x.php", str_replace(":", "_", basename($tpl)), crc32($hash), strlen($hash));
$tpl = urlencode(str_replace(":", "_", basename($tpl)));
}
if($tpl > self::$filename_length) {
$tpl = sha1($tpl);
}
return $this->_compile_id . $tpl . "." . sprintf("%x.%x.php", crc32($hash), strlen($hash));
}
/**

View File

@ -1129,27 +1129,6 @@ class TemplateTest extends TestCase
);
}
/**
* @group sb
*/
public function _testSandbox()
{
try {
var_dump(
$this->fenom->compileCode(
'{Fenom\Helper::method()->page->title}'
)->getBody()
);
} catch (\Exception $e) {
print_r($e->getMessage() . "\n" . $e->getTraceAsString());
while ($e->getPrevious()) {
$e = $e->getPrevious();
print_r("\n\n" . $e->getMessage() . " in {$e->getFile()}:{$e->getLine()}\n" . $e->getTraceAsString());
}
}
exit;
}
/**
* @dataProvider providerScalars
*/