You are here

public static function EntityStub::fromEntityUri in Better Normalizers 8

Factory method to create new stub from entity URI.

Parameters

string $uri: Entity URI to parse.

Return value

static New instance.

Throws

\InvalidArgumentException When not an entity URI.

2 calls to EntityStub::fromEntityUri()
MenuLinkContentNormalizer::denormalize in src/Normalizer/MenuLinkContentNormalizer.php
Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::denormalize().
MenuLinkContentNormalizer::normalize in src/Normalizer/MenuLinkContentNormalizer.php
Normalizes an object into a set of arrays/scalars.

File

src/Normalizer/EntityStub.php, line 36

Class

EntityStub
Defines a value object to track an entity type and ID pair.

Namespace

Drupal\better_normalizers\Normalizer

Code

public static function fromEntityUri($uri) {
  $scheme = parse_url($uri, PHP_URL_SCHEME);
  if ($scheme !== 'entity') {
    throw new \InvalidArgumentException();
  }
  $path = parse_url($uri, PHP_URL_PATH);
  $static = new static();
  list($static->entityTypeId, $static->entityId) = explode('/', $path);
  return $static;
}