public function Serializer::__construct

Same name in this branch
  1. 8.x drupal/core/vendor/symfony/serializer/Symfony/Component/Serializer/Serializer.php \Symfony\Component\Serializer\Serializer::__construct()
  2. 8.x drupal/core/modules/rest/lib/Drupal/rest/Plugin/views/style/Serializer.php \Drupal\rest\Plugin\views\style\Serializer::__construct()

File

drupal/core/vendor/symfony/serializer/Symfony/Component/Serializer/Serializer.php, line 46

Class

Serializer
Serializer serializes and deserializes data

Namespace

Symfony\Component\Serializer

Code

public function __construct(array $normalizers = array(), array $encoders = array()) {
  foreach ($normalizers as $normalizer) {
    if ($normalizer instanceof SerializerAwareInterface) {
      $normalizer
        ->setSerializer($this);
    }
  }
  $this->normalizers = $normalizers;
  $decoders = array();
  $realEncoders = array();
  foreach ($encoders as $encoder) {
    if ($encoder instanceof SerializerAwareInterface) {
      $encoder
        ->setSerializer($this);
    }
    if ($encoder instanceof DecoderInterface) {
      $decoders[] = $encoder;
    }
    if ($encoder instanceof EncoderInterface) {
      $realEncoders[] = $encoder;
    }
  }
  $this->encoder = new ChainEncoder($realEncoders);
  $this->decoder = new ChainDecoder($decoders);
}