You are here

public static function SchemaMetatagManager::recomputeSerializedLength in Schema.org Metatag 8.2

Same name and namespace in other branches
  1. 8 src/SchemaMetatagManager.php \Drupal\schema_metatag\SchemaMetatagManager::recomputeSerializedLength()

Update serialized item length computations.

Prevent unserialization error if token replacements are different lengths than the original tokens.

Parameters

string $value: The string serialization value to recompute.

Return value

string The recomputed serialized value.

Overrides SchemaMetatagManagerInterface::recomputeSerializedLength

2 calls to SchemaMetatagManager::recomputeSerializedLength()
SchemaMetatagManager::unserialize in src/SchemaMetatagManager.php
Wrapper for unserialize to prevent errors.
SchemaMetatagManagerTest::testRecomputeSerializedLength in tests/src/Unit/SchemaMetatagManagerTest.php
@covers ::recomputeSerializedLength

File

src/SchemaMetatagManager.php, line 313

Class

SchemaMetatagManager
The SchemaMetatag Manager.

Namespace

Drupal\schema_metatag

Code

public static function recomputeSerializedLength($value) {
  $value = preg_replace_callback('!s:(\\d+):"(.*?)";!', function ($match) {
    return $match[1] == strlen($match[2]) ? $match[0] : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
  }, $value);
  return $value;
}