TransformerInterface
in
Interface for transforming resources into arrays.
This interface can be implemented by classes that need to transform data into a standardized array format, such as for API responses.
Table of Contents
Methods
- toArray() : array<string, mixed>
- Converts the resource to an array representation.
- transform() : array<string, mixed>
- Transforms the given resource into an array.
- transformMany() : array<int, array<string, mixed>>
- Transforms a collection of resources using $this->transform() on each item.
Methods
toArray()
Converts the resource to an array representation.
public
toArray(mixed $resource) : array<string, mixed>
This is overridden by child classes to define specific fields.
Parameters
- $resource : mixed
-
The resource being transformed
Return values
array<string, mixed>transform()
Transforms the given resource into an array.
public
transform(array<string, mixed>|object|null $resource) : array<string, mixed>
Parameters
- $resource : array<string, mixed>|object|null
Return values
array<string, mixed>transformMany()
Transforms a collection of resources using $this->transform() on each item.
public
transformMany(array<int|string, mixed> $resources) : array<int, array<string, mixed>>
Parameters
- $resources : array<int|string, mixed>