Skip to content

Commit 78868aa

Browse files
author
Harlan Wilton
committed
Merge branch 'feat/laravel-7-support' of github.com:loonpwn/api into feat/phpunit-8
2 parents f5b347f + 56bda8f commit 78868aa

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
}],
1515
"require": {
1616
"php": "^7.2.5",
17+
"dingo/blueprint": "^0.4",
1718
"illuminate/routing": "^5.5 || ^6.0 || ^7.0",
1819
"illuminate/support": "^5.5 || ^6.0 || ^7.0",
1920
"league/fractal": "^0.17"

src/Exception/Handler.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
use Dingo\Api\Http\Request;
66
use Exception;
77
use Illuminate\Database\Eloquent\ModelNotFoundException;
8-
use ReflectionFunction;
98
use Illuminate\Support\Str;
109
use Illuminate\Http\Response;
1110
use Dingo\Api\Contract\Debug\ExceptionHandler;
1211
use Dingo\Api\Contract\Debug\MessageBagErrors;
12+
use Illuminate\Contracts\Debug\ExceptionHandler as IlluminateExceptionHandler;
1313
use Illuminate\Validation\ValidationException;
14+
use ReflectionFunction;
1415
use Symfony\Component\Console\Output\OutputInterface;
1516
use Symfony\Component\HttpFoundation\Response as BaseResponse;
16-
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1717
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
18-
use Illuminate\Contracts\Debug\ExceptionHandler as IlluminateExceptionHandler;
18+
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1919
use Throwable;
2020

2121
class Handler implements ExceptionHandler, IlluminateExceptionHandler
@@ -161,11 +161,11 @@ public function handle($exception)
161161
$response = new Response($response, $this->getExceptionStatusCode($exception));
162162
}
163163

164-
return $response;
164+
return $response->withException($exception);
165165
}
166166
}
167167

168-
return $this->genericResponse($exception);
168+
return $this->genericResponse($exception)->withException($exception);
169169
}
170170

171171
/**

src/Http/Response/Factory.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,12 @@ public function collection(Collection $collection, $transformer, $parameters = [
123123
*/
124124
public function item($item, $transformer, $parameters = [], Closure $after = null)
125125
{
126-
$class = get_class($item);
126+
// Check for $item being null
127+
if (! is_null($item)) {
128+
$class = get_class($item);
129+
} else {
130+
$class = \StdClass::class;
131+
}
127132

128133
if ($parameters instanceof \Closure) {
129134
$after = $parameters;

src/Routing/Route.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,8 @@ public function methods()
511511
*/
512512
public function httpOnly()
513513
{
514-
return in_array('https', $this->action, true)
515-
|| (array_key_exists('https', $this->action) && $this->action['https']);
514+
return in_array('http', $this->action, true)
515+
|| (array_key_exists('http', $this->action) && $this->action['http']);
516516
}
517517

518518
/**
@@ -532,7 +532,8 @@ public function httpsOnly()
532532
*/
533533
public function secure()
534534
{
535-
return in_array('https', $this->action, true);
535+
return in_array('https', $this->action, true)
536+
|| (array_key_exists('https', $this->action) && $this->action['https']);
536537
}
537538

538539
/**

tests/Exception/HandlerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function testExceptionHandlerHandlesException()
5050

5151
$this->assertSame('foo', $response->getContent());
5252
$this->assertSame(404, $response->getStatusCode());
53+
$this->assertSame($exception, $response->exception);
5354
}
5455

5556
public function testExceptionHandlerHandlesExceptionAndCreatesNewResponse()
@@ -137,6 +138,7 @@ public function testRegularExceptionsAreHandledByGenericHandler()
137138

138139
$this->assertSame('{"message":"Uh oh","status_code":500}', $response->getContent());
139140
$this->assertSame(500, $response->getStatusCode());
141+
$this->assertSame($exception, $response->exception);
140142
}
141143

142144
public function testResourceExceptionErrorsAreIncludedInResponse()

0 commit comments

Comments
 (0)