Skip to content

Commit d54843f

Browse files
author
Harlan Wilton
committed
Merge branch 'feature/laravel-7' of github.com:dingo/api into feat/laravel-7-support
2 parents 5fe4ed6 + 1ff4d3a commit d54843f

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

src/Exception/Handler.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
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 Exception;
13+
use Illuminate\Contracts\Debug\ExceptionHandler as IlluminateExceptionHandler;
14+
use Illuminate\Http\Response;
15+
use Illuminate\Support\Str;
1316
use Illuminate\Validation\ValidationException;
17+
use ReflectionFunction;
1418
use Symfony\Component\Console\Output\OutputInterface;
1519
use Symfony\Component\HttpFoundation\Response as BaseResponse;
16-
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1720
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
18-
use Illuminate\Contracts\Debug\ExceptionHandler as IlluminateExceptionHandler;
21+
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1922
use Throwable;
2023

2124
class Handler implements ExceptionHandler, IlluminateExceptionHandler
@@ -161,11 +164,11 @@ public function handle($exception)
161164
$response = new Response($response, $this->getExceptionStatusCode($exception));
162165
}
163166

164-
return $response;
167+
return $response->withException($exception);
165168
}
166169
}
167170

168-
return $this->genericResponse($exception);
171+
return $this->genericResponse($exception)->withException($exception);
169172
}
170173

171174
/**

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: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
namespace Dingo\Api\Tests\Exception;
44

5-
use Mockery as m;
6-
use RuntimeException;
7-
use Illuminate\Http\Response;
8-
use PHPUnit\Framework\TestCase;
95
use Dingo\Api\Exception\Handler;
6+
use Dingo\Api\Exception\ResourceException;
7+
use Dingo\Api\Http\Request as ApiRequest;
108
use Illuminate\Http\JsonResponse;
119
use Illuminate\Http\RedirectResponse;
12-
use Dingo\Api\Http\Request as ApiRequest;
13-
use Dingo\Api\Exception\ResourceException;
10+
use Illuminate\Http\Response;
11+
use Mockery as m;
12+
use PHPUnit\Framework\TestCase;
13+
use RuntimeException;
1414
use Symfony\Component\HttpKernel\Exception\HttpException;
1515

1616
class HandlerTest extends TestCase
@@ -55,6 +55,7 @@ public function testExceptionHandlerHandlesException()
5555

5656
$this->assertSame('foo', $response->getContent());
5757
$this->assertSame(404, $response->getStatusCode());
58+
$this->assertSame($exception, $response->exception);
5859
}
5960

6061
public function testExceptionHandlerHandlesExceptionAndCreatesNewResponse()
@@ -142,6 +143,7 @@ public function testRegularExceptionsAreHandledByGenericHandler()
142143

143144
$this->assertSame('{"message":"Uh oh","status_code":500}', $response->getContent());
144145
$this->assertSame(500, $response->getStatusCode());
146+
$this->assertSame($exception, $response->exception);
145147
}
146148

147149
public function testResourceExceptionErrorsAreIncludedInResponse()

0 commit comments

Comments
 (0)