Exemplo n.º 1
0
 /**
  * Builds a response
  *
  * @param array $content
  * @param int $status
  * @param array $headers
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function buildResponse($content, $status, $headers)
 {
     $encodedContent = $this->serializer->serialize($content, 'json');
     $jsonResponse = new Response($encodedContent, $status, $headers);
     $jsonResponse->headers->set('Content-Type', 'application/json');
     return $jsonResponse;
 }
 /**
  * @param \Staffim\DTOBundle\Model\ModelInterface $model
  * @param string $patchOperations
  * @return string
  * @throws \Rs\Json\Patch\FailedTestException
  */
 protected function applyPatch(ModelInterface $model, $patchOperations)
 {
     try {
         $document = $this->serializer->serialize($this->mapper->map($model), 'json', $this->serializationContext);
         $patch = new Patch($document, $patchOperations);
         return $patch->apply();
     } catch (Patch\FailedTestException $exception) {
         throw new Exception($exception->getMessage(), 417, $exception);
     } catch (Patch\Exception $exception) {
         throw new Exception($exception->getMessage(), 400, $exception);
     }
 }
Exemplo n.º 3
0
 /**
  * @param \Staffim\DTOBundle\Model\ModelInterface $model
  * @param string $patchOperations
  * @return string
  * @throws \Rs\Json\Patch\FailedTestException
  */
 protected function applyPatch(ModelInterface $model, $patchOperations)
 {
     $document = $this->serializer->serialize($this->mapper->map($model), 'json', $this->serializationContext);
     $patch = new Patch($document, $patchOperations);
     return $patch->apply();
 }