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

Avoid extra calls to Smarty::getTemplateDir #30280

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 14 additions & 9 deletions mixin/smarty-v2@1/mixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Auto-register "templates/" folder.
*
* @mixinName smarty-v2
* @mixinVersion 1.0.2
* @mixinVersion 1.0.3
* @since 5.59
*
* @deprecated - it turns out that the mixin is not version specific so the 'smarty'
Expand All @@ -29,14 +29,19 @@
$smarty->addTemplateDir($dir);
return;
}
// getTemplateDir returns string or array by reference
$templateRef = $smarty->getTemplateDir();
// Dereference and normalize as array
$templateDirs = (array) $templateRef;
// Add the dir if not already present
if (!in_array($dir, $templateDirs, TRUE)) {
array_unshift($templateDirs, $dir);
$smarty->setTemplateDir($templateDirs);
// Avoid calling getTemplateDir on Smarty 3+ when we know we
// have already registered the directory
if (empty(Civi::$statics[__FUNCTION__][$dir])) {
// getTemplateDir returns string or array by reference
$templateRef = $smarty->getTemplateDir();
// Dereference and normalize as array
$templateDirs = (array) $templateRef;
// Add the dir if not already present
if (!in_array($dir, $templateDirs, TRUE)) {
array_unshift($templateDirs, $dir);
$smarty->setTemplateDir($templateDirs);
}
Civi::$statics[__FUNCTION__][$dir] = true;
}
};

Expand Down
23 changes: 14 additions & 9 deletions mixin/smarty@1/mixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Auto-register "templates/" folder.
*
* @mixinName smarty
* @mixinVersion 1.0.2
* @mixinVersion 1.0.3
* @since 5.71
*
* @param CRM_Extension_MixInfo $mixInfo
Expand All @@ -25,14 +25,19 @@
$smarty->addTemplateDir($dir);
return;
}
// getTemplateDir returns string or array by reference
$templateRef = $smarty->getTemplateDir();
// Dereference and normalize as array
$templateDirs = (array) $templateRef;
// Add the dir if not already present
if (!in_array($dir, $templateDirs, TRUE)) {
array_unshift($templateDirs, $dir);
$smarty->setTemplateDir($templateDirs);
// Avoid calling getTemplateDir on Smarty 3+ when we know we
// have already registered the directory
if (empty(Civi::$statics[__FUNCTION__][$dir])) {
// getTemplateDir returns string or array by reference
$templateRef = $smarty->getTemplateDir();
// Dereference and normalize as array
$templateDirs = (array) $templateRef;
// Add the dir if not already present
if (!in_array($dir, $templateDirs, TRUE)) {
array_unshift($templateDirs, $dir);
$smarty->setTemplateDir($templateDirs);
}
Civi::$statics[__FUNCTION__][$dir] = true;
}
};

Expand Down