You are here

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

Wrapper for unserialize to prevent errors.

Parameters

string $value: The value to unserialize.

Return value

array The unserialized array.

Overrides SchemaMetatagManagerInterface::unserialize

File

src/SchemaMetatagManager.php, line 217
A generic substitution for Drupal 8 Random utility.

Class

SchemaMetatagManager
Class SchemaMetatagManager.

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;
}