A PHP 8.5+ DTO and Data library with immutable DTOs and mutable Data objects

Maintainers

Package info

github.com/jooservices/dto

pkg:composer/jooservices/dto

Statistics

Installs: 63

Dependents: 2

Suggesters: 0

Stars: 0

Open Issues: 2

1.0.3 2026-04-02 05:35 UTC

README

codecov CI OpenSSF Scorecard PHP Version License: MIT Packagist Version

The JOOservices DTO Library is a PHP 8.5+ library for constructor-based DTO hydration, mutable data objects, opt-in validation, serialization control, and DTO collection wrappers.

Package name: jooservices/dto

Install

composer require jooservices/dto

Quick example

use DateTimeImmutable;
use JOOservices\Dto\Attributes\MapFrom;
use JOOservices\Dto\Core\Dto;

final class UserDto extends Dto
{
    public function __construct(
        public readonly string $id,
        #[MapFrom('email_address')]
        public readonly string $email,
        public readonly DateTimeImmutable $createdAt,
    ) {}
}

$user = UserDto::from([
    'id' => 'u_123',
    'email_address' => 'john@example.com',
    'createdAt' => '2026-01-15T10:30:00+00:00',
]);

$payload = $user->toArray();

What is supported today

  • Dto and Data
  • hydration from arrays, JSON strings, and simple public-property objects
  • scalar, enum, and DateTimeInterface casting
  • nested single DTO hydration
  • opt-in validation with attributes
  • serialization filtering and wrapping
  • lazy derived serialization through ComputesLazyProperties
  • DataCollection and PaginatedCollection

Important current limitations

  • typed DTO arrays are not inferred from PHPDoc
  • several declared attributes are not wired into the runtime yet, including Pipeline, StrictType, and DiscriminatorMap
  • Data::update() and Data::set() do not re-run casting or validation

Documentation

Start with:

AI Support

This repository includes an AI skill pack for agents working in Cursor, Claude Code, VS Code, JetBrains, and Antigravity.

Start with:

The canonical skill source lives in .github/skills/, with adapter layers for each supported AI environment.

Development

composer lint:all
composer test

Contributor workflow details live in:

GitHub Actions and Services

Current GitHub Actions coverage:

  • CI: security checks, linting, tests, coverage upload
  • Release: validate tags, create GitHub releases, trigger Packagist update
  • PR Labeler: apply labels to pull requests
  • Semantic PR Title: enforce pull request title format
  • OpenSSF Scorecard: publish scorecard results as SARIF
  • Secret Scanning: workflow file exists, but the gitleaks job is currently disabled

External services currently used by workflows:

Important notes:

  • No workflow currently defines Docker-style services: containers such as MySQL, Redis, or PostgreSQL.
  • The SonarCloud workflow step is currently commented out, so the old Sonar badge has been removed from this README.

License

This project is licensed under the MIT License.