| 1 |
<?php |
| 2 |
declare(strict_types=1); |
| 3 |
|
| 4 |
namespace Imagify\Optimization; |
| 5 |
|
| 6 |
/** |
| 7 |
* Builds the fragile serialized-data needles used to detect, via a `LIKE`/`NOT LIKE` on the |
| 8 |
* `_imagify_data` postmeta, whether a media has a successful next-gen size or was permanently |
| 9 |
* refused by the API. |
| 10 |
* |
| 11 |
* These strings depend on the exact key order Imagify writes when serializing a size's |
| 12 |
* optimization data (see `Imagify\Optimization\Data\WP::update_size_optimization_data()`), so any |
| 13 |
* consumer must go through this class rather than retyping the literal. |
| 14 |
* |
| 15 |
* Two other copies of the same literals currently exist in `classes/Bulk/WP.php` (around lines |
| 16 |
* 320 and 325, for the `permanent_error` and `success` markers respectively) and in |
| 17 |
* `classes/Optimization/Process/AbstractProcess::has_avif()`. They predate this helper and were |
| 18 |
* left untouched to avoid destabilizing branches with in-flight changes; whoever next touches |
| 19 |
* those call sites should consider adopting this class instead. |
| 20 |
*/ |
| 21 |
class NextGenMarker { |
| 22 |
/** |
| 23 |
* Builds the needle matching a size that was successfully converted to the given next-gen |
| 24 |
* format (e.g. `@imagify-webp";a:4:{s:7:"success";b:1;`). |
| 25 |
* |
| 26 |
* @param string $suffix The format suffix, e.g. `ProcessInterface::WEBP_SUFFIX` or `::AVIF_SUFFIX`. |
| 27 |
* |
| 28 |
* @return string |
| 29 |
*/ |
| 30 |
public static function success( string $suffix ): string { |
| 31 |
return $suffix . '";a:4:{s:7:"success";b:1;'; |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Builds the needle matching a size the API permanently refused to convert (as opposed to a |
| 36 |
* transient failure, which is retried and does not carry the `permanent_error` key). |
| 37 |
* |
| 38 |
* @param string $suffix The format suffix, e.g. `ProcessInterface::WEBP_SUFFIX` or `::AVIF_SUFFIX`. |
| 39 |
* |
| 40 |
* @return string |
| 41 |
*/ |
| 42 |
public static function permanent_error( string $suffix ): string { |
| 43 |
return $suffix . '";a:3:{s:15:"permanent_error";b:1;'; |
| 44 |
} |
| 45 |
} |
| 46 |
|