Skip to content

Commit 18a8e4a

Browse files
committed
Merge branch 'develop' into next
2 parents 0f63280 + 9a53997 commit 18a8e4a

File tree

18 files changed

+98
-70
lines changed

18 files changed

+98
-70
lines changed

.github/workflows/tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
fail-fast: true
1616
matrix:
17-
php: [8.2, 8.3]
17+
php: [8.2, 8.3, 8.4]
1818
laravel: [11]
1919

2020
steps:

CHANGELOG.md

+25
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,31 @@ All notable changes to this project will be documented in this file. This projec
1818

1919
## Unreleased
2020

21+
## [5.0.0] - 2024-11-29
22+
23+
### Added
24+
25+
- **BREAKING**: [#21](https://github.com/laravel-json-api/core/pull/21) The `Authorizer` contract now allows all methods
26+
to return a `bool` or an Illuminate authorization response.
27+
28+
## [4.3.1] - 2024-11-29
29+
30+
### Fixed
31+
32+
- Reverted [#19](https://github.com/laravel-json-api/core/pull/19) as the changes were breaking, so should not have been
33+
released as a minor version.
34+
35+
## [4.3.0] - 2024-11-26
36+
37+
### Added
38+
39+
- [#19](https://github.com/laravel-json-api/core/pull/19) The `Authorizer` contract now allows all methods to return a
40+
`bool` or an authorizer response.
41+
42+
### Fixed
43+
44+
- Removed deprecation notices in PHP 8.4.
45+
2146
## [4.2.0] - 2024-08-21
2247

2348
### Added

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"require": {
2626
"php": "^8.2",
2727
"ext-json": "*",
28-
"illuminate/auth": "^11.0",
28+
"illuminate/auth": "^11.33",
2929
"illuminate/contracts": "^11.0",
3030
"illuminate/http": "^11.0",
3131
"illuminate/pipeline": "^11.0",
@@ -47,8 +47,8 @@
4747
},
4848
"extra": {
4949
"branch-alias": {
50-
"dev-develop": "4.x-dev",
51-
"dev-next": "5.x-dev"
50+
"dev-develop": "5.x-dev",
51+
"dev-next": "6.x-dev"
5252
}
5353
},
5454
"minimum-stability": "stable",

phpunit.xml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
failOnWarning="true"
1414
failOnDeprecation="true"
1515
failOnNotice="true"
16+
displayDetailsOnTestsThatTriggerDeprecations="true"
1617
>
1718
<coverage/>
1819
<testsuites>

src/Contracts/Auth/Authorizer.php

+21-20
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace LaravelJsonApi\Contracts\Auth;
1313

14+
use Illuminate\Auth\Access\Response;
1415
use Illuminate\Auth\Access\AuthorizationException;
1516
use Illuminate\Auth\AuthenticationException;
1617
use Illuminate\Http\Request;
@@ -25,95 +26,95 @@ interface Authorizer
2526
*
2627
* @param Request|null $request
2728
* @param string $modelClass
28-
* @return bool
29+
* @return bool|Response
2930
*/
30-
public function index(?Request $request, string $modelClass): bool;
31+
public function index(?Request $request, string $modelClass): bool|Response;
3132

3233
/**
3334
* Authorize a JSON:API store operation.
3435
*
3536
* @param Request|null $request
3637
* @param string $modelClass
37-
* @return bool
38+
* @return bool|Response
3839
*/
39-
public function store(?Request $request, string $modelClass): bool;
40+
public function store(?Request $request, string $modelClass): bool|Response;
4041

4142
/**
4243
* Authorize a JSON:API show query.
4344
*
4445
* @param Request|null $request
4546
* @param object $model
46-
* @return bool
47+
* @return bool|Response
4748
*/
48-
public function show(?Request $request, object $model): bool;
49+
public function show(?Request $request, object $model): bool|Response;
4950

5051
/**
5152
* Authorize the update controller action.
5253
*
5354
* @param object $model
5455
* @param Request $request
55-
* @return bool
56+
* @return bool|Response
5657
*/
57-
public function update(Request $request, object $model): bool;
58+
public function update(Request $request, object $model): bool|Response;
5859

5960
/**
6061
* Authorize the destroy controller action.
6162
*
6263
* @param Request $request
6364
* @param object $model
64-
* @return bool
65+
* @return bool|Response
6566
*/
66-
public function destroy(Request $request, object $model): bool;
67+
public function destroy(Request $request, object $model): bool|Response;
6768

6869
/**
6970
* Authorize the show-related controller action.
7071
*
7172
* @param Request $request
7273
* @param object $model
7374
* @param string $fieldName
74-
* @return bool
75+
* @return bool|Response
7576
*/
76-
public function showRelated(Request $request, object $model, string $fieldName): bool;
77+
public function showRelated(Request $request, object $model, string $fieldName): bool|Response;
7778

7879
/**
7980
* Authorize the show-relationship controller action.
8081
*
8182
* @param Request $request
8283
* @param object $model
8384
* @param string $fieldName
84-
* @return bool
85+
* @return bool|Response
8586
*/
86-
public function showRelationship(Request $request, object $model, string $fieldName): bool;
87+
public function showRelationship(Request $request, object $model, string $fieldName): bool|Response;
8788

8889
/**
8990
* Authorize the update-relationship controller action.
9091
*
9192
* @param Request $request
9293
* @param object $model
9394
* @param string $fieldName
94-
* @return bool
95+
* @return bool|Response
9596
*/
96-
public function updateRelationship(Request $request, object $model, string $fieldName): bool;
97+
public function updateRelationship(Request $request, object $model, string $fieldName): bool|Response;
9798

9899
/**
99100
* Authorize the attach-relationship controller action.
100101
*
101102
* @param Request $request
102103
* @param object $model
103104
* @param string $fieldName
104-
* @return bool
105+
* @return bool|Response
105106
*/
106-
public function attachRelationship(Request $request, object $model, string $fieldName): bool;
107+
public function attachRelationship(Request $request, object $model, string $fieldName): bool|Response;
107108

108109
/**
109110
* Authorize the detach-relationship controller action.
110111
*
111112
* @param Request $request
112113
* @param object $model
113114
* @param string $fieldName
114-
* @return bool
115+
* @return bool|Response
115116
*/
116-
public function detachRelationship(Request $request, object $model, string $fieldName): bool;
117+
public function detachRelationship(Request $request, object $model, string $fieldName): bool|Response;
117118

118119
/**
119120
* Get JSON:API errors describing the failure, or throw an appropriate exception.

src/Contracts/Schema/Schema.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function repository(): ?Repository;
4343
* @param bool|null $secure
4444
* @return string
4545
*/
46-
public function url($extra = [], bool $secure = null): string;
46+
public function url($extra = [], ?bool $secure = null): string;
4747

4848
/**
4949
* Do resources of this type have a `self` link?

src/Contracts/Server/Server.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,5 @@ public function authorizable(): bool;
9090
* @param bool|null $secure
9191
* @return string
9292
*/
93-
public function url($extra = [], bool $secure = null): string;
93+
public function url($extra = [], ?bool $secure = null): string;
9494
}

src/Core/Auth/Authorizer.php

+20-19
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Illuminate\Auth\AuthenticationException;
1616
use Illuminate\Contracts\Auth\Access\Gate;
1717
use Illuminate\Contracts\Auth\Guard;
18+
use Illuminate\Auth\Access\Response;
1819
use Illuminate\Http\Request;
1920
use LaravelJsonApi\Contracts\Auth\Authorizer as AuthorizerContract;
2021
use LaravelJsonApi\Contracts\Schema\Schema;
@@ -41,10 +42,10 @@ public function __construct(
4142
/**
4243
* @inheritDoc
4344
*/
44-
public function index(?Request $request, string $modelClass): bool
45+
public function index(?Request $request, string $modelClass): bool|Response
4546
{
4647
if ($this->mustAuthorize()) {
47-
return $this->gate->check(
48+
return $this->gate->inspect(
4849
'viewAny',
4950
$modelClass
5051
);
@@ -56,10 +57,10 @@ public function index(?Request $request, string $modelClass): bool
5657
/**
5758
* @inheritDoc
5859
*/
59-
public function store(?Request $request, string $modelClass): bool
60+
public function store(?Request $request, string $modelClass): bool|Response
6061
{
6162
if ($this->mustAuthorize()) {
62-
return $this->gate->check(
63+
return $this->gate->inspect(
6364
'create',
6465
$modelClass
6566
);
@@ -71,10 +72,10 @@ public function store(?Request $request, string $modelClass): bool
7172
/**
7273
* @inheritDoc
7374
*/
74-
public function show(?Request $request, object $model): bool
75+
public function show(?Request $request, object $model): bool|Response
7576
{
7677
if ($this->mustAuthorize()) {
77-
return $this->gate->check(
78+
return $this->gate->inspect(
7879
'view',
7980
$model
8081
);
@@ -86,10 +87,10 @@ public function show(?Request $request, object $model): bool
8687
/**
8788
* @inheritDoc
8889
*/
89-
public function update(Request $request, object $model): bool
90+
public function update(Request $request, object $model): bool|Response
9091
{
9192
if ($this->mustAuthorize()) {
92-
return $this->gate->check(
93+
return $this->gate->inspect(
9394
'update',
9495
$model
9596
);
@@ -101,10 +102,10 @@ public function update(Request $request, object $model): bool
101102
/**
102103
* @inheritDoc
103104
*/
104-
public function destroy(Request $request, object $model): bool
105+
public function destroy(Request $request, object $model): bool|Response
105106
{
106107
if ($this->mustAuthorize()) {
107-
return $this->gate->check(
108+
return $this->gate->inspect(
108109
'delete',
109110
$model
110111
);
@@ -116,10 +117,10 @@ public function destroy(Request $request, object $model): bool
116117
/**
117118
* @inheritDoc
118119
*/
119-
public function showRelated(Request $request, object $model, string $fieldName): bool
120+
public function showRelated(Request $request, object $model, string $fieldName): bool|Response
120121
{
121122
if ($this->mustAuthorize()) {
122-
return $this->gate->check(
123+
return $this->gate->inspect(
123124
'view' . Str::classify($fieldName),
124125
$model
125126
);
@@ -131,18 +132,18 @@ public function showRelated(Request $request, object $model, string $fieldName):
131132
/**
132133
* @inheritDoc
133134
*/
134-
public function showRelationship(Request $request, object $model, string $fieldName): bool
135+
public function showRelationship(Request $request, object $model, string $fieldName): bool|Response
135136
{
136137
return $this->showRelated($request, $model, $fieldName);
137138
}
138139

139140
/**
140141
* @inheritDoc
141142
*/
142-
public function updateRelationship(Request $request, object $model, string $fieldName): bool
143+
public function updateRelationship(Request $request, object $model, string $fieldName): bool|Response
143144
{
144145
if ($this->mustAuthorize()) {
145-
return $this->gate->check(
146+
return $this->gate->inspect(
146147
'update' . Str::classify($fieldName),
147148
[$model, $this->createRelation($request, $fieldName)]
148149
);
@@ -154,10 +155,10 @@ public function updateRelationship(Request $request, object $model, string $fiel
154155
/**
155156
* @inheritDoc
156157
*/
157-
public function attachRelationship(Request $request, object $model, string $fieldName): bool
158+
public function attachRelationship(Request $request, object $model, string $fieldName): bool|Response
158159
{
159160
if ($this->mustAuthorize()) {
160-
return $this->gate->check(
161+
return $this->gate->inspect(
161162
'attach' . Str::classify($fieldName),
162163
[$model, $this->createRelation($request, $fieldName)]
163164
);
@@ -169,10 +170,10 @@ public function attachRelationship(Request $request, object $model, string $fiel
169170
/**
170171
* @inheritDoc
171172
*/
172-
public function detachRelationship(Request $request, object $model, string $fieldName): bool
173+
public function detachRelationship(Request $request, object $model, string $fieldName): bool|Response
173174
{
174175
if ($this->mustAuthorize()) {
175-
return $this->gate->check(
176+
return $this->gate->inspect(
176177
'detach' . Str::classify($fieldName),
177178
[$model, $this->createRelation($request, $fieldName)]
178179
);

src/Core/Document/JsonApi.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class JsonApi implements Serializable
3434
* @param string|null $version
3535
* @return JsonApi
3636
*/
37-
public static function make(string $version = null): self
37+
public static function make(?string $version = null): self
3838
{
3939
return new self($version);
4040
}
@@ -113,7 +113,7 @@ public static function nullable($value): ?self
113113
*
114114
* @param string|null $version
115115
*/
116-
public function __construct(string $version = null)
116+
public function __construct(?string $version = null)
117117
{
118118
$this->version = $version ?: null;
119119
}

src/Core/Document/LinkHref.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static function cast($value): self
5656
* @param string $uri
5757
* @param iterable|null $query
5858
*/
59-
public function __construct(string $uri, iterable $query = null)
59+
public function __construct(string $uri, ?iterable $query = null)
6060
{
6161
if (empty($uri)) {
6262
throw new UnexpectedValueException('Expecting a non-empty string URI.');

src/Core/Exceptions/JsonApiException.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class JsonApiException extends Exception implements HttpExceptionInterface, Resp
3838
* @param Throwable|null $previous
3939
* @return static
4040
*/
41-
public static function make($errors, Throwable $previous = null): self
41+
public static function make($errors, ?Throwable $previous = null): self
4242
{
4343
return new self($errors, $previous);
4444
}
@@ -50,7 +50,7 @@ public static function make($errors, Throwable $previous = null): self
5050
* @param Throwable|null $previous
5151
* @return static
5252
*/
53-
public static function error($error, Throwable $previous = null): self
53+
public static function error($error, ?Throwable $previous = null): self
5454
{
5555
return new self(Error::cast($error), $previous);
5656
}
@@ -62,7 +62,7 @@ public static function error($error, Throwable $previous = null): self
6262
* @param Throwable|null $previous
6363
* @param array $headers
6464
*/
65-
public function __construct($errors, Throwable $previous = null, array $headers = [])
65+
public function __construct($errors, ?Throwable $previous = null, array $headers = [])
6666
{
6767
parent::__construct('JSON:API error', 0, $previous);
6868
$this->errors = ErrorList::cast($errors);

0 commit comments

Comments
 (0)