Skip to content

Commit

Permalink
Adding custom headers using the HalJsonResponseTrait is now possible
Browse files Browse the repository at this point in the history
  • Loading branch information
nilportugues committed Oct 20, 2015
1 parent 3dde8aa commit b4801cd
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/Serializer/HalJsonResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@

trait HalJsonResponseTrait
{
/**
* @param \Psr\Http\Message\ResponseInterface $response
* @return \Psr\Http\Message\ResponseInterface
*/
protected function addHeaders(\Psr\Http\Message\ResponseInterface $response)
{
return $response;
}

/**
* @param string $json
*
Expand All @@ -14,7 +23,7 @@ trait HalJsonResponseTrait
private function errorResponse($json)
{
return (new HttpFoundationFactory())
->createResponse(new \NilPortugues\Api\HalJson\Http\Message\ErrorResponse($json));
->createResponse($this->addHeaders(new \NilPortugues\Api\HalJson\Http\Message\ErrorResponse($json)));
}

/**
Expand All @@ -25,7 +34,7 @@ private function errorResponse($json)
private function resourceCreatedResponse($json)
{
return (new HttpFoundationFactory())
->createResponse(new \NilPortugues\Api\HalJson\Http\Message\ResourceCreatedResponse($json));
->createResponse($this->addHeaders(new \NilPortugues\Api\HalJson\Http\Message\ResourceCreatedResponse($json)));
}

/**
Expand All @@ -36,7 +45,7 @@ private function resourceCreatedResponse($json)
private function resourceDeletedResponse($json)
{
return (new HttpFoundationFactory())
->createResponse(new \NilPortugues\Api\HalJson\Http\Message\ResourceDeletedResponse($json));
->createResponse($this->addHeaders(new \NilPortugues\Api\HalJson\Http\Message\ResourceDeletedResponse($json)));
}

/**
Expand All @@ -47,7 +56,7 @@ private function resourceDeletedResponse($json)
private function resourceNotFoundResponse($json)
{
return (new HttpFoundationFactory())
->createResponse(new \NilPortugues\Api\HalJson\Http\Message\ResourceNotFoundResponse($json));
->createResponse($this->addHeaders(new \NilPortugues\Api\HalJson\Http\Message\ResourceNotFoundResponse($json)));
}

/**
Expand All @@ -58,7 +67,7 @@ private function resourceNotFoundResponse($json)
private function resourcePatchErrorResponse($json)
{
return (new HttpFoundationFactory())
->createResponse(new \NilPortugues\Api\HalJson\Http\Message\ResourcePatchErrorResponse($json));
->createResponse($this->addHeaders(new \NilPortugues\Api\HalJson\Http\Message\ResourcePatchErrorResponse($json)));
}

/**
Expand All @@ -69,7 +78,7 @@ private function resourcePatchErrorResponse($json)
private function resourcePostErrorResponse($json)
{
return (new HttpFoundationFactory())
->createResponse(new \NilPortugues\Api\HalJson\Http\Message\ResourcePostErrorResponse($json));
->createResponse($this->addHeaders(new \NilPortugues\Api\HalJson\Http\Message\ResourcePostErrorResponse($json)));
}

/**
Expand All @@ -80,7 +89,7 @@ private function resourcePostErrorResponse($json)
private function resourceProcessingResponse($json)
{
return (new HttpFoundationFactory())
->createResponse(new \NilPortugues\Api\HalJson\Http\Message\ResourceProcessingResponse($json));
->createResponse($this->addHeaders(new \NilPortugues\Api\HalJson\Http\Message\ResourceProcessingResponse($json)));
}

/**
Expand All @@ -91,7 +100,7 @@ private function resourceProcessingResponse($json)
private function resourceUpdatedResponse($json)
{
return (new HttpFoundationFactory())
->createResponse(new \NilPortugues\Api\HalJson\Http\Message\ResourceUpdatedResponse($json));
->createResponse($this->addHeaders(new \NilPortugues\Api\HalJson\Http\Message\ResourceUpdatedResponse($json)));
}

/**
Expand All @@ -102,7 +111,7 @@ private function resourceUpdatedResponse($json)
private function response($json)
{
return (new HttpFoundationFactory())
->createResponse(new \NilPortugues\Api\HalJson\Http\Message\Response($json));
->createResponse($this->addHeaders(new \NilPortugues\Api\HalJson\Http\Message\Response($json)));
}

/**
Expand All @@ -113,6 +122,6 @@ private function response($json)
private function unsupportedActionResponse($json)
{
return (new HttpFoundationFactory())
->createResponse(new \NilPortugues\Api\HalJson\Http\Message\UnsupportedActionResponse($json));
->createResponse($this->addHeaders(new \NilPortugues\Api\HalJson\Http\Message\UnsupportedActionResponse($json)));
}
}

0 comments on commit b4801cd

Please sign in to comment.