Download the PHP package eve/dto without Composer

On this page you can find all versions of the php package eve/dto. 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 dto

eve/dto

Main Latest version

A simplistic, flexible Data Transfer Object library written in PHP.

Why?

It's arguably a common practice to pass data as associative arrays between layers. For example, a service method to create a new user may look like this:

The method can be called by e.g., a controller this way:

This kind of works, but with several drawbacks:

Now imagine instead of using an arbitrary array, we use an object with typed properties:

With this approach, we have a clear idea of what fields to expect as user creation data, their types and other restrictions, and we can enjoy all type-hinting, auto-completion, static analysis etc. This is exactly what eve/dto allows you to do.

Requirements and Installation

You can install eve/dto via Composer:

This package requires PHP ≥7.4.

Migrate from v1.x

v1.x versions of this library include a strict type check—for example, assigning a string to a boolean property will throw an error. Though certainly useful, this feature doesn't belong in the scope of a DTO and has been removed from v2. You're encouraged to use a static analysis tool like PHPStan or Psalm for the task instead.

Usage

Basic Usage

Following the example above, firstly, we make UserCreationData extends Eve\DTO\DataTransferObject and define all attributes as public properties:

To construct a new UserCreationData instance, call make with an array of parameters:

Alternatively, you can explicitly set the attributes. The code above is essentially the same as:

Or you can use the fluent set method, which can take either an associative array or two separated $name, $value parameters:

If any of the passed properties doesn't exist in the class definition, an exception will be thrown:

Then we can call the toArray() method to transform the object into an associative array:

Note that non-set properties will NOT be included in the output array:

This is especially handy e.g., if you have a method to patch a database record, as it allows the operation to be totally flexible—you can patch all properties or only a subset of them.

Nested DTOs

Nested DTOs will be transformed into their corresponding arrays:

Helper Functions

Differences from spatie/data-transfer-object

Though eve/dto is inspired by and shares some similarities with spatie/data-transfer-object, the two packages have certain differences, the most significant of which are as follows:

License

MIT


All versions of dto with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|~8
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 eve/dto contains the following files

Loading the files please wait ....