You are here

protected static function JsonBlueprintDenormalizer::arrayIsKeyed in Subrequests 8.2

Same name and namespace in other branches
  1. 8 src/Normalizer/JsonBlueprintDenormalizer.php \Drupal\subrequests\Normalizer\JsonBlueprintDenormalizer::arrayIsKeyed()
  2. 3.x src/Normalizer/JsonBlueprintDenormalizer.php \Drupal\subrequests\Normalizer\JsonBlueprintDenormalizer::arrayIsKeyed()

Check if an array is keyed.

Parameters

array $input: The input array to check.

Return value

bool True if the array is keyed.

1 call to JsonBlueprintDenormalizer::arrayIsKeyed()
JsonBlueprintDenormalizer::supportsDenormalization in src/Normalizer/JsonBlueprintDenormalizer.php
Checks whether the given class is supported for denormalization by this normalizer.

File

src/Normalizer/JsonBlueprintDenormalizer.php, line 100

Class

JsonBlueprintDenormalizer
Denormalizer that builds the blueprint based on the incoming blueprint.

Namespace

Drupal\subrequests\Normalizer

Code

protected static function arrayIsKeyed(array $input) {
  $keys = array_keys($input);

  // If the array does not start at 0, it is not numeric.
  if ($keys[0] !== 0) {
    return TRUE;
  }

  // If there is a non-numeric key, the array is not numeric.
  $numeric_keys = array_filter($keys, 'is_numeric');
  if (count($keys) != count($numeric_keys)) {
    return TRUE;
  }

  // If the keys are not following the natural numbers sequence, then it is
  // not numeric.
  for ($index = 1; $index < count($keys); $index++) {
    if ($keys[$index] - $keys[$index - 1] !== 1) {
      return TRUE;
    }
  }
  return FALSE;
}