Skip to content

Commit

Permalink
Merge branch 'release/4.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
lindyhopchris committed Nov 26, 2024
2 parents 5a3d177 + a319386 commit 37c4734
Show file tree
Hide file tree
Showing 19 changed files with 83 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [8.2, 8.3]
php: [8.2, 8.3, 8.4]
laravel: [11]

steps:
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file. This projec

## Unreleased

## [4.3.0] - 2024-11-26

### Added

- [#19](https://github.com/laravel-json-api/core/pull/19) The `Authorizer` contract now allows all methods to return a
`bool` or an authorizer response.

### Fixed

- Removed deprecation notices in PHP 8.4.

## [4.2.0] - 2024-08-21

### Added
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"require": {
"php": "^8.2",
"ext-json": "*",
"illuminate/auth": "^11.33",
"illuminate/contracts": "^11.0",
"illuminate/http": "^11.0",
"illuminate/support": "^11.0"
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
failOnWarning="true"
failOnDeprecation="true"
failOnNotice="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
>
<coverage/>
<testsuites>
Expand Down
41 changes: 21 additions & 20 deletions src/Contracts/Auth/Authorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace LaravelJsonApi\Contracts\Auth;

use Illuminate\Auth\Access\Response;
use Illuminate\Http\Request;

interface Authorizer
Expand All @@ -20,93 +21,93 @@ interface Authorizer
*
* @param Request $request
* @param string $modelClass
* @return bool
* @return bool|Response
*/
public function index(Request $request, string $modelClass): bool;
public function index(Request $request, string $modelClass): bool|Response;

/**
* Authorize the store controller action.
*
* @param Request $request
* @param string $modelClass
* @return bool
* @return bool|Response
*/
public function store(Request $request, string $modelClass): bool;
public function store(Request $request, string $modelClass): bool|Response;

/**
* Authorize the show controller action.
*
* @param Request $request
* @param object $model
* @return bool
* @return bool|Response
*/
public function show(Request $request, object $model): bool;
public function show(Request $request, object $model): bool|Response;

/**
* Authorize the update controller action.
*
* @param object $model
* @param Request $request
* @return bool
* @return bool|Response
*/
public function update(Request $request, object $model): bool;
public function update(Request $request, object $model): bool|Response;

/**
* Authorize the destroy controller action.
*
* @param Request $request
* @param object $model
* @return bool
* @return bool|Response
*/
public function destroy(Request $request, object $model): bool;
public function destroy(Request $request, object $model): bool|Response;

/**
* Authorize the show-related controller action.
*
* @param Request $request
* @param object $model
* @param string $fieldName
* @return bool
* @return bool|Response
*/
public function showRelated(Request $request, object $model, string $fieldName): bool;
public function showRelated(Request $request, object $model, string $fieldName): bool|Response;

/**
* Authorize the show-relationship controller action.
*
* @param Request $request
* @param object $model
* @param string $fieldName
* @return bool
* @return bool|Response
*/
public function showRelationship(Request $request, object $model, string $fieldName): bool;
public function showRelationship(Request $request, object $model, string $fieldName): bool|Response;

/**
* Authorize the update-relationship controller action.
*
* @param Request $request
* @param object $model
* @param string $fieldName
* @return bool
* @return bool|Response
*/
public function updateRelationship(Request $request, object $model, string $fieldName): bool;
public function updateRelationship(Request $request, object $model, string $fieldName): bool|Response;

/**
* Authorize the attach-relationship controller action.
*
* @param Request $request
* @param object $model
* @param string $fieldName
* @return bool
* @return bool|Response
*/
public function attachRelationship(Request $request, object $model, string $fieldName): bool;
public function attachRelationship(Request $request, object $model, string $fieldName): bool|Response;

/**
* Authorize the detach-relationship controller action.
*
* @param Request $request
* @param object $model
* @param string $fieldName
* @return bool
* @return bool|Response
*/
public function detachRelationship(Request $request, object $model, string $fieldName): bool;
public function detachRelationship(Request $request, object $model, string $fieldName): bool|Response;
}
2 changes: 1 addition & 1 deletion src/Contracts/Schema/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function uriType(): string;
* @param bool|null $secure
* @return string
*/
public function url($extra = [], bool $secure = null): string;
public function url($extra = [], ?bool $secure = null): string;

/**
* Do resources of this type have a `self` link?
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/Server/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ public function authorizable(): bool;
* @param bool|null $secure
* @return string
*/
public function url($extra = [], bool $secure = null): string;
public function url($extra = [], ?bool $secure = null): string;
}
39 changes: 20 additions & 19 deletions src/Core/Auth/Authorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace LaravelJsonApi\Core\Auth;

use Illuminate\Contracts\Auth\Access\Gate;
use Illuminate\Auth\Access\Response;
use Illuminate\Http\Request;
use LaravelJsonApi\Contracts\Auth\Authorizer as AuthorizerContract;
use LaravelJsonApi\Contracts\Schema\Schema;
Expand Down Expand Up @@ -47,10 +48,10 @@ public function __construct(Gate $gate, JsonApiService $service)
/**
* @inheritDoc
*/
public function index(Request $request, string $modelClass): bool
public function index(Request $request, string $modelClass): bool|Response
{
if ($this->mustAuthorize()) {
return $this->gate->check(
return $this->gate->inspect(
'viewAny',
$modelClass
);
Expand All @@ -62,10 +63,10 @@ public function index(Request $request, string $modelClass): bool
/**
* @inheritDoc
*/
public function store(Request $request, string $modelClass): bool
public function store(Request $request, string $modelClass): bool|Response
{
if ($this->mustAuthorize()) {
return $this->gate->check(
return $this->gate->inspect(
'create',
$modelClass
);
Expand All @@ -77,10 +78,10 @@ public function store(Request $request, string $modelClass): bool
/**
* @inheritDoc
*/
public function show(Request $request, object $model): bool
public function show(Request $request, object $model): bool|Response
{
if ($this->mustAuthorize()) {
return $this->gate->check(
return $this->gate->inspect(
'view',
$model
);
Expand All @@ -92,10 +93,10 @@ public function show(Request $request, object $model): bool
/**
* @inheritDoc
*/
public function update(Request $request, object $model): bool
public function update(Request $request, object $model): bool|Response
{
if ($this->mustAuthorize()) {
return $this->gate->check(
return $this->gate->inspect(
'update',
$model
);
Expand All @@ -107,10 +108,10 @@ public function update(Request $request, object $model): bool
/**
* @inheritDoc
*/
public function destroy(Request $request, object $model): bool
public function destroy(Request $request, object $model): bool|Response
{
if ($this->mustAuthorize()) {
return $this->gate->check(
return $this->gate->inspect(
'delete',
$model
);
Expand All @@ -122,10 +123,10 @@ public function destroy(Request $request, object $model): bool
/**
* @inheritDoc
*/
public function showRelated(Request $request, object $model, string $fieldName): bool
public function showRelated(Request $request, object $model, string $fieldName): bool|Response
{
if ($this->mustAuthorize()) {
return $this->gate->check(
return $this->gate->inspect(
'view' . Str::classify($fieldName),
$model
);
Expand All @@ -137,18 +138,18 @@ public function showRelated(Request $request, object $model, string $fieldName):
/**
* @inheritDoc
*/
public function showRelationship(Request $request, object $model, string $fieldName): bool
public function showRelationship(Request $request, object $model, string $fieldName): bool|Response
{
return $this->showRelated($request, $model, $fieldName);
}

/**
* @inheritDoc
*/
public function updateRelationship(Request $request, object $model, string $fieldName): bool
public function updateRelationship(Request $request, object $model, string $fieldName): bool|Response
{
if ($this->mustAuthorize()) {
return $this->gate->check(
return $this->gate->inspect(
'update' . Str::classify($fieldName),
[$model, $this->createRelation($request, $fieldName)]
);
Expand All @@ -160,10 +161,10 @@ public function updateRelationship(Request $request, object $model, string $fiel
/**
* @inheritDoc
*/
public function attachRelationship(Request $request, object $model, string $fieldName): bool
public function attachRelationship(Request $request, object $model, string $fieldName): bool|Response
{
if ($this->mustAuthorize()) {
return $this->gate->check(
return $this->gate->inspect(
'attach' . Str::classify($fieldName),
[$model, $this->createRelation($request, $fieldName)]
);
Expand All @@ -175,10 +176,10 @@ public function attachRelationship(Request $request, object $model, string $fiel
/**
* @inheritDoc
*/
public function detachRelationship(Request $request, object $model, string $fieldName): bool
public function detachRelationship(Request $request, object $model, string $fieldName): bool|Response
{
if ($this->mustAuthorize()) {
return $this->gate->check(
return $this->gate->inspect(
'detach' . Str::classify($fieldName),
[$model, $this->createRelation($request, $fieldName)]
);
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Document/JsonApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class JsonApi implements Serializable
* @param string|null $version
* @return JsonApi
*/
public static function make(string $version = null): self
public static function make(?string $version = null): self
{
return new self($version);
}
Expand Down Expand Up @@ -113,7 +113,7 @@ public static function nullable($value): ?self
*
* @param string|null $version
*/
public function __construct(string $version = null)
public function __construct(?string $version = null)
{
$this->version = $version ?: null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Document/LinkHref.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function cast($value): self
* @param string $uri
* @param iterable|null $query
*/
public function __construct(string $uri, iterable $query = null)
public function __construct(string $uri, ?iterable $query = null)
{
if (empty($uri)) {
throw new UnexpectedValueException('Expecting a non-empty string URI.');
Expand Down
6 changes: 3 additions & 3 deletions src/Core/Exceptions/JsonApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class JsonApiException extends Exception implements HttpExceptionInterface, Resp
* @param Throwable|null $previous
* @return static
*/
public static function make($errors, Throwable $previous = null): self
public static function make($errors, ?Throwable $previous = null): self
{
return new self($errors, $previous);
}
Expand All @@ -50,7 +50,7 @@ public static function make($errors, Throwable $previous = null): self
* @param Throwable|null $previous
* @return static
*/
public static function error($error, Throwable $previous = null): self
public static function error($error, ?Throwable $previous = null): self
{
return new self(Error::cast($error), $previous);
}
Expand All @@ -62,7 +62,7 @@ public static function error($error, Throwable $previous = null): self
* @param Throwable|null $previous
* @param array $headers
*/
public function __construct($errors, Throwable $previous = null, array $headers = [])
public function __construct($errors, ?Throwable $previous = null, array $headers = [])
{
parent::__construct('JSON:API error', 0, $previous);
$this->errors = ErrorList::cast($errors);
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Json/Hash.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function cast($value): self
*
* @param array|null $value
*/
public function __construct(array $value = null)
public function __construct(?array $value = null)
{
$this->value = $value ?: [];
}
Expand Down
Loading

0 comments on commit 37c4734

Please sign in to comment.