Provides a foundation for data transfer objects in PHP applications. Built with support for ArrayAccess, JsonSerializable interfaces and hydration provided by our dependency injection container.

Maintainers

Package info

github.com/WebdevCave/dto-php

pkg:composer/webdevcave/dto

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0 2026-05-06 19:59 UTC

This package is auto-updated.

Last update: 2026-05-06 20:01:51 UTC


README

Provides a foundation for data transfer objects in PHP applications. Built with support for ArrayAccess, JsonSerializable interfaces and hydration provided by our dependency injection container (webdevcave/yadic).

Requirements

Installation

Using composer:

composer require webdevcave/dto

Usage example

Extend the DataTransferObject class and define your properties. You can use the from() method to hydrate the DTO from an array.

use Webdevcave\DTO\DataTransferObject;

class UserDTO extends DataTransferObject
{
    public string $name;
    public string $email;
}

// Hydrating from array
$data = ['name' => 'John Doe', 'email' => 'john@example.com'];
$user = UserDTO::from($data);

echo $user->name; // John Doe

// ArrayAccess
echo $user['email']; // john@example.com

// JSON Serialization
echo json_encode($user);

Scripts

The following scripts are available via Composer:

  • composer test: Run the tests
  • composer test-coverage: Run the tests with coverage (requires Xdebug)
  • composer check-coverage: Check the coverage

Tests

The project uses PHPUnit for testing. You can run the tests using:

composer test

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or a pull request on GitHub.

License

This project is licensed under the MIT License - see the LICENSE file for details.