function Serializer::__construct

Same name in this branch
  1. 9 core/modules/rest/src/Plugin/views/style/Serializer.php \Drupal\rest\Plugin\views\style\Serializer::__construct()
Same name in other branches
  1. 8.9.x core/modules/jsonapi/src/Serializer/Serializer.php \Drupal\jsonapi\Serializer\Serializer::__construct()
  2. 8.9.x core/modules/rest/src/Plugin/views/style/Serializer.php \Drupal\rest\Plugin\views\style\Serializer::__construct()
  3. 10 core/modules/jsonapi/src/Serializer/Serializer.php \Drupal\jsonapi\Serializer\Serializer::__construct()
  4. 10 core/modules/rest/src/Plugin/views/style/Serializer.php \Drupal\rest\Plugin\views\style\Serializer::__construct()
  5. 11.x core/modules/jsonapi/src/Serializer/Serializer.php \Drupal\jsonapi\Serializer\Serializer::__construct()
  6. 11.x core/modules/rest/src/Plugin/views/style/Serializer.php \Drupal\rest\Plugin\views\style\Serializer::__construct()

File

core/modules/jsonapi/src/Serializer/Serializer.php, line 35

Class

Serializer
Overrides the Symfony serializer to cordon off our incompatible normalizers.

Namespace

Drupal\jsonapi\Serializer

Code

public function __construct(array $normalizers = [], array $encoders = []) {
    foreach ($normalizers as $normalizer) {
        if (strpos(get_class($normalizer), 'Drupal\\jsonapi\\Normalizer') !== 0) {
            throw new \LogicException('JSON:API does not allow adding more normalizers!');
        }
    }
    parent::__construct($normalizers, $encoders);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.