8000 Merge branch 'hotfix/0.10.1' · tooshay/laravel-json-api@fa9ef7c · GitHub
[go: up one dir, main page]

Skip to content

Commit fa9ef7c

Browse files
committed
Merge branch 'hotfix/0.10.1'
2 parents 3fec745 + 54e06bc commit fa9ef7c

File tree

5 files changed

+57
-2
lines changed

5 files changed

+57
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
All notable changes to this project will be documented in this file. This project adheres to
33
[Semantic Versioning](http://semver.org/) and [this changelog format](http://keepachangelog.com/).
44

5+
## [0.10.1] - 2017-08-15
6+
7+
### Fixed
8+
- [#88] Fixed fatal error caused when resolving request objects out of the service container when there was no
9+
inbound request bound in the service container.
10+
511
## [0.10.0] - 2017-07-29
612

713
### Added

src/ServiceProvider.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ protected function bindInboundRequest()
215215
});
216216

217217
$this->app->bind(DocumentInterface::class, function () {
218-
if (!$document = json_api_request()->getDocument()) {
218+
if (!$request = json_api_request()) {
219+
throw new RuntimeException('No inbound JSON API request.');
220+
}
221+
222+
if (!$document = $request->getDocument()) {
219223
throw new RuntimeException('No request document on inbound JSON API request.');
220224
}
221225

src/Services/JsonApiService.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ public function request()
8383
return $this->container->make('json-api.request');
8484
}
8585

86+
/**
87+
* @return RequestInterface
88+
*/
89+
public function requestOrFail()
90+
{
91+
if (!$request = $this->request()) {
92+
throw new RuntimeException('No inbound JSON API request.');
93+
}
< 8000 /td>94+
95+
return $request;
96+
}
97+
8698
/**
8799
* Get the API that is handling the inbound HTTP request.
88100
*

stubs/eloquent/adapter.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Adapter extends EloquentAdapter
2424
/**
2525
* @param Builder $query
2626
* @param Collection $filters
27-
* @return mixed
27+
* @return void
2828
*/
2929
protected function filter(Builder $query, Collection $filters)
3030
{

tests/Integration/ServicesTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace CloudCreativity\LaravelJsonApi\Tests\Integration;
4+
5+
use CloudCreativity\JsonApi\Contracts\Object\DocumentInterface;
6+
use CloudCreativity\JsonApi\Contracts\Object\RelationshipInterface;
7+
use CloudCreativity\JsonApi\Contracts\Object\ResourceObjectInterface;
8+
use CloudCreativity\JsonApi\Exceptions\RuntimeException;
9+
10+
class ServicesTest extends TestCase
11+
{
12+
13+
/**
14+
* @see Issue 88
15+
*/
16+
public function testDocumentWithoutInboundRequest()
17+
{
18+
$this->expectException(RuntimeException::class);
19+
app(DocumentInterface::class);
20+
}
21+
22+
public function testResourceObjectWithoutInboundRequest()
23+
{
24+
$this->expectException(RuntimeException::class);
25+
app(ResourceObjectInterface::class);
26+
}
27+
28+
public function testRelationshipObjectWithoutInboundRequest()
29+
{
30+
$this->expectException(RuntimeException::class);
31+
app(RelationshipInterface::class);
32+
}
33+
}

0 commit comments

Comments
 (0)
0