🔄 PrestaShop 9 : Évolution de la classe Tools et impact sur vos modules
La classe Tools de PrestaShop évolue dans la version 9, avec des changements majeurs à anticiper. The PrestaShop Tools class evolves in version 9, with major changes to anticipate. La clase Tools de PrestaShop evoluciona en la versión 9, con cambios importantes que anticipar. La classe Tools di PrestaShop si evolve nella versione 9, con cambiamenti importanti da anticipare. Ces évolutions, alignées sur les standards PHP modernes, nécessitent une préparation en amont de vos modules. These changes, aligned with modern PHP standards, require advance preparation of your modules. Estos cambios, alineados con los estándares modernos de PHP, requieren una preparación previa de sus módulos. Questi cambiamenti, allineati con gli standard PHP moderni, richiedono una preparazione anticipata dei vostri moduli. Identifiez les points d'attention pour préparer sereinement la compatibilité de votre code. Identify the key points to smoothly prepare your code for compatibility. Identifique los puntos clave para preparar tranquilamente la compatibilidad de su código. Identificate i punti chiave per preparare serenamente la compatibilità del vostro codice.
Tools::getBytes()
public static function getBytes($length)
{
$length = (int) $length;
if ($length <= 0) {
return false;
}
}
Tools::redirectLink()
public static function redirectLink($url)
{
Tools::displayAsDeprecated('Use Tools::redirect() instead');
static::redirect($url);
}
Tools::redirect($url);
Tools::displayNumber()
public static function displayNumber($number, $currency = null)
{
$context = Context::getContext();
$locale = static::getContextLocale($context);
return $locale->formatNumber($number);
}
$locale = Context::getContext()->getCurrentLocale();
$formattedNumber = $locale->formatNumber($number);
Tools::encrypt() et Tools::encryptIV()
$encrypted = Tools::encrypt($passwd);
$encryptedIV = Tools::encryptIV($data);
$hashed = Tools::hash($passwd);
$hashedIV = Tools::hashIV($data);
Tools::getBrightness() et Tools::isBright()
public static function getBrightness($hex)
{
if (Tools::strtolower($hex) == 'transparent') {
return '129';
}
}
public static function isBright($hex)
{
if (null === self::$colorBrightnessCalculator) {
self::$colorBrightnessCalculator = new ColorBrightnessCalculator();
}
}
$colorBrightnessCalculator = new ColorBrightnessCalculator();
$brightness = $colorBrightnessCalculator->getBrightness($hex);
$isBright = $colorBrightnessCalculator->isBright($hex);
Tools::replaceByAbsoluteURL()
public static function replaceByAbsoluteURL($matches)
{
Tools::displayAsDeprecated('Use Media::replaceByAbsoluteURL($matches) instead');
return Media::replaceByAbsoluteURL($matches);
}
$absoluteUrl = Media::replaceByAbsoluteURL($matches);
Tools::generateIndex()
public static function generateIndex()
{
PrestaShopAutoload::getInstance()->generateIndex();
}
PrestaShopAutoload::getInstance()->generateIndex();
Tools::clearColorListCache()
public static function clearColorListCache($id_product = false)
{
$current_template_dir = Context::getContext()->smarty->getTemplateDir();
Context::getContext()->smarty->setTemplateDir(_PS_THEME_DIR_);
Tools::clearCache(null, _PS_THEME_DIR_ . 'product-list-colors.tpl',
Product::getColorsListCacheId((int) $id_product, false));
Context::getContext()->smarty->setTemplateDir($current_template_dir);
}
Tools::cleanNonUnicodeSupport()
public static function cleanNonUnicodeSupport($pattern)
{
@trigger_error(
sprintf(
'%s is deprecated since version 8.0.0. Its use is not required.',
__METHOD__
),
E_USER_DEPRECATED
);
return $pattern;
}
Tools::getDescriptionClean()
public static function getDescriptionClean($description)
{
return strip_tags(stripslashes($description));
}
$cleanDescription = strip_tags(stripslashes($description));
Tools::arrayReplaceRecursive()
public static function arrayReplaceRecursive($base, $replacements)
{
Tools::displayAsDeprecated('Use PHP\\\'s array_replace_recursive() instead');
return array_replace_recursive($base, $replacements);
}
$result = array_replace_recursive($base, $replacements);
Tools::addonsRequest()
public static function addonsRequest($request, $params = array())
{
Tools::displayAsDeprecated('Use Addons\\AddonsRequester instead');
return false;
}
$addonsRequester = new \PrestaShop\PrestaShop\Adapter\Addons\AddonsRequester();
$result = $addonsRequester->request($request, $params);
Tools::getMediaServer()
public static function getMediaServer($filename)
{
Tools::displayAsDeprecated('Use Tools::getMediaServers() instead');
return Tools::getMediaServers($filename);
}
$mediaServer = Tools::getMediaServers($filename);
Tools::getHttpHost()
public static function getHttpHost($http = false, $entities = false, $ignore_port = false)
{
Tools::displayAsDeprecated('Use Tools::getServerName() instead');
return Tools::getServerName();
}
$serverName = Tools::getServerName();
Tools::getShopDomain()
public static function getShopDomain($http = false, $entities = false)
{
Tools::displayAsDeprecated('Use Tools::getServerName() instead');
return Tools::getServerName();
}
$serverName = Tools::getServerName();
Tools::displayPrice()
public static function displayPrice($price, $currency = null, $no_utf8 = false, Context $context = null)
{
@trigger_error(
'Tools::displayPrice() is deprecated since version 1.7.6.0. '
. 'Use ' . Locale::class . '::formatPrice() instead.',
E_USER_DEPRECATED
);
if (!is_numeric($price)) {
return $price;
}
}
$locale = Context::getContext()->getCurrentLocale();
$formattedPrice = $locale->formatPrice($price, $currencyIsoCode);