You are here

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

Check if a value looks like a serialized array.

Parameters

string $value: The string value to assess.

Return value

bool TRUE/FALSE.

Overrides SchemaMetatagManagerInterface::isSerialized

1 call to SchemaMetatagManager::isSerialized()
SchemaMetatagManager::unserialize in src/SchemaMetatagManager.php
Wrapper for unserialize to prevent errors.

File

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

Class

SchemaMetatagManager
Class SchemaMetatagManager.

Code

public static function isSerialized($value) {

  // If it isn't a string, it isn't serialized.
  if (!is_string($value)) {
    return FALSE;
  }
  $data = trim($value);
  if ('N' == $value) {
    return TRUE;
  }
  if (!preg_match('/^([adObis]):/', $value, $badions)) {
    return FALSE;
  }
  switch ($badions[1]) {
    case 'a':
    case 'O':
    case 's':
      if (preg_match("/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $value)) {
        return TRUE;
      }
      break;
    case 'b':
    case 'i':
    case 'd':
      if (preg_match("/^{$badions[1]}:[0-9.E-]+;\$/", $value)) {
        return TRUE;
      }
      break;
  }
  return FALSE;
}