componenta/arrayable
Composer 安装命令:
composer require componenta/arrayable
包简介
Array conversion contract for Componenta packages
README 文档
README
Minimal contract for objects that expose a public array representation.
Use it when a package needs to accept DTOs, view models, pagination results, or collections without depending on a serializer implementation.
Installation
composer require componenta/arrayable
Related Packages
| Package | Why it matters here |
|---|---|
componenta/array |
to_array() consumes Arrayable objects. |
componenta/http-responder |
Responders can turn arrayable objects into JSON responses. |
componenta/paginator |
Pagination results can expose a public array shape. |
Usage
use Componenta\Arrayable\Arrayable; final readonly class UserView implements Arrayable { public function __construct( public string $id, public string $name, ) {} public function toArray(): array { return [ 'id' => $this->id, 'name' => $this->name, ]; } }
Contract
Arrayable::toArray() returns the public array representation of an object.
The interface does not define:
- JSON encoding
- recursive conversion rules
- key naming conventions
- whether private/internal state is included
Those decisions belong to the implementing object or to a serializer package.
Typical Consumers
Packages such as paginator, iterator helpers, HTTP responders, and config exporters can depend on this contract when they only need an array shape and do not need object-specific behavior.
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 18
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-14