Repository navigation
Payload
Pair\Data\Payload is a minimal explicit read model used mainly as a Pair v4 migration bridge.
It wraps an associative array or an ActiveRecord::toArray() result so legacy code can stop relying on implicit raw-object serialization before a proper application read model is written.
For new Pair v4 code, prefer an application-specific readonly ReadModel.
use Pair\Data\Payload;
use Pair\Http\JsonResponse;
$payload = Payload::fromArray([
'id' => 7,
'name' => 'Alice',
'meta' => ['active' => true],
]);
return new JsonResponse($payload);Payload implements ReadModel, so JsonResponse normalizes it through toArray().
use Pair\Data\Payload;
$user = new User(7);
$payload = Payload::fromRecord($user);
return \Pair\Api\ApiResponse::jsonResponse($payload->toArray());This is explicit, but it still mirrors the persistence array shape. Replace it with a real read model when the API contract is known.
The Pair v4 upgrader may add Payload::class as a conservative fallback when an existing CRUD model has no explicit read contract yet:
use Pair\Api\ApiExposable;
use Pair\Data\Payload;
use Pair\Orm\ActiveRecord;
/**
* Legacy model exposed during a staged v4 migration.
*/
final class Faq extends ActiveRecord {
use ApiExposable;
/**
* Return the temporary CRUD API contract.
*
* @return array<string, mixed>
*/
public static function apiConfig(): array {
return [
'readModel' => Payload::class,
];
}
}Treat this as a bridge. The final shape should usually be:
return [
'readModel' => FaqReadModel::class,
];-
Payload::fromArray()preserves the array as-is. -
Payload::fromRecord()delegates toActiveRecord::toArray(). -
jsonSerialize()reusestoArray()throughArraySerializableData. - Do not use
Payloadto hide unclear API contracts; use it to make an incremental migration explicit.
See also: ReadModel, RecordMapper, Upgrade-to-v4, CrudController.
Maintained by Viames Marino — VM Ingegneria · Professional enquiries
Home · Setup · Configuration
Build with Pair 4
- Generator
- Controllers and responses
- Read models
- ActiveRecord and queries
- Forms and validation
- PairUI.js, PairMotion.js and HTML fragments
APIs and authentication
- API guide and CRUD
- Middleware and rate limits
- Users, sessions, and ACL
- Passkeys and social login
- Native mobile setup
Integrate and operate
- Integrations
- Runtime extensions and adapter keys
- Cache and cache stores
- Logs and observability
- PWA and push
- Packages and distribution
- Upgrade to v4