Download the PHP package rogerthomas84/dtoinflator without Composer

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

DTO Inflator

DtoInflator is a helpful library for converting arrays or generic objects into DTOs.

This was originally written for helping ease the management of responses from API services.

Usage

Create your model, extending DtoInflatorAbstract

If you require a sub model, add the property of protected $keyToClassMap to your parent model mapping the key name to the fully qualified class name. This tells the library to identify the key and that it needs to inflate a specific model.

All models should extend DtoInflatorAbstract.

If you have a property within a DTO called 'favourite' and it requires a sub model, you could map it with this:

If you require an array of models (for example someone can have various favourite items), you can simply append [] onto the class name in the map.

So, if you have a property called 'favourites' and it's an array of child models, the key to class map should look like this:

Sometimes you might want to change the name of a property to something else, for example in the case of API responses, you might want to change underscored keys with camelcase. To do this, simply expose the fieldToFieldMap variable in your model. Where the key is the original name, and the value is the new key to use in the DTO.

Please note, the newly named key is only used in inflation.

You might also want to shorten keys every now and then. To do this, you can pass a second parameter into the inflate methods, defining where these keys need to be mapped.

Examples

There are example models in the tests/DtoInflatorTests/TestModels directory.

Inflating

You can inflate a single record by calling inflateSingleArray passing the array of data or alternatively, if you've got an object (for example stdClass) you can use inflateSingleObject

Likewise, you can inflate a multiple records by calling inflateMultipleArrays passing the array of arrays, or again if you're using objects like above, the inflateMultipleObjects method.

Mapping fields

If a key passed into the inflate methods isn't found in the object, it gets added to the unmappedFields array. Likewise, if you try to request data from the object after inflating and the property isn't found, internally the abstract method __get($name) will check the unmappedFields for a corresponding value.

Theoretically you don't have to declare variables. But this obviously isn't advised. It does however mean that properties don't actually have to be public, they could be protected but never (ever) private.

More advanced models

If you needed more advanced models, you could use something like this:

Running unit tests

./vendor/bin/phpunit -c phpunit.xml


All versions of dtoinflator with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
ext-json Version *
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 rogerthomas84/dtoinflator contains the following files

Loading the files please wait ....