Download the PHP package fab2s/dt0 without Composer

On this page you can find all versions of the php package fab2s/dt0. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package dt0

Dt0

CI QA codecov PHPStan Latest Stable Version Total Downloads PRs Welcome License

Immutable PHP DTOs with bidirectional casting. No framework required. ~8x faster than the alternative.

Dt0 (DeeTO) is a PHP 8.1+ Data Transfer Object implementation that uses native readonly properties for true immutability. One #[Cast] attribute handles input transformation, output formatting, defaults, and property renaming. Compiled once per class, fast always.

Quick Start

Installation

For Laravel model casting integration, see laravel-dt0.

Why Dt0

Creating Instances

Method Input On Failure
make(...$args) Named/positional args Throws
fromArray(array) Associative array Throws
fromJson(string) JSON string Throws
fromGz(string) Gzipped JSON Throws
from(mixed) Array, JSON, or Dt0 Throws
tryFrom(mixed) Array, JSON, or Dt0 Returns null

Custom constructors with promoted properties are supported. See Creating Instances for constructors, new vs factory methods, and edge cases.

Casting

Dt0 supports bidirectional casting: transform values on the way in (hydration) and out (serialization).

Class-level casting with #[Casts]:

Built-in types — Enums and nested Dt0 classes are handled automatically, no caster needed:

Available Casters

Caster Description
ScalarCaster Cast to int, float, bool, string
JsonCaster Decode JSON on input, encode on output
TrimCaster Trim strings (ltrim, rtrim, custom characters)
Base64Caster Decode base64 on input, encode on output
DateTimeCaster Parse to DateTime or DateTimeImmutable
DateTimeFormatCaster Format DateTime for output
CarbonCaster Parse to Carbon (requires nesbot/carbon)
Dt0Caster Cast to nested Dt0 instances
ArrayOfCaster Cast typed arrays (Dt0, Enum, or scalar)
ClassCaster Instantiate arbitrary classes
MathCaster Precision numbers (requires fab2s/math)
CasterCollection Chain multiple casters in a pipeline

See Casters Documentation for detailed usage, bidirectional casting, and custom casters.

Validation

Dt0 provides standalone validation powered by Laravel's validation engine — no Laravel framework required. In Laravel applications, it auto-detects the framework and uses Laravel's validator transparently.

Requires illuminate/validation and illuminate/translation (v11+):

Rules can be defined at three levels with clear priority: property #[Rule] > class #[Rules] > #[Validate] rules. The ValidatorInterface is open for custom implementations.

See Validation Documentation for locale configuration, custom translations, and custom validators.

Output

Output Filtering

Declarative output control with #[With] is also supported. See Output Documentation for details.

Immutable Operations

Property Renaming

Map between external names (APIs, databases) and internal property names:

All renameTo values are automatically added to renameFrom, ensuring round-trip consistency.

Default Values

Resolution order: provided value > Cast default > nullable default > promoted parameter default.

Attribute Inheritance

Dt0 resolves attributes up the parent class chain — both property-level and class-level:

See Inheritance Documentation for multi-level inheritance, class attribute inheritance, and override patterns.

Performance

Reflection and attribute metadata compiled once per class, per process. Subsequent instantiations reuse cached data with zero reflection overhead.

Benchmarks

Dt0 vs spatie/laravel-data (PHP 8.4, 10,000 iterations)

Operation Dt0 spatie/laravel-data Speedup
Simple DTO (8 props, 5 casts) 141.6 µs 1,158 µs ~8.2x faster
Complex DTO (nested + arrays) 741.9 µs 3,628 µs ~4.9x faster
Round-trip (json->dto->json) 248.4 µs 2,004 µs ~8.1x faster

Repeated serialization (same instance):

Operation Dt0 spatie/laravel-data Speedup
toArray() (simple) 3.6 µs 679.4 µs ~188.7x faster
toArray() (nested) 3.6 µs 2,056 µs ~571.1x faster
toJson() 2.8 µs 681.8 µs ~243.5x faster

Output caching delivers 188-571x improvements when serializing the same instance multiple times (API + logging, event sourcing, queue + monitoring, caching layers).

Extending

Dt0's attributes, casters, and validators are extensible. See Extending Documentation for interfaces, abstract classes, and compiled metadata access.

Exceptions

All exceptions extend ContextException with structured context for debugging:

Exception Usage
Dt0Exception General DTO errors (missing properties, invalid input)
CasterException Casting failures
AttributeException Attribute configuration errors

Requirements

Dependencies

Optional

Contributing

Contributions are welcome. Please open issues and submit pull requests.

License

Dt0 is open-sourced software licensed under the MIT license.


All versions of dt0 with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-zlib Version *
fab2s/context-exception Version ^2.0|^3.0
fab2s/enumerate Version ^0.0.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package fab2s/dt0 contains the following files

Loading the files please wait ...