You are here

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

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

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 230

Class

SchemaMetatagManager
Class SchemaMetatagManager.

Namespace

Drupal\schema_metatag

Code

public static function isSerialized($value) {

  // If it isn't a string, it isn't serialized.
  if (!is_string($value)) {
    return FALSE;
  }
  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;
}