function AbstractObjectNormalizerContextBuilder::withDepthKeyPattern
Configures a pattern to keep track of the current depth.
Must contain exactly two string placeholders.
Throws
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\NormalizerCode
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);
}