Download the PHP package rmezhuev/data-transfer-object without Composer

On this page you can find all versions of the php package rmezhuev/data-transfer-object. 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 data-transfer-object

Flexible Data transfer objects

Implementation of immutable Data Transfer Object (DTO) concept for safe transferring data between architecture layers of application. Like transferring data received from API to the application core. Arrays don't provide reliable mechanism for that purpose, due to the lack of strict structure, validation, type checks and immutability. Data Transfer Object (DTO) can solve this problem remaining a simple data structure object without business logic, while at the same time providing powerful tools for validating, structuring and serializing data.

Installation

You can install the package via composer:

Usage

Declaration

The package contains RMezhuev\DTO\DataObject class, to create your own DTO just extend it from this class.

To make the class IDE friendly and immutable, supported properties are declared using phpdoc. All properties and values are validated on object construction. For optional properties, type null must be added to the description of their types.

Initialization

Constructor

Constructor of the object expects an associative array of properties with names matching the phpdoc names and with values of the supported types.

Factory methods

Most likely, you will need to initialize your DTO from different data structures depending on the context of use. To do this, you can use separate factory methods for each specific case.

Accessing data

By magic getter or array notation

All properties are accessible through magic getter defined in base class. You can also use array brackets notation because the class also implements Arrayable interface as well.

Serialization

DTO supports toArray() and toJson() serialization out of the box and implements Illuminate\Contracts\Support\Arrayable and Illuminate\Contracts\Support\Jsonable corresponding interfaces for better integration with Laravel framework.

Snake case

By default during serialization all names will be converted to the snake case so fullName will become full_name. To disable this behavior you can set $snakeOnSerialize = false

Partial mode

On serialization DTO allows you to specify partial mode. In this case only implicitly initialized fields will be serialized, all the rest will be excluded. This mode is useful for partial updates, when you need to discern if nullable field was implicitly set to null value or wasn't set at all.

Custom serialization

Serialization methods can be easily overwritten in child class when built-in methods do not meet your needs or if you want to make it more explicit.

Exception handling

In addition to property type validation, on constructing data transfer object will check if all required properties are set. If not, then RMezhuev\DTO\Exceptions\DataObjectException will be thrown. Likewise, if you're trying to set unsupported or change existing properties, you'll get the same exception.

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

License

The MIT License (MIT). Please see License for more information.


All versions of data-transfer-object with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ext-json Version *
illuminate/support Version ^5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.00|^12.0
symfony/property-info Version ^4.0|^5.0|^6.0|7.0
phpdocumentor/reflection-docblock Version ^5.3
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 rmezhuev/data-transfer-object contains the following files

Loading the files please wait ....