Skip to content
This repository has been archived by the owner on Sep 19, 2018. It is now read-only.

Commit

Permalink
Merge branch '2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
crynobone committed Aug 4, 2014
2 parents 5a34373 + 465206d commit 08b13be
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ before_script:
script: phpunit -c phpunit.xml --coverage-text

after_script:
- php vendor/bin/coveralls -v
- if [[ "$TRAVIS_PHP_VERSION" != *hhvm* ]]; then php vendor/bin/coveralls -v; fi

matrix:
allow_failures:
Expand Down
42 changes: 23 additions & 19 deletions src/Resources/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response as IlluminateResponse;
use Orchestra\Facile\Container as FacileContainer;
use Orchestra\Support\Str;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

Expand All @@ -13,17 +14,13 @@ class Response
/**
* Handle response from resources.
*
* @param mixed $content
* @param \Closure $callback
* @return mixed
* @param mixed $content
* @param \Closure|null $callback
* @return \Illuminate\Http\Response|string
*/
public function call($content, Closure $callback = null)
{
if (false === $content) {
$this->abort(404);
} elseif (is_null($content)) {
return new IlluminateResponse($content, 200);
} elseif ($content instanceof RedirectResponse || $content instanceof JsonResponse) {
if ($content instanceof RedirectResponse || $content instanceof JsonResponse) {
return $content;
} elseif ($content instanceof FacileContainer) {
return $content->render();
Expand All @@ -39,7 +36,9 @@ public function call($content, Closure $callback = null)
*
* @param \Illuminate\Http\Response $content
* @param \Closure $callback
* @return mixed
* @return \Illuminate\Http\Response|string
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
protected function handleIlluminateResponse(IlluminateResponse $content, Closure $callback = null)
{
Expand All @@ -50,24 +49,30 @@ protected function handleIlluminateResponse(IlluminateResponse $content, Closure
return $response->render();
} elseif ($this->isNoneHtmlResponse($content)) {
return $content;
} elseif (! $content->isSuccessful()) {
$this->abort($code);
} elseif ($content->isSuccessful()) {
return $this->handleResponseCallback($response, $callback);
}

return $this->handleResponseCallback($response, $callback);
return $this->abort($code);
}

/**
* Handle response callback.
*
* @param mixed $content
* @param \Closure $callback
* @param mixed $content
* @param \Closure|null $callback
* @return mixed
*/
protected function handleResponseCallback($content, Closure $callback = null)
{
if ($callback instanceof Closure) {
return call_user_func($callback, $content);
$content = call_user_func($callback, $content);
}

if (false === $content) {
return $this->abort(404);
} elseif (is_null($content)) {
return new IlluminateResponse($content, 200);
}

return $content;
Expand All @@ -80,7 +85,6 @@ protected function handleResponseCallback($content, Closure $callback = null)
* @param string $message
* @param array $headers
* @return void
*
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
Expand All @@ -97,7 +101,7 @@ protected function abort($code, $message = '', array $headers = array())
* Is response renderable.
*
* @param object|string $response
* @return boolean
* @return bool
*/
protected function isRenderableResponse($response)
{
Expand All @@ -108,12 +112,12 @@ protected function isRenderableResponse($response)
* Is response none html.
*
* @param \Illuminate\Http\Response $content
* @return boolean
* @return bool
*/
protected function isNoneHtmlResponse(IlluminateResponse $content)
{
$contentType = $content->headers->get('Content-Type');
$isHtml = starts_with($contentType, 'text/html');
$isHtml = Str::startsWith($contentType, 'text/html');

return ! is_null($content) && ! $isHtml;
}
Expand Down

0 comments on commit 08b13be

Please sign in to comment.