@param mixed  $collection
@param string $class
@param string $name
@param string $format
@param array  $context

@return mixed|object
961053
protected function denormalizeCollection($collection, $class, $name, $format = null, array $context = array())
    {
        /** @var ClassMetadata $meta */
        $meta = $context['entityMeta'];

        $targetEntity = $meta->associationMappings[$name]['targetEntity'];

        $result = array();
        foreach ($collection as $key => $element) {
            $class = $class ?: $targetEntity;

            $result[$key] = $this->denormalizeAssociation($element, $class, $name, $format, $context);
        }

        return $result;
    }
414966
public function denormalize($data, $class, $format = null, array $context = [])
    {
        $resolver = new OptionsResolver();
        $this->configureDenormalizeOptions($resolver);
        $options = $resolver->resolve(array_key_exists(self::OPTION_KEY, $context) ? $context[self::OPTION_KEY] : []);

        $entityManager = $this->doctrine->getManagerForClass($class);
        if (!$entityManager instanceof EntityManagerInterface) {
            throw new \UnexpectedValueException("No manager found for class {$class}");
        }
        $repository = $entityManager->getRepository($class);

        if (empty($data)) {
            return null;
        }

        if (is_scalar($data)) {
            // Test base identifier
            /** @var ResourceInterface $resource */
            $resource = $repository->find($data);
            if (null === $resource) {
                $resource = $repository->findOneBy(['path' => $data]);
            }
            if ($resource) {
                return $resource;
            }

            return $this->uploadFile($data, $class, $options);
        }

        /** @noinspection PhpIncompatibleReturnTypeInspection */

        return parent::denormalize($data, $class, $format, $context);
    }
422533
protected function denormalizeProperty($data, $class, $name, $format = null, array $context = array())
    {
        if (!($_class = $this->getClassFromArray($data))) {
            return parent::denormalizeProperty($data, $class, $name, $format, $context);
        }

        $class = $_class;
        if (!$this->serializer instanceof DenormalizerInterface) {
            $message = 'Cannot denormalize attribute "%s" because injected serializer is not a denormalizer';
            throw new RuntimeException(sprintf($message, $name));
        }

        return $this->serializer->denormalize($data, $class, $format, $context);
    }
946073
function fetchCollection($class_name = "stdClass")
    {
        /* backward compatibility, you can use object instead of class name */
        if (is_object($class_name)) {
            $class_name = get_class($class_name);
        }

        return $this->fetchAll(DB::FETCH_CLASS, $class_name);
    }
1051219
public function normalize($object, $format = null, array $context = [])
    {
        if (null !== $outputClass = $this->getOutputClass($this->getObjectClass($object), $context)) {
            return parent::normalize($object, $format, $context);
        }

        $data = parent::normalize($object, $format, $context);
        if (!\is_array($data)) {
            throw new UnexpectedValueException('Expected data to be an array');
        }

        $data[self::ITEM_RESOURCE_CLASS_KEY] = $this->getObjectClass($object);
        $data[self::ITEM_IDENTIFIERS_KEY] = $this->identifiersExtractor->getIdentifiersFromItem($object);

        return $data;
    }
476824
public function normalize($object, $format = null, array $context = [])
    {
        $normalized = ['errors' => []];

        foreach ($object as $innerError) {
            $normalized['errors'][] = $this->normalizer->normalize($innerError, $format, $context);
        }

        $normalized = $this->appendCollectionAttributes($normalized, $object, (string) $format, $context);

        return $normalized;
    }
999317
private function resolveCollection(\ArrayIterator $tokens, Type $classType, Context $context)
    {
        $isArray = ('array' === (string) $classType);

        // allow only "array" or class name before "<"
        if (!$isArray
            && (! $classType instanceof Object_ || $classType->getFqsen() === null)) {
            throw new \RuntimeException(
                $classType . ' is not a collection'
            );
        }

        $tokens->next();

        $valueType = $this->parseTypes($tokens, $context, self::PARSER_IN_COLLECTION_EXPRESSION);
        $keyType = null;

        if ($tokens->current() !== null && trim($tokens->current()) === ',') {
            // if we have a comma, then we just parsed the key type, not the value type
            $keyType = $valueType;
            if ($isArray) {
                // check the key type for an "array" collection. We allow only
                // strings or integers.
                if (! $keyType instanceof String_ &&
                    ! $keyType instanceof Integer &&
                    ! $keyType instanceof Compound
                ) {
                    throw new \RuntimeException(
                        'An array can have only integers or strings as keys'
                    );
                }

                if ($keyType instanceof Compound) {
                    foreach ($keyType->getIterator() as $item) {
                        if (! $item instanceof String_ &&
                            ! $item instanceof Integer
                        ) {
                            throw new \RuntimeException(
                                'An array can have only integers or strings as keys'
                            );
                        }
                    }
                }
            }

            $tokens->next();
            // now let's parse the value type
            $valueType = $this->parseTypes($tokens, $context, self::PARSER_IN_COLLECTION_EXPRESSION);
        }

        if ($tokens->current() !== '>') {
            if (empty($tokens->current())) {
                throw new \RuntimeException(
                    'Collection: ">" is missing'
                );
            }

            throw new \RuntimeException(
                'Unexpected character "' . $tokens->current() . '", ">" is missing'
            );
        }

        if ($isArray) {
            return new Array_($valueType, $keyType);
        }

        if ($classType instanceof Object_) {
            return $this->makeCollectionFromObject($classType, $valueType, $keyType);
        }
    }
809720
protected function denormalizeProperty($value, $class, $name, $format = null, array $context = array())
    {
        /** @var ClassMetadata $meta */
        $meta = $context['entityMeta'];

        if ($meta->hasField($name)) {
            return $value;
        }

        if (isset($meta->embeddedClasses[$name])) {
            return parent::denormalize($value, null, $format, $context);
        }

        if (!isset($meta->associationMappings[$name])) {
            return parent::denormalizeProperty($value, $class, $name, $format, $context);
        }

        switch ($meta->associationMappings[$name]['type']) {
            case ClassMetadata::ONE_TO_ONE:
            case ClassMetadata::MANY_TO_ONE:
                return $this->denormalizeAssociation($value, null, $name, $format, $context);

            case ClassMetadata::ONE_TO_MANY:
            case ClassMetadata::MANY_TO_MANY:
                return $this->denormalizeCollection($value, null, $name, $format, $context);
        }
    }
131624
public function normalize($object, $format = null, array $context = [])
    {
        foreach ($this->normalizers as $normalizer) {
            // Return the result from the first denormalizer that can
            // denormalize this.
            if ($normalizer->supportsNormalization($object, $format)) {
                return $normalizer->normalize($object, $format, $context);
            }
        }
    }
1155605
public function mapCollection(\Iterator $collection, $expression = null, $context = null)
    {
        foreach ($collection as $key => $record) {
            if (!is_array($record)) {
                throw new InvalidRecordException('Record must be an array.');
            }

            yield $key => $expression !== null
                ? $this->mapMapping($record, $expression, $context, $key)
                : $record;
        }
    }
609476
protected function getShortReference($object, $format, array $context)
    {
        return [
            'code' => $object->getCode(),
            'type' => $object->getType()->getCode(),
            'collection' => $object->isCollection(),
        ];
    }
1359429
public function denormalize($data, $class, $format = null, array $context = [])
    {
        if (!preg_match('/^data:([a-z0-9][a-z0-9\!\#\$\&\-\^\_\+\.]{0,126}\/[a-z0-9][a-z0-9\!\#\$\&\-\^\_\+\.]{0,126}(;[a-z0-9\-]+\=[a-z0-9\-]+)?)?(;base64)?,[a-z0-9\!\$\&\\\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i', $data)) {
            throw new NotNormalizableValueException('The provided "data:" URI is not valid.');
        }

        try {
            switch ($class) {
                case 'Symfony\Component\HttpFoundation\File\File':
                    return new File($data, false);

                case 'SplFileObject':
                case 'SplFileInfo':
                    return new \SplFileObject($data);
            }
        } catch (\RuntimeException $exception) {
            throw new NotNormalizableValueException($exception->getMessage(), $exception->getCode(), $exception);
        }

        throw new InvalidArgumentException(sprintf('The class parameter "%s" is not supported. It must be one of "SplFileInfo", "SplFileObject" or "Symfony\Component\HttpFoundation\File\File".', $class));
    }
1149769
public function serialize($data, $format, array $context = array())
    {
        if (!isset($this->handlers[$format])) {
            throw new \BadMethodCallException(sprintf(
                'Unsupported format "%s", only [%s] are',
                $format, implode(', ', array_keys($this->handlers))
            ));
        }

        return $this->handlers[$format]->serialize(
            $data,
            empty($context['scope']) ? 'default' : $context['scope']
        );
    }
487962
public function denormalize($data, $class, $format = null, array $context = array())
    {
        if (!($_class = $this->getClassFromArray($data))) {
            return parent::denormalize($data, $class, $format, $context);
        }

        $class = $_class;

        return parent::denormalize($data, $class, $format, $context);
    }
446106
public function denormalize($data, $class, $format = null, array $context = array())
    {
        /** @var \ReflectionParameter[] $params */
        $params = $context['params'];
        $indexBy = isset($context['indexBy']) ? $context['indexBy'] : 'name';

        $arguments = [];
        foreach ($params as $param) {
            $index = $param->getPosition();

            $arguments[$index] = $this->denormalizeParam($data, $param, $format, $context);
        }
        ksort($arguments);

        $output = [];
        foreach ($params as $param) {
            $name = $param->getName();
            $index = $param->getPosition();
            $key = $indexBy === 'name' ? $name : $index;

            $output[$key] = $arguments[$index];
        }

        return $output;
    }
915421
public function getCollection($collectionClass = CreateFromAttributesInterface::class)
    {
        $collection = [];
        if ($this->isSuccessful()) {
            $data = $this->getData();
            foreach ($data as $attributes) {
                /** @var AbstractModel $collectionClass */
                $collection[] = $collectionClass::createFromAttributes($attributes);
            }
        }

        return $collection;
    }
487663
public function denormalize($data, $class, $format = null, array $context = [])
    {
        // Handle -1 in expiresAt property of AppCredential.
        if ($data < 0) {
            return null;
        }
        $context[$this->normalizer::FORMAT_KEY] = 'U';
        $context[$this->normalizer::TIMEZONE_KEY] = new \DateTimeZone('UTC');

        return $this->normalizer->denormalize(intval($data / 1000), $class, $format, $context);
    }