8000 Merge branch 'release/1.0.0-alpha.2' into main · siberfx/laravel-json-api@d094eb7 · GitHub
[go: up one dir, main page]

Skip to content

Commit d094eb7

Browse files
committed
Merge branch 'release/1.0.0-alpha.2' into main
2 parents 223e43c + b8cc281 commit d094eb7

23 files changed

+253
-362
lines changed

.github/workflows/tests.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
fail-fast: true
16+
matrix:
17+
php: ['7.4', '8.0']
18+
laravel: ['^8.0']
19+
20+
steps:
21+
- name: Checkout Code
22+
uses: actions/checkout@v2
23+
24+
- name: Setup PHP
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: ${{ matrix.php }}
28+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd
29+
tools: composer:v2
30+
coverage: none
31+
32+
- name: Set Laravel Version
33+
run: composer require "laravel/framework:${{ matrix.laravel }}" --no-update -n
34+
35+
- name: Install dependencies
36+
uses: nick-invision/retry@v1
37+
with:
38+
timeout_minutes: 5
39+
max_attempts: 5
40+
command: composer install --no-suggest --prefer-dist -n -o
41+
42+
- name: Execute tests
43+
run: vendor/bin/phpunit

.travis.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

CHANGELOG.md

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

6+
## [1.0.0-alpha.2] - 2021-02-02
7+
8+
### Added
9+
10+
- [#1](https://github.com/laravel-json-api/laravel/pull/1)
11+
Resource classes are now optional. If one is not defined, the implementation falls-back to using the Eloquent schema
12+
to serialize a model. Eloquent schema fields now have new
13+
`hidden` and `serializeUsing` methods to customise the serialization of models by the schema.
14+
- Resource classes now support using conditional attributes in their `meta()` method.
15+
- New field classes `ArrayList` and `ArrayHash` have been added, to distinguish between PHP zero-indexed arrays that
16+
serialize to JSON arrays (`ArrayList`) and PHP associative arrays that serialize to JSON objects (`ArrayHash`). The
17+
distinction is required because an empty array list can be serialized to `[]` in JSON whereas an empty associative
18+
array must be serialized to `null` in JSON.
19+
20+
### Changed
21+
22+
- **BREAKING** The JsonApiResource method signatures for the `attributes()`, `relationships()`,
23+
`meta()`, and `links()` methods have been changed so that they receive the HTTP request as the first (and only)
24+
parameter. This brings the implementation in line with Laravel's Eloquent resources, which receive the request to
25+
their `toArray()` method. The slight difference is our implementation allows the request to be `null` - this is to
26+
cover encoding resources outside of HTTP requests, e.g. queued broadcasting. When upgrading, you will need to either
27+
delete resource classes (as they are now optional), or update the method signatures on any classes you are retaining.
28+
29+
### Fixed
30+
31+
- [#3](https://github.com/laravel-json-api/laravel/issues/3)
32+
Example server registration in the published configuration file prevented developer from creating a `v1` server after
33+
adding this package to their Laravel application.
34+
- Package discovery for sub-packages that have service providers now works correctly.
35+
36+
### Removed
37+
38+
- **BREAKING** The `Arr` schema field has been removed - use the new `ArrayList` or `ArrayHash`
39+
fields instead.
40+
- **BREAKING** The `uri` method on resource and relationship routes has been removed:
41+
- The resource type URI can now be set on the resource's schema (using the `$uriType` property).
42+
- Relationship URIs are now set on the schema field for the relationship (via the `withUriFieldName` method).
43+
644
## [1.0.0-alpha.1] - 2021-01-25
745

846
Initial release.

composer.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525
"require": {
2626
"php": "^7.4|^8.0",
2727
"ext-json": "*",
28-
"laravel-json-api/core": "^1.0.0-alpha.1",
29-
"laravel-json-api/eloquent": "^1.0.0-alpha.1",
30-
"laravel-json-api/encoder-neomerx": "^1.0.0-alpha.1",
28+
"laravel-json-api/core": "^1.0.0-alpha.2",
29+
"laravel-json-api/eloquent": "^1.0.0-alpha.2",
30+
"laravel-json-api/encoder-neomerx": "^1.0.0-alpha.2",
3131
"laravel-json-api/exceptions": "^1.0.0-alpha.1",
32-
"laravel-json-api/spec": "^1.0.0-alpha.1",
33-
"laravel-json-api/validation": "^1.0.0-alpha.1",
32+
"laravel-json-api/spec": "^1.0.0-alpha.2",
33+
"laravel-json-api/validation": "^1.0.0-alpha.2",
3434
"laravel/framework": "^8.0"
3535
},
3636
"require-dev": {
37-
"laravel-json-api/testing": "^1.0@alpha",
37+
"laravel-json-api/testing": "^1.0.0-alpha.1",
3838
"orchestra/testbench": "^6.9",
3939
"phpunit/phpunit": "^9.5"
4040
},
@@ -56,16 +56,16 @@
5656
"dev-develop": "1.x-dev"
5757
},
5858
"laravel": {
59-
"providers": [
60-
"LaravelJsonApi\\Laravel\\ServiceProvider"
61-
],
6259
"aliases": {
6360
"JsonApi": "LaravelJsonApi\\Core\\Facades\\JsonApi",
6461
"JsonApiRoute": "LaravelJsonApi\\Laravel\\Facades\\JsonApiRoute"
65-
}
62+
},
63+
"providers": [
64+
"LaravelJsonApi\\Laravel\\ServiceProvider"
65+
]
6666
}
6767
},
68-
"minimum-stability": "stable",
68+
"minimum-stability": "dev",
6969
"prefer-stable": true,
7070
"config": {
7171
"sort-packages": true

config/jsonapi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
| class name of the server class.
2828
*/
2929
'servers' => [
30-
'v1' => \App\JsonApi\V1\Server::class,
30+
// 'v1' => \App\JsonApi\V1\Server::class,
3131
],
3232
];

src/Http/Requests/ResourceRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ protected function existingAttributes(object $model): iterable
449449
{
450450
$resource = $this->resources()->create($model);
451451

452-
return $resource->attributes();
452+
return $resource->attributes($this);
453453
}
454454

455455
/**
@@ -463,7 +463,7 @@ protected function existingRelationships(object $model): iterable
463463
$resource = $this->resources()->create($model);
464464

465465
/** @var Relation $relationship */
466-
foreach ($resource->relationships() as $relationship) {
466+
foreach ($resource->relationships($this) as $relationship) {
467467
if ($relationship->isValidated()) {
468468
yield $relationship->fieldName() => $relationship->data();
469469
}

src/Routing/PendingRelationshipRegistration.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,6 @@ public function __construct(
8282
$this->options = [];
8383
}
8484

85-
/**
86-
* Set the URI for the relationship, if it is not the same as the field name.
87-
*
88-
* @param string $uri
89-
* @return $this
90-
*/
91-
public function uri(string $uri): self
92-
{
93-
$this->options['relationship_uri'] = $uri;
94-
95-
return $this;
96-
}
97-
9885
/**
9986
* Set the methods the controller should apply to.
10087
*

src/Routing/PendingResourceRegistration.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,6 @@ public function __construct(
8282
$this->options = [];
8383
}
8484

85-
/**
86-
* Set the URI for the resource type, if it is not the same as the resource type's name.
87-
*
88-
* @param string $uri
89-
* @return $this
90-
*/
91-
public function uri(string $uri): self
92-
{
93-
$this->options['resource_uri'] = $uri;
94-
95-
return $this;
96-
}
97-
9885
/**
9986
* Set the methods the controller should apply to.
10087
*

src/Routing/RelationshipRegistrar.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Illuminate\Contracts\Routing\Registrar as RegistrarContract;
2323
use Illuminate\Routing\Route as IlluminateRoute;
2424
use Illuminate\Routing\RouteCollection;
25+
use LaravelJsonApi\Contracts\Schema\Schema;
2526
use LaravelJsonApi\Core\Support\Str;
2627

2728
class RelationshipRegistrar
@@ -32,6 +33,11 @@ class RelationshipRegistrar
3233
*/
3334
private RegistrarContract $router;
3435

36+
/**
37+
* @var Schema
38+
*/
39+
private Schema $schema;
40+
3541
/**
3642
* @var string
3743
*/
@@ -51,17 +57,20 @@ class RelationshipRegistrar
5157
* RelationshipRegistrar constructor.
5258
*
5359
* @param RegistrarContract $router
60+
* @param Schema $schema
5461
* @param string $resourceType
5562
* @param string $controller
5663
* @param string $parameter
5764
*/
5865
public function __construct(
5966
RegistrarContract $router,
67+
Schema $schema,
6068
string $resourceType,
6169
string $controller,
6270
string $parameter
6371
) {
6472
$this->router = $router;
73+
$this->schema = $schema;
6574
$this->resourceType = $resourceType;
6675
$this->controller = $controller;
6776
$this->parameter = $parameter;
@@ -95,7 +104,7 @@ public function register(string $fieldName, bool $hasMany, array $options = []):
95104
*/
96105
protected function addShowRelated(string $fieldName, array $options): IlluminateRoute
97106
{
98-
$uri = $this->getRelationshipUri($fieldName, $options);
107+
$uri = $this->getRelationshipUri($fieldName);
99108
$action = $this->getRelationshipAction(
100109
'showRelated',
101110
'showRelated' . Str::classify($fieldName),
@@ -120,7 +129,7 @@ protected function addShowRelated(string $fieldName, array $options): Illuminate
120129
*/
121130
protected function addShowRelationship(string $fieldName, array $options): IlluminateRoute
122131
{
123-
$uri = $this->getRelationshipUri($fieldName, $options);
132+
$uri = $this->getRelationshipUri($fieldName);
124133
$action = $this->getRelationshipAction(
125134
'showRelationship',
126135
'show' . Str::classify($fieldName),
@@ -145,7 +154,7 @@ protected function addShowRelationship(string $fieldName, array $options): Illum
145154
*/
146155
protected function addUpdateRelationship(string $fieldName, array $options): Illuminate 10000 Route
147156
{
148-
$uri = $this->getRelationshipUri($fieldName, $options);
157+
$uri = $this->getRelationshipUri($fieldName);
149158
$action = $this->getRelationshipAction(
150159
'updateRelationship',
151160
'update' . Str::classify($fieldName),
@@ -170,7 +179,7 @@ protected function addUpdateRelationship(string $fieldName, array $options): Ill
170179
*/
171180
protected function addAttachRelationship(string $fieldName, array $options): IlluminateRoute
172181
{
173-
$uri = $this->getRelationshipUri($fieldName, $options);
182+
$uri = $this->getRelationshipUri($fieldName);
174183
$action = $this->getRelationshipAction(
175184
'attachRelationship',
176185
'attach' . Str::classify($fieldName),
@@ -195,7 +204,7 @@ protected function addAttachRelationship(string $fieldName, array $options): Ill
195204
*/
196205
protected function addDetachRelationship(string $fieldName, array $options): IlluminateRoute
197206
{
198-
$uri = $this->getRelationshipUri($fieldName, $options);
207+
$uri = $this->getRelationshipUri($fieldName);
199208
$action = $this->getRelationshipAction(
200209
'detachRelationship',
201210
'detach' . Str::classify($fieldName),
@@ -277,16 +286,11 @@ private function getRelationshipAction(
277286

278287
/**
279288
* @param string $fieldName
280-
* @param array $options
281289
* @return string
282290
*/
283-
private function getRelationshipUri(string $fieldName, array $options): string
291+
private function getRelationshipUri(string $fieldName): string
284292
{
285-
if (isset($options['relationship_uri'])) {
286-
return $options['relationship_uri'];
287-
}
288-
289-
return Str::dasherize($fieldName);
293+
return $this->schema->relationship($fieldName)->uriName();
290294
}
291295

292296
/**
< 3192 /td>

0 commit comments

Comments
 (0)
0