8000 Merge branch 'release/2.0.0-beta.2' · ollivr/laravel-json-api@1028133 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1028133

Browse files
committed
Merge branch 'release/2.0.0-beta.2'
2 parents 8a2cbfb + 6e7b6a3 commit 1028133

File tree

11 files changed

+218
-137
lines changed

11 files changed

+218
-137
lines changed

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@ language: php
22
dist: trusty
33
sudo: false
44

5-
env:
6-
global:
7-
- PHPUNIT_VERSION=^8.0
8-
95
matrix:
106
include:
117
- php: "7.2"
128
env:
139
- LARAVEL_VERSION=^7.0
10+
- PHPUNIT_VERSION=^8.0
1411
- php: "7.3"
1512
env:
1613
- LARAVEL_VERSION=^7.0
14+
- PHPUNIT_VERSION=^9.0
1715
- php: "7.4"
1816
env:
1917
- LARAVEL_VERSION=^7.0
18+
- PHPUNIT_VERSION=^9.0
2019

2120
install:
2221
- composer require "laravel/framework:${LARAVEL_VERSION}" --no-update -n

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
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+
## [2.0.0-beta.2] - 2020-04-12
6+
7+
### Changed
8+
- Refactored API configuration to reduce constructor arguments in the API class.
9+
- Updated UUID dependency so that version 3 and 4 are allowed.
10+
11+
### Fixed
12+
- [#498](https://github.com/cloudcreativity/laravel-json-api/issues/498)
13+
Update exception parser interface to type-hint a `Throwable` instance instead of an
14+
`Exception`.
15+
516
## [2.0.0-beta.1] - 2020-03-04
617

718
### Added

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@
3333
"illuminate/support": "^7.0",
3434
"neomerx/json-api": "^1.0.3",
3535
"nyholm/psr7": "^1.2",
36-
"ramsey/uuid": "^3.0",
36+
"ramsey/uuid": "^3.0|^4.0",
3737
"symfony/psr-http-message-bridge": "^2.0"
3838
},
3939
"require-dev": {
4040
"ext-sqlite3": "*",
41-
"cloudcreativity/json-api-testing": "^2.1",
41+
"cloudcreativity/json-api-testing": "^3.0",
4242
"guzzlehttp/guzzle": "^6.3",
4343
"laravel/ui": "^2.0",
4444
"mockery/mockery": "^1.1",
4545
"orchestra/testbench": "^5.0",
46-
"phpunit/phpunit": "^8.0"
46+
"phpunit/phpunit": "^9.0"
4747
},
4848
"suggest": {
4949
"cloudcreativity/json-api-testing": "Required to use the test helpers."

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Introduction
22

3-
Add [jsonapi.org](http://jsonapi.org) compliant APIs to your Laravel 5 application.
3+
Add [jsonapi.org](http://jsonapi.org) compliant APIs to your Laravel application.
44
Based on the framework agnostic packages [neomerx/json-api](https://github.com/neomerx/json-api) and
55
[cloudcreativity/json-api](https://github.com/cloudcreativity/json-api).
66

docs/installation.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ Install using [Composer](http://getcomposer.org):
44

55
```bash
66
$ composer require cloudcreativity/laravel-json-api
7-
$ composer require --dev "cloudcreativity/json-api-testing:^1.2|^2.0"
7+
$ composer require --dev "cloudcreativity/json-api-testing"
88
```
99

1010
This package's service provider and facade will be automatically added using package discovery. You will
1111
then need to check your API route prefix and update your Exception handler as follows...
1212

13+
Please find a compatibility matrix between Laravel and Laravel JSON API version in
14+
[project's readme on GitHub](https://github.com/cloudcreativity/laravel-json-api#laravel-versions).
15+
1316
## Route Prefixes
1417

1518
The default Laravel installation has an `api` prefix for API routes. If you want to register your JSON API
16-
routes in your `routes/api.php` file, you will need to remove the prefix from the `mapApiRoutes()` method in your
19+
routes in your `routes/api.php` file, you will need to remove the prefix from the `mapApiRoutes()` method in your
1720
`RouteServiceProvider`.
1821

1922
For example, change this:
@@ -99,7 +102,7 @@ class Handler extends ExceptionHandler
99102

100103
// do standard exception rendering here...
101104
}
102-
105+
103106
protected function prepareException(Exception $e)
104107
{
105108
if ($e instanceof JsonApiException) {

src/Api/Api.php

Lines changed: 38 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -60,34 +60,24 @@ class Api
6060
private $name;
6161

6262
/**
63-
* @var EncodingList
64-
*/
65-
private $encodings;
66-
67-
/**
68-
* @var DecodingList
69-
*/
70-
private $decodings;
71-
72-
/**
73-
* @var bool
63+
* @var Url
7464
*/
75-
private $useEloquent;
65+
private $url;
7666

7767
/**
78-
* @var Url
68+
* @var Config
7969
*/
80-
private $url;
70+
private $config;
8171

8272
/**
83-
* @var Jobs
73+
* @var EncodingList|null
8474
*/
85-
private $jobs;
75+
private $encodings;
8676

8777
/**
88-
* @var string|null
78+
* @var DecodingList|null
8979
*/
90-
private $supportedExt;
80+
private $decodings;
9181

9282
/**
9383
* @var ContainerInterface|null
@@ -104,71 +94,27 @@ class Api
10494
*/
10595
private $responses;
10696

107-
/**
108-
* @var array
109-
*/
110-
private $providers;
111-
112-
/**
113-
* @var string|null
114-
*/
115-
private $connection;
116-
117-
/**
118-
* @var bool
119-
*/
120-
private $transactions;
121-
122-
/**
123-
* @var string|null
124-
*/
125-
private $modelNamespace;
126-
12797
/**
12898
* Api constructor.
12999
*
130100
* @param Factory $factory
131101
* @param AggregateResolver $resolver
132-
* @param $apiName
133-
* @param EncodingList $encodings
134-
* @param DecodingList $decodings
102+
* @param string $name
135103
* @param Url $url
136-
* @param Jobs $jobs
137-
* @param bool $useEloquent
138-
* @param string|null $supportedExt
139-
* @param array $providers
140-
* @param string|null $connection
141-
* @param bool $transactions
142-
* @param string|null $modelNamespace
104+
* @param Config $config
143105
*/
144106
public function __construct(
145107
Factory $factory,
146108
AggregateResolver $resolver,
147-
$apiName,
148-
EncodingList $encodings,
149-
DecodingList $decodings,
109+
string $name,
150110
Url $url,
151-
Jobs $jobs,
152-
$useEloquent = true,
153-
$supportedExt = null,
154-
array $providers = [],
155-
string $connection = null,
156-
bool $transactions = true,
157-
string $modelNamespace = null
111+
Config $config
158112
) {
159113
$this->factory = $factory;
160114
$this->resolver = $resolver;
161-
$this->name = $apiName;
162-
$this->encodings = $encodings;
163-
$this->decodings = $decodings;
115+
$this->name = $name;
164116
$this->url = $url;
165-
$this->jobs = $jobs;
166-
$this->useEloquent = $useEloquent;
167-
$this->supportedExt = $supportedExt;
168-
$this->providers = $providers;
169-
$this->connection = $connection;
170-
$this->transactions = $transactions;
171-
$this->modelNamespace = $modelNamespace;
117+
$this->config = $config;
172118
}
173119

174120
/**
@@ -223,7 +169,7 @@ public function getName()
223169
*/
224170
public function isEloquent()
225171
{
226-
return $this->useEloquent;
172+
return $this->config->useEloquent();
227173
}
228174

229175
/**
@@ -239,7 +185,7 @@ public function getUrl()
239185
*/
240186
public function getJobs()
241187
{
242-
return $this->jobs;
188+
return Jobs::fromArray($this->config->jobs());
243189
}
244190

245191
/**
@@ -271,27 +217,38 @@ public function getStore()
271217
*/
272218
public function getSupportedExtensions()
273219
{
274-
if (!$this->supportedExt) {
275-
return null;
220+
if ($ext = $this->config->supportedExt()) {
221+
return $this->factory->createSupportedExtensions($ext);
276222
}
277223

278-
return $this->factory->createSupportedExtensions($this->supportedExt);
224+
return null;
279225
}
280226

281227
/**
282228
* @return EncodingList
283229
*/
284230
public function getEncodings(): EncodingList
285231
{
286-
return $this->encodings;
232+
if ($this->encodings) {
233+
return $this->encodings;
234+
}
235+
236+
return $this->encodings = EncodingList::fromArray(
237+
$this->config->encoding(),
238+
$this->url->toString()
239+
);
287240
}
288241

289242
/**
290243
* @return DecodingList
291244
*/
292245
public function getDecodings(): DecodingList
293246
{
294-
return $this->decodings;
247+
if ($this->decodings) {
248+
return $this->decodings;
249+
}
250+
251+
return $this->decodings = DecodingList::fromArray($this->config->decoding());
295252
}
296253

297254
/**
@@ -303,8 +260,8 @@ public function getDefaultCodec(): Codec
303260
{
304261
return $this->factory->createCodec(
305262
$this->getContainer(),
306-
$this->encodings->find(MediaTypeInterface::JSON_API_MEDIA_TYPE) ?: Encoding::jsonApi(),
307-
$this->decodings->find(MediaTypeInterface::JSON_API_MEDIA_TYPE)
263+
$this->getEncodings()->find(MediaTypeInterface::JSON_API_MEDIA_TYPE) ?: Encoding::jsonApi(),
264+
$this->getDecodings()->find(MediaTypeInterface::JSON_API_MEDIA_TYPE)
308265
);
309266
}
310267

@@ -329,7 +286,7 @@ public function getResponses()
329286
*/
330287
public function getConnection(): ?string
331288
{
332-
return $this->connection;
289+
return $this->config->dbConnection();
333290
}
334291

335292
/**
@@ -339,7 +296,7 @@ public function getConnection(): ?string
339296
*/
340297
public function hasTransactions(): bool
341298
{
342-
return $this->transactions;
299+
return $this->config->dbTransactions();
343300
}
344301

345302
/**
@@ -356,7 +313,7 @@ public function exceptions(): ExceptionParserInterface
356313
*/
357314
public function getModelNamespace(): ?string
358315
{
359-
return $this->modelNamespace;
316+
return $this->config->modelNamespace();
360317
}
361318

362319
/**
@@ -438,7 +395,7 @@ public function providers(): ResourceProviders
438395
{
439396
return new ResourceProviders(
440397
$this->factory,
441-
$this->providers
398+
$this->config->providers()
442399
);
443400
}
444401

0 commit comments

Comments
 (0)
0