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

Breadcrumb

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

function AbstractNormalizerContextBuilder::withAttributes

Configures attributes to (de)normalize.

For nested structures, this list needs to reflect the object tree.

Eg: ['foo', 'bar', 'object' => ['baz']]

Parameters

array<string|array>|null $attributes:

Throws

InvalidArgumentException

File

vendor/symfony/serializer/Context/Normalizer/AbstractNormalizerContextBuilder.php, line 84

Class

AbstractNormalizerContextBuilder
A helper providing autocompletion for available AbstractNormalizer options.

Namespace

Symfony\Component\Serializer\Context\Normalizer

Code

public function withAttributes(?array $attributes) : static {
    $it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($attributes ?? []), \RecursiveIteratorIterator::LEAVES_ONLY);
    foreach ($it as $attribute) {
        if (!\is_string($attribute)) {
            throw new InvalidArgumentException(\sprintf('Each attribute must be a string, "%s" given.', get_debug_type($attribute)));
        }
    }
    return $this->with(AbstractNormalizer::ATTRIBUTES, $attributes);
}

API Navigation

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