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

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

Data transfer objects with batteries included

based on https://github.com/spatie/data-transfer-object

Latest Version on Packagist Build Status Quality Score StyleCI Total Downloads

Installation

You can install the package via composer:

Have you ever…

… worked with an array of data, retrieved from a request, a CSV file or a JSON API; and wondered what was in it?

Here's an example:

The goal of this package is to structure "unstructured data", which is normally stored in associative arrays. By structuring this data into an object, we gain several advantages:

Let's look at the example of a JSON API call:

Working with this array is difficult, as we'll always have to refer to the documentation to know what's exactly in it. This package allows you to create data transfer object definitions, classes, which will represent the data in a structured way.

We did our best to keep the syntax and overhead as little as possible:

An object of PostData can from now on be constructed like so:

Now you can use this data in a structured way:

It's, of course, possible to add static constructors to PostData:

By adding doc blocks to our properties, their values will be validated against the given type; and a TypeError will be thrown if the value doesn't comply with the given type.

Here are the possible ways of declaring types:

When PHP 7.4 introduces typed properties, you'll be able to simply remove the doc blocks and type the properties with the new, built-in syntax.

Working with collections

If you're working with collections of DTOs, you probably want auto completion and proper type validation on your collections too. This package adds a simple collection implementation, which you can extend from.

By overriding the current method, you'll get auto completion in your IDE, and use the collections like so.

Of course you're free to implement your own static constructors:

Automatic casting of nested DTOs

If you've got nested DTO fields, data passed to the parent DTO will automatically be casted.

PostData can now be constructed like so:

Automatic casting of nested array DTOs

Similarly to above, nested array DTOs will automatically be casted.

PostData will automatically construct tags like such:

Attention: For nested type casting to work your Docblock definition needs to be a Fully Qualified Class Name (\App\DTOs\TagData[] instead of TagData[] and an use statement at the top)

Immutability

If you want your data object to be never changeable (this is a good idea in some cases), you can make them immutable:

Trying to change a property of $postData after it's constructed, will result in a DataTransferObjectError.

Helper functions

There are also some helper functions provided for working with multiple properties at once.

You can also chain these methods:

It's important to note that except and only are immutable, they won't change the original data transfer object.

Exception handling

Beside property type validation, you can also be certain that the data transfer object in its whole is always valid. On constructing a data transfer object, we'll validate whether all required (non-nullable) properties are set. If not, a Spatie\DataTransferObject\DataTransferObjectError will be thrown.

Likewise, if you're trying to set non-defined properties, you'll get a DataTransferObjectError.

Testing

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Postcardware

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.

We publish all received postcards on our company website.

Credits

Our Arr class contains functions copied from Laravels Arr helper.

Support us

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.

License

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


All versions of data-transfer-object with dependencies

PHP Build Version
Package Version
Requires php Version ^7.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 knobik/data-transfer-object contains the following files

Loading the files please wait ....