|
1 | 1 | <?php |
2 | | -/** |
3 | | - * Copyright © Magento, Inc. All rights reserved. |
4 | | - * See COPYING.txt for license details. |
| 2 | +/************************************************************************ |
| 3 | + * Copyright 2024 Adobe |
| 4 | + * All Rights Reserved. |
| 5 | + * |
| 6 | + * NOTICE: All information contained herein is, and remains |
| 7 | + * the property of Adobe and its suppliers, if any. The intellectual |
| 8 | + * and technical concepts contained herein are proprietary to Adobe |
| 9 | + * and its suppliers and are protected by all applicable intellectual |
| 10 | + * property laws, including trade secret and copyright laws. |
| 11 | + * Dissemination of this information or reproduction of this material |
| 12 | + * is strictly forbidden unless prior written permission is obtained |
| 13 | + * from Adobe. |
| 14 | + * *********************************************************************** |
5 | 15 | */ |
6 | 16 |
|
7 | 17 | namespace Magento\Catalog\Model\View\Asset; |
|
11 | 21 | use Magento\Catalog\Model\Product\Image\ConvertImageMiscParamsToReadableFormat; |
12 | 22 | use Magento\Catalog\Model\Product\Media\ConfigInterface; |
13 | 23 | use Magento\Framework\App\ObjectManager; |
14 | | -use Magento\Framework\Encryption\Encryptor; |
15 | 24 | use Magento\Framework\Encryption\EncryptorInterface; |
16 | 25 | use Magento\Framework\Exception\LocalizedException; |
17 | 26 | use Magento\Framework\View\Asset\ContextInterface; |
|
25 | 34 | */ |
26 | 35 | class Image implements LocalInterface |
27 | 36 | { |
| 37 | + /** |
| 38 | + * Current hashing algorithm |
| 39 | + */ |
| 40 | + private const HASH_ALGORITHM = 'md5'; |
| 41 | + |
28 | 42 | /** |
29 | 43 | * Image type of image (thumbnail,small_image,image,swatch_image,swatch_thumb) |
30 | 44 | * |
@@ -96,6 +110,8 @@ class Image implements LocalInterface |
96 | 110 | * @param CatalogMediaConfig $catalogMediaConfig |
97 | 111 | * @param StoreManagerInterface $storeManager |
98 | 112 | * @param ConvertImageMiscParamsToReadableFormat $convertImageMiscParamsToReadableFormat |
| 113 | + * |
| 114 | + * @SuppressWarnings(PHPMD.ExcessiveParameterList) |
99 | 115 | */ |
100 | 116 | public function __construct( |
101 | 117 | ConfigInterface $mediaConfig, |
@@ -260,29 +276,27 @@ public function getModule() |
260 | 276 | } |
261 | 277 |
|
262 | 278 | /** |
263 | | - * Retrieve part of path based on misc params |
264 | | - * |
265 | | - * @return string |
266 | | - */ |
267 | | - private function getMiscPath() |
268 | | - { |
269 | | - return $this->encryptor->hash( |
270 | | - implode('_', $this->convertToReadableFormat($this->miscParams)), |
271 | | - Encryptor::HASH_VERSION_MD5 |
272 | | - ); |
273 | | - } |
274 | | - |
275 | | - /** |
276 | | - * Generate path from image info |
| 279 | + * Generate path from image info. |
277 | 280 | * |
278 | 281 | * @return string |
279 | 282 | */ |
280 | 283 | private function getImageInfo() |
281 | 284 | { |
282 | | - $path = $this->getModule() |
283 | | - . DIRECTORY_SEPARATOR . $this->getMiscPath() |
284 | | - . DIRECTORY_SEPARATOR . $this->getFilePath(); |
285 | | - return preg_replace('|\Q'. DIRECTORY_SEPARATOR . '\E+|', DIRECTORY_SEPARATOR, $path); |
| 285 | + $data = implode('_', $this->convertToReadableFormat($this->miscParams)); |
| 286 | + |
| 287 | + $pathTemplate = $this->getModule() |
| 288 | + . DIRECTORY_SEPARATOR . "%s" . DIRECTORY_SEPARATOR |
| 289 | + . $this->getFilePath(); |
| 290 | + |
| 291 | + /** |
| 292 | + * New paths are generated without dependency on |
| 293 | + * an encryption key. |
| 294 | + */ |
| 295 | + return preg_replace( |
| 296 | + '|\Q' . DIRECTORY_SEPARATOR . '\E+|', |
| 297 | + DIRECTORY_SEPARATOR, |
| 298 | + sprintf($pathTemplate, hash(self::HASH_ALGORITHM, $data)) |
| 299 | + ); |
286 | 300 | } |
287 | 301 |
|
288 | 302 | /** |
|
0 commit comments