Skip to content

Commit

Permalink
Merge branch '8.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed Aug 23, 2024
2 parents e8a65ca + b804330 commit b328b76
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Abstracts/Transformers/Transformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/Traits/CanEagerLoadTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Str;

/**
* @internal
*/
trait CanEagerLoadTrait
{
/**
Expand Down
7 changes: 5 additions & 2 deletions src/Traits/HasResourceKeyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
36 changes: 29 additions & 7 deletions src/Traits/ResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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,
Expand Down Expand Up @@ -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
{
Expand All @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit b328b76

Please sign in to comment.