From 3130eb0520117b98ff62bfbb7fe1679e2a93815c Mon Sep 17 00:00:00 2001 From: Mohammad Alavi Date: Fri, 23 Aug 2024 16:25:16 +0330 Subject: [PATCH 1/4] fix(transformer): cannot set "resource key" --- src/Abstracts/Transformers/Transformer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Abstracts/Transformers/Transformer.php b/src/Abstracts/Transformers/Transformer.php index d7ac7e622..1e7e070fe 100644 --- a/src/Abstracts/Transformers/Transformer.php +++ b/src/Abstracts/Transformers/Transformer.php @@ -19,7 +19,7 @@ public function nullableItem($data, $transformer, $resourceKey = null): Primitiv return $this->primitive(null); } - return $this->item($data, $transformer, $resourceKey = null); + return $this->item($data, $transformer, $resourceKey); } public function item($data, $transformer, $resourceKey = null): Item From 0e5664195eeceeeeac6f685632cc35879cd9dbed Mon Sep 17 00:00:00 2001 From: Mohammad Alavi Date: Fri, 23 Aug 2024 16:25:58 +0330 Subject: [PATCH 2/4] docs: update docblock --- src/Traits/HasResourceKeyTrait.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Traits/HasResourceKeyTrait.php b/src/Traits/HasResourceKeyTrait.php index b39caa7d2..bee6f49ce 100644 --- a/src/Traits/HasResourceKeyTrait.php +++ b/src/Traits/HasResourceKeyTrait.php @@ -9,11 +9,14 @@ trait HasResourceKeyTrait /** * @var string|null */ - #[Deprecated(reason: 'Override the getResourceKey method in the respective model class instead of using the $resourceKey property.')] + #[Deprecated(reason: 'Override the getResourceKey method in the respective model class instead of using the $resourceKey property')] protected $resourceKey; /** - * Returns the type for JSON API Serializer. Can be overwritten with the protected $resourceKey in respective model class. + * Returns the type for JSON API Serializer. + * + * If the $resourceKey property is set, it will be used as the resource key. + * Otherwise, the class name will be used. */ public function getResourceKey(): string { From 555015e7d7bd653273d687120f5873f2b53c0c28 Mon Sep 17 00:00:00 2001 From: Mohammad Alavi Date: Fri, 23 Aug 2024 16:26:14 +0330 Subject: [PATCH 3/4] docs: mark trait as "internal" --- src/Traits/CanEagerLoadTrait.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Traits/CanEagerLoadTrait.php b/src/Traits/CanEagerLoadTrait.php index a4f151403..a0de3c225 100644 --- a/src/Traits/CanEagerLoadTrait.php +++ b/src/Traits/CanEagerLoadTrait.php @@ -8,6 +8,9 @@ use Illuminate\Support\Facades\Request; use Illuminate\Support\Str; +/** + * @internal + */ trait CanEagerLoadTrait { /** From b804330a17d561935c7e453db172ec5fb69605ca Mon Sep 17 00:00:00 2001 From: Mohammad Alavi Date: Fri, 23 Aug 2024 16:26:41 +0330 Subject: [PATCH 4/4] docs: add deprecation notice --- src/Traits/ResponseTrait.php | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/Traits/ResponseTrait.php b/src/Traits/ResponseTrait.php index 9b031c8e3..06e7b7933 100644 --- a/src/Traits/ResponseTrait.php +++ b/src/Traits/ResponseTrait.php @@ -13,6 +13,10 @@ use JetBrains\PhpStorm\Deprecated; use Spatie\Fractal\Facades\Fractal; +#[Deprecated( + reason: 'All methods in this trait are deprecated and will be removed in the next major release.', + replacement: 'Use the Response facade instead.', +)] trait ResponseTrait { protected array $metaData = []; @@ -21,8 +25,8 @@ trait ResponseTrait * @throws InvalidTransformerException */ #[Deprecated( - reason: 'This method is the cause of many bugs and its functionality is already covered by the Fractal package.', - replacement: '\Spatie\Fractal\Facades\Fractal::create(%parameter0%,%parameter1%)->parseIncludes(%parameter2%)->addMeta(%parameter3%)->toArray();', + reason: 'This method is the cause of many bugs and its functionality is already covered by the Response facade. Use the Response facade instead.', + replacement: '\Apiato\Core\Facades\Response::createFrom(%parameter0%,%parameter1%)->parseIncludes(%parameter2%)->addMeta(%parameter3%)->toArray();', )] public function transform( $data, @@ -126,8 +130,8 @@ private function filterResponse(array $responseArray, array $filters): array } #[Deprecated( - reason: 'Its functionality is already covered by the Fractal package. Use the addMeta() method on the Fractal instance instead.', - replacement: '\Spatie\Fractal\Facades\Fractal::create()->addMeta(%parameter0%)->toArray();', + reason: 'Its functionality is already covered by the Response facade. Use the addMeta method from the Response facade instead.', + replacement: '\Apiato\Core\Facades\Response::createFrom()->addMeta(%parameter0%)->toArray();', )] public function withMeta($data): self { @@ -136,19 +140,29 @@ public function withMeta($data): self return $this; } + #[Deprecated( + reason: 'Its functionality is already covered by the Response facade. Use the toJson method from the Response facade instead.', + replacement: '\Apiato\Core\Facades\Response::createFrom(%parameter0%)->toJson();', + )] public function json($data, $status = 200, array $headers = [], $options = 0): JsonResponse { return new JsonResponse($data, $status, $headers, $options); } + #[Deprecated( + reason: 'Its functionality is already covered by the Response facade. Use the created method from the Response facade instead.', + replacement: '\Apiato\Core\Facades\Response::createFrom(%parameter0%)->created();', + )] public function created($data = null, $status = 201, array $headers = [], $options = 0): JsonResponse { return new JsonResponse($data, $status, $headers, $options); } - /** - * @throws \ReflectionException - */ + + #[Deprecated( + reason: 'Use the noContent method from the Response facade instead.', + replacement: '\Apiato\Core\Facades\Response::createFrom(%parameter0%)->noContent();', + )] public function deleted(Model|null $deletedModel = null): JsonResponse { if (!$deletedModel) { @@ -163,11 +177,19 @@ public function deleted(Model|null $deletedModel = null): JsonResponse ]); } + #[Deprecated( + reason: 'Its functionality is already covered by the Response facade. Use the accepted method from the Response facade instead.', + replacement: '\Apiato\Core\Facades\Response::createFrom(%parameter0%)->accepted();', + )] public function accepted($data = null, $status = 202, array $headers = [], $options = 0): JsonResponse { return new JsonResponse($data, $status, $headers, $options); } + #[Deprecated( + reason: 'Its functionality is already covered by the Response facade. Use the noContent method from the Response facade instead.', + replacement: '\Apiato\Core\Facades\Response::createFrom()->noContent();', + )] public function noContent($status = 204): JsonResponse { return new JsonResponse(null, $status);