/**
  * Process transform object response
  *
  * @param ObjectTransformableResponse $objectResponse
  *
  * @return Response
  */
 private function doTransformObjectResponse(ObjectTransformableResponse $objectResponse)
 {
     $responseData = $objectResponse;
     if ($objectResponse->isActionTransform()) {
         try {
             $responseData = $this->transformerManager->transform($responseData->getObject(), $objectResponse->getTransformerContext());
             if (!is_object($responseData)) {
                 throw UnexpectedTypeException::create($responseData, 'object');
             }
         } catch (TransformerUnsupportedObjectException $e) {
             throw new \RuntimeException(sprintf('Can not transform object with class "%s".', get_class($objectResponse)), 0, $e);
         }
     }
     try {
         $responseData = $this->normalizerManager->normalize($responseData instanceof ObjectTransformableResponse ? $responseData->getObject() : $responseData, $objectResponse->getNormalizerContext());
         if (!is_array($responseData)) {
             throw UnexpectedTypeException::create($responseData, 'array');
         }
     } catch (NormalizerUnsupportedObjectException $e) {
         throw new \RuntimeException(sprintf('Can not normalize object with class "%s".', get_class($responseData)), 0, $e);
     }
     if ($objectResponse->isEmptyResponse()) {
         $response = new EmptyResponse($responseData, $objectResponse->getHttpStatusCode());
     } else {
         $response = new Response($responseData, $objectResponse->getHttpStatusCode());
     }
     return $response;
 }
 /**
  * {@inheritdoc}
  */
 public function transform($object, ContextInterface $context)
 {
     if (!$object instanceof \Traversable) {
         throw UnsupportedClassException::create($object);
     }
     if (!$object instanceof \ArrayAccess) {
         throw new UnsupportedClassException(sprintf('The collection object for transform should implement \\ArrayAccess, %s given.', get_class($object)));
     }
     // Try crete a new collection
     try {
         $transformed = $this->createCollection($object);
     } catch (\Exception $e) {
         throw new UnsupportedClassException(sprintf('Could not create new collection instance with class "%s" (Use constructor).', get_class($object)), 0, $e);
     }
     // Try get a child context
     $childContext = $context->getAttribute('child_context', null);
     foreach ($object as $key => $child) {
         $transformed[$key] = $this->manager->transform($child, $childContext);
     }
     return $transformed;
 }
 /**
  * Transform value
  *
  * @param object              $object
  * @param mixed               $value
  * @param PropertyMetadata    $metadata
  * @param \ReflectionProperty $property
  *
  * @return mixed
  *
  * @throws TransformationFailedException
  */
 protected function transformValue($object, $value, PropertyMetadata $metadata, \ReflectionProperty $property)
 {
     // Check, if should use expression language for get value
     if ($metadata->getExpressionValue()) {
         if (!$this->expressionLanguage) {
             throw new \LogicException('Can not evaluate expression language. Please inject ExpressionLanguage to transformer.');
         }
         $attributes = ['object' => $object, 'value' => $value];
         $value = $this->expressionLanguage->evaluate($metadata->getExpressionValue(), $attributes);
     }
     // Check, if should use transformer for this value (recursive) and value is not null
     if ($metadata->isShouldTransform() && $value !== null) {
         if (!is_object($value)) {
             throw new TransformationFailedException(sprintf('Can not transform property "%s" in class "%s". The value must be a object, but "%s" given.', $property->getName(), $property->getDeclaringClass()->getName(), gettype($value)));
         }
         return $this->transformerManager->transform($value);
     }
     return $value;
 }