You are here

public static function SchemaMetatagManager::unserialize in Schema.org Metatag 8

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

Wrapper for unserialize to prevent errors.

Parameters

string $value: The value to unserialize.

Return value

array The unserialized array.

Overrides SchemaMetatagManagerInterface::unserialize

1 call to SchemaMetatagManager::unserialize()
SchemaMetatagManagerTest::testUnserialize in tests/src/Unit/SchemaMetatagManagerTest.php
@covers ::unserialize @dataProvider arrayData

File

src/SchemaMetatagManager.php, line 204

Class

SchemaMetatagManager
Class SchemaMetatagManager.

Namespace

Drupal\schema_metatag

Code

public static function unserialize($value) {

  // Make sure the the value is not just a plain string and that
  // the same value isn't unserialized more than once if this is called
  // multiple times.
  if (self::isSerialized($value)) {

    // If a line break made it into the serialized array, it can't be
    // unserialized.
    $value = str_replace("\n", "", $value);

    // Fix problems created if token replacements are a different size
    // than the original tokens.
    $value = self::recomputeSerializedLength($value);

    // Keep broken unserialization from throwing errors on the page.
    if ($value = @unserialize($value)) {
      $value = self::arrayTrim($value);
    }
    else {

      // Fail safe if unserialization is broken.
      $value = [];
    }
  }
  return $value;
}