AssetVariantLegacyHelper
in package
Migrates legacy ImageVariantEntity serialized objects to plain arrays.
Old format stored in DB (variants column): json_encode(serialize([ImageVariantEntity, ImageVariantEntity, ...]))
New format: json_encode(serialize([['name' => 'big', 'maxWidth' => 1200, ...], ...]))
The old CoolCMS\CoreModule\SystemModule\Models\Entities\ImageVariantEntity class no longer exists, so the string is unserialized with allowed_classes => false and the properties are extracted from __PHP_Incomplete_Class via an array cast.
Table of Contents
Methods
- isLegacyFormat() : bool
- Detects whether the variants string contains legacy serialized objects.
- migrate() : array<int, array<string|int, mixed>>
- Converts a legacy variants string to an array of plain associative arrays.
- extractFromIncompleteClass() : array<string, mixed>
- Extracts properties from a __PHP_Incomplete_Class object.
Methods
isLegacyFormat()
Detects whether the variants string contains legacy serialized objects.
public
static isLegacyFormat(string $variantsJson) : bool
Parameters
- $variantsJson : string
Return values
boolmigrate()
Converts a legacy variants string to an array of plain associative arrays.
public
static migrate(string $variantsJson) : array<int, array<string|int, mixed>>
Values are raw: types and the required name are completed by Asset::getUnserializedVariants().
Parameters
- $variantsJson : string
Return values
array<int, array<string|int, mixed>>extractFromIncompleteClass()
Extracts properties from a __PHP_Incomplete_Class object.
private
static extractFromIncompleteClass(__PHP_Incomplete_Class $obj) : array<string, mixed>
Private properties are stored with null-byte prefix: \0ClassName\0propName Protected properties: \0*\0propName
Parameters
- $obj : __PHP_Incomplete_Class