Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. AbstractObjectNormalizerContextBuilder.php

function AbstractObjectNormalizerContextBuilder::withDepthKeyPattern

Configures a pattern to keep track of the current depth.

Must contain exactly two string placeholders.

Throws

InvalidArgumentException

File

vendor/symfony/serializer/Context/Normalizer/AbstractObjectNormalizerContextBuilder.php, line 39

Class

AbstractObjectNormalizerContextBuilder
A helper providing autocompletion for available AbstractObjectNormalizer options.

Namespace

Symfony\Component\Serializer\Context\Normalizer

Code

public function withDepthKeyPattern(?string $depthKeyPattern) : static {
    if (null === $depthKeyPattern) {
        return $this->with(AbstractObjectNormalizer::DEPTH_KEY_PATTERN, null);
    }
    // This will match every occurrences of sprintf specifiers
    $matches = [];
    preg_match_all('/(?<!%)(?:%{2})*%(?<specifier>[a-z])/', $depthKeyPattern, $matches);
    if (2 !== \count($matches['specifier']) || 's' !== $matches['specifier'][0] || 's' !== $matches['specifier'][1]) {
        throw new InvalidArgumentException(\sprintf('The depth key pattern "%s" is not valid. You must set exactly two string placeholders.', $depthKeyPattern));
    }
    return $this->with(AbstractObjectNormalizer::DEPTH_KEY_PATTERN, $depthKeyPattern);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal