Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] Use xxh3 instead of sha1 #871

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/src/CustomVariableProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CustomVariableProvider extends StandardVariableProvider implements Variabl
public function getByPath($path)
{
if ($path === 'random') {
return 'random' . sha1(rand(0, 999999999));
return 'random' . hash('xxh3', (string)rand(0, 999999999));
lolli42 marked this conversation as resolved.
Show resolved Hide resolved
}
if ($path === 'incrementer') {
return ++$this->incrementer;
Expand Down
8 changes: 2 additions & 6 deletions src/Core/Compiler/TemplateCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,7 @@ protected function generateCodeForLayoutName($storedLayoutNameArgument): string
return 'return (string)\'' . $storedLayoutNameArgument . '\'';
}

/**
* @param ParsingState $parsingState
* @return string
*/
protected function generateSectionCodeFromParsingState(ParsingState $parsingState)
protected function generateSectionCodeFromParsingState(ParsingState $parsingState): string
{
$generatedRenderFunctions = '';
if ($parsingState->getVariableContainer()->exists('1457379500_sections')) {
Expand All @@ -249,7 +245,7 @@ protected function generateSectionCodeFromParsingState(ParsingState $parsingStat
// @todo: Verify this is *always* an instance of RootNode
// and call $node->convert($this) directly.
$this->convertSubNodes($sectionRootNode->getChildNodes()),
'section_' . sha1($sectionName),
'section_' . hash('xxh3', $sectionName),
'section ' . $sectionName,
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/View/AbstractTemplateView.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public function renderSection($sectionName, array $variables = [], $ignoreUnknow
}

if ($parsedTemplate->isCompiled()) {
$methodNameOfSection = 'section_' . sha1($sectionName);
$methodNameOfSection = 'section_' . hash('xxh3', (string)$sectionName);
if (!method_exists($parsedTemplate, $methodNameOfSection)) {
if ($ignoreUnknown) {
return '';
Expand Down
6 changes: 3 additions & 3 deletions src/View/TemplatePaths.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ public function getLayoutSource($layoutName = 'Default')
public function getTemplateIdentifier($controller = 'Default', $action = 'Default')
{
if ($this->templateSource !== null) {
return 'source_' . sha1($this->templateSource) . '_' . $controller . '_' . $action . '_' . $this->getFormat();
return 'source_' . hash('xxh3', (string)$this->templateSource) . '_' . $controller . '_' . $action . '_' . $this->getFormat();
}
$templatePathAndFilename = $this->resolveTemplateFileForControllerAndActionAndFormat($controller, $action);
$prefix = ltrim($controller . '_action_' . $action, '_');
Expand Down Expand Up @@ -610,7 +610,7 @@ public function getTemplateSource($controller = 'Default', $action = 'Default')

/**
* Returns a unique identifier for the given file in the format
* <PackageKey>_<SubPackageKey>_<ControllerName>_<prefix>_<SHA1>
* <PackageKey>_<SubPackageKey>_<ControllerName>_<prefix>_<hash>
* The SH1 hash is a checksum that is based on the file path and last modification date
*
* @param string|null $pathAndFilename
Expand All @@ -621,7 +621,7 @@ protected function createIdentifierForFile($pathAndFilename, $prefix)
{
$pathAndFilename = (string)$pathAndFilename;
$templateModifiedTimestamp = $pathAndFilename !== 'php://stdin' && file_exists($pathAndFilename) ? filemtime($pathAndFilename) : 0;
return sprintf('%s_%s', $prefix, sha1($pathAndFilename . '|' . $templateModifiedTimestamp));
return sprintf('%s_%s', $prefix, hash('xxh3', $pathAndFilename . '|' . $templateModifiedTimestamp));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/AbstractFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract class AbstractFunctionalTestCase extends BaseTestCase

public static function setUpBeforeClass(): void
{
self::$cachePath = sys_get_temp_dir() . '/' . 'fluid-functional-tests-' . sha1(__CLASS__);
self::$cachePath = sys_get_temp_dir() . '/' . 'fluid-functional-tests-' . hash('xxh3', __CLASS__);
mkdir(self::$cachePath);
self::$cache = (new SimpleFileCache(self::$cachePath));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/View/TemplatePathsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public function testGetTemplateIdentifierReturnsSourceChecksumWithControllerAndA
{
$instance = new TemplatePaths();
$instance->setTemplateSource('foobar');
self::assertSame('source_8843d7f92416211de9ebb963ff4ce28125932878_DummyController_dummyAction_html', $instance->getTemplateIdentifier('DummyController', 'dummyAction'));
self::assertSame('source_d78fda63144c5c84_DummyController_dummyAction_html', $instance->getTemplateIdentifier('DummyController', 'dummyAction'));
}

/**
Expand Down
Loading