Download the PHP package callismart/dto without Composer
On this page you can find all versions of the php package callismart/dto. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download callismart/dto
More information about callismart/dto
Files in callismart/dto
Package dto
Short Description A flexible, extendable foundation for Data Transfer Objects (DTOs) in PHP.
License MIT
Informations about the package dto
Callismart DTO
A flexible, extensible foundation for Data Transfer Objects (DTOs) in PHP 8.1+. Build type-safe, immutable data containers with zero dependencies.
Why Callismart DTO?
DTOs are fundamental building blocks for clean architecture, but creating them usually means writing repetitive boilerplate. Callismart DTO eliminates that by providing a powerful, extensible base class that handles:
- Dynamic Properties — Add any data without declaring fields
- Type Coercion — Automatically cast values to expected types
- Validation — Enforce which keys are allowed
- Security — Mask sensitive values in debugging and serialization
- Fluent API — Chain methods for readable configuration
- Zero Dependencies — No external packages required
Perfect for APIs, configuration objects, domain models, and any data transfer scenario.
Installation
Install via Composer:
Requirements: PHP 8.1 or higher
Quick Start
Basic Usage
Creating Type-Safe Subclasses
Restrict allowed keys and apply type casting:
Core Features
Dynamic Properties
Access properties using any of three syntaxes:
Type Casting & Validation
Override cast() to enforce types and validate values:
Key Whitelisting
Restrict which keys are allowed:
Sensitive Value Masking
Protect sensitive data in debugging and serialization:
Fluent API
Chain methods for readable code:
Advanced Operations
Serialization
DTOs work with standard PHP serialization interfaces:
Debugging
API Reference
Reading
Writing
Selection
Serialization
Extension Points
Override these methods in subclasses to customize behavior:
allowed_keys()
Restrict which properties can be set:
Return empty array (default) to allow any key.
sensitive_keys()
Mark values that should be masked in output:
Sensitive values are masked as *** in:
to_array()output- JSON serialization
var_dump()outputdump()method
cast()
Transform or validate values before storage:
Can throw InvalidArgumentException for invalid values.
Examples
API Request/Response
Configuration Object
Domain Entity
Nested DTOs
Testing
Run the test suite with:
Or with PHPUnit directly:
Best Practices
- Create Typed Subclasses — Always subclass DTO for domain objects, not raw instances
- Define allowed_keys() — Restrict to prevent typos and unexpected properties
- Implement cast() — Enforce types, trim strings, validate values
- Mark sensitive_keys() — Protect passwords, tokens, API keys, etc.
- Use Fluent API — Chain methods for readable initialization
- Immutability — Once created, avoid mutating DTOs (clone if needed)
- Safe Logging — Use
dump()orto_array()for safe debug output
Performance
The DTO class is designed for performance:
- Zero Reflection — No reflection or magic used beyond
__get/__set - Direct Array Access — Internal storage is a simple array
- Minimal Overhead — Single method call for get/set operations
- Type Hints — Full type hints enable JIT compilation optimizations
Security
Sensitive value protection:
- Automatic masking in serialization and debugging
- Prevent accidental credential exposure in logs
- Safe for storing in configuration objects
- Works with any sensitive key name you define
Requirements
- PHP: 8.1 or higher
- Extensions: None required
License
MIT License. See LICENSE file for details.
Contributing
Contributions are welcome! Please ensure:
- Code follows WordPress PHP Coding Standards (K&R braces, tab indentation)
- All public methods have PHPDoc comments
- Full type hints on parameters and returns
- Tests pass with
composer test
Support
- Issues: Report bugs on GitHub
- Documentation: Check examples and API reference above
- Questions: Create a discussion on GitHub
Related Packages
- callismart/http — Lightweight HTTP client with multi-adapter support
- callismart/database — Multi-adapter database abstraction (uses this DTO for configuration)
Changelog
v1.0.0
- Initial release
- Full DTO functionality with extension hooks
- Magic property access, array access, iteration
- JSON serialization with sensitive value masking
- Fluent API with chaining
- Zero dependencies
Author
Callistus Nwachukwu - [email protected]