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

Breadcrumb

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

class AbstractObjectNormalizerContextBuilder

A helper providing autocompletion for available AbstractObjectNormalizer options.

@author Mathias Arlaud <mathias.arlaud@gmail.com>

Hierarchy

  • class \Symfony\Component\Serializer\Context\Normalizer\AbstractNormalizerContextBuilder implements \Symfony\Component\Serializer\Context\ContextBuilderInterface uses \Symfony\Component\Serializer\Context\ContextBuilderTrait
    • class \Symfony\Component\Serializer\Context\Normalizer\AbstractObjectNormalizerContextBuilder extends \Symfony\Component\Serializer\Context\Normalizer\AbstractNormalizerContextBuilder

Expanded class hierarchy of AbstractObjectNormalizerContextBuilder

File

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

Namespace

Symfony\Component\Serializer\Context\Normalizer
View source
abstract class AbstractObjectNormalizerContextBuilder extends AbstractNormalizerContextBuilder {
    
    /**
     * Configures whether to respect the max depth metadata on fields.
     */
    public function withEnableMaxDepth(?bool $enableMaxDepth) : static {
        return $this->with(AbstractObjectNormalizer::ENABLE_MAX_DEPTH, $enableMaxDepth);
    }
    
    /**
     * Configures a pattern to keep track of the current depth.
     *
     * Must contain exactly two string placeholders.
     *
     * @throws InvalidArgumentException
     */
    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);
    }
    
    /**
     * Configures whether verifying types match during denormalization.
     */
    public function withDisableTypeEnforcement(?bool $disableTypeEnforcement) : static {
        return $this->with(AbstractObjectNormalizer::DISABLE_TYPE_ENFORCEMENT, $disableTypeEnforcement);
    }
    
    /**
     * Configures whether fields with the value `null` should be output during normalization.
     */
    public function withSkipNullValues(?bool $skipNullValues) : static {
        return $this->with(AbstractObjectNormalizer::SKIP_NULL_VALUES, $skipNullValues);
    }
    
    /**
     * Configures whether uninitialized typed class properties should be excluded during normalization.
     */
    public function withSkipUninitializedValues(?bool $skipUninitializedValues) : static {
        return $this->with(AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES, $skipUninitializedValues);
    }
    
    /**
     * Configures a callback to allow to set a value for an attribute when the max depth has
     * been reached.
     *
     * If no callback is given, the attribute is skipped. If a callable is
     * given, its return value is used (even if null).
     *
     * The arguments are:
     *
     * - mixed                 $attributeValue value of this field
     * - object                $object         the whole object being normalized
     * - string                $attributeName  name of the attribute being normalized
     * - string                $format         the requested format
     * - array<string, mixed>  $context        the serialization context
     */
    public function withMaxDepthHandler(?callable $maxDepthHandler) : static {
        return $this->with(AbstractObjectNormalizer::MAX_DEPTH_HANDLER, $maxDepthHandler);
    }
    
    /**
     * Configures which context key are not relevant to determine which attributes
     * of an object to (de)normalize.
     *
     * @param list<string>|null $excludeFromCacheKeys
     */
    public function withExcludeFromCacheKeys(?array $excludeFromCacheKeys) : static {
        return $this->with(AbstractObjectNormalizer::EXCLUDE_FROM_CACHE_KEY, $excludeFromCacheKeys);
    }
    
    /**
     * Configures whether to tell the denormalizer to also populate existing objects on
     * attributes of the main object.
     *
     * Setting this to true is only useful if you also specify the root object
     * in AbstractNormalizer::OBJECT_TO_POPULATE.
     */
    public function withDeepObjectToPopulate(?bool $deepObjectToPopulate) : static {
        return $this->with(AbstractObjectNormalizer::DEEP_OBJECT_TO_POPULATE, $deepObjectToPopulate);
    }
    
    /**
     * Configures whether an empty object should be kept as an object (in
     * JSON: {}) or converted to a list (in JSON: []).
     */
    public function withPreserveEmptyObjects(?bool $preserveEmptyObjects) : static {
        return $this->with(AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS, $preserveEmptyObjects);
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary
AbstractNormalizerContextBuilder::withAllowExtraAttributes public function If AbstractNormalizer::ATTRIBUTES are specified, and the source has fields that are not part of that list,
configures whether to ignore those attributes or throw an ExtraAttributesException.
AbstractNormalizerContextBuilder::withAttributes public function Configures attributes to (de)normalize.
AbstractNormalizerContextBuilder::withCallbacks public function Configures an hashmap of field name =&gt; callable to normalize this field.
AbstractNormalizerContextBuilder::withCircularReferenceHandler public function Configures an handler to call when a circular reference has been detected.
AbstractNormalizerContextBuilder::withCircularReferenceLimit public function Configures how many loops of circular reference to allow while normalizing.
AbstractNormalizerContextBuilder::withDefaultConstructorArguments public function Configures a hashmap of classes containing hashmaps of constructor argument =&gt; default value.
AbstractNormalizerContextBuilder::withDefaultContructorArguments Deprecated public function
AbstractNormalizerContextBuilder::withGroups public function Configures groups containing attributes to (de)normalize.
AbstractNormalizerContextBuilder::withIgnoredAttributes public function Configures attributes to be skipped when normalizing an object tree.
AbstractNormalizerContextBuilder::withObjectToPopulate public function Configures an object to be updated instead of creating a new instance.
AbstractNormalizerContextBuilder::withRequireAllProperties public function Configures requiring all properties to be listed in the input instead
of falling back to null for nullable ones.
AbstractObjectNormalizerContextBuilder::withDeepObjectToPopulate public function Configures whether to tell the denormalizer to also populate existing objects on
attributes of the main object.
AbstractObjectNormalizerContextBuilder::withDepthKeyPattern public function Configures a pattern to keep track of the current depth.
AbstractObjectNormalizerContextBuilder::withDisableTypeEnforcement public function Configures whether verifying types match during denormalization.
AbstractObjectNormalizerContextBuilder::withEnableMaxDepth public function Configures whether to respect the max depth metadata on fields.
AbstractObjectNormalizerContextBuilder::withExcludeFromCacheKeys public function Configures which context key are not relevant to determine which attributes
of an object to (de)normalize.
AbstractObjectNormalizerContextBuilder::withMaxDepthHandler public function Configures a callback to allow to set a value for an attribute when the max depth has
been reached.
AbstractObjectNormalizerContextBuilder::withPreserveEmptyObjects public function Configures whether an empty object should be kept as an object (in
JSON: {}) or converted to a list (in JSON: []).
AbstractObjectNormalizerContextBuilder::withSkipNullValues public function Configures whether fields with the value `null` should be output during normalization.
AbstractObjectNormalizerContextBuilder::withSkipUninitializedValues public function Configures whether uninitialized typed class properties should be excluded during normalization.
ContextBuilderTrait::$context private property
ContextBuilderTrait::toArray public function
ContextBuilderTrait::with protected function
ContextBuilderTrait::withContext public function
RSS feed
Powered by Drupal