Download the PHP package shetabit/transformer without Composer

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

Transformer

transform array keys easily.

Latest Version on Packagist Total Downloads on Packagist Tests Code Style Static Analysis Code Coverage

This package supports PHP 8.4+ and has no dependencies of its own, so it can be used in any PHP framework — Laravel, Symfony and the rest — as well as in no framework at all.

List of contents

Install

Via Composer

How to use

Renaming with a format

A format maps the keys the data has onto the keys it should have. Hand it to a Transformer and run it with get($transformer).

A key the format does not mention is left as it is, and every key keeps the place it had in the data.

The original data can be set at any time with setOriginalData(), so one Transform can be run over row after row:

Renaming with from and to

The same format can be written down pair by pair with from($currentFormat) and to($destinationFormat).

Both take a list as well:

Nested arrays

By default only the keys of the array itself are renamed. A recursive transformer applies the same format to every array nested in the data, including the arrays of a list:

recursive() turns it on for a transformer that was built without it, recursive(false) turns it off again.

How keys that collide are resolved

Every key is renamed at once, so a key can take the name another key is giving up in the same run. Two columns that were filled in the wrong order are swapped back with:

Where two keys would end up with the same name the renamed one wins, and of two renamed ones the one that comes first in the data:

Custom transformers

For a structure a format cannot describe, write a transformer of your own by implementing TransformerInterface.

Errors

Every exception of the package extends Shetabit\Transformer\Exceptions\TransformerException, so all of them can be caught at once.

Exception Thrown when
TransformerNotValidException Transform::get() is run without a transformer.
InvalidFormatException from() and to() were not given the same number of keys.

Testing

Every pull request and every push to master is checked by GitHub Actions: the test suite runs on PHP 8.4 and 8.5 (against both the lowest and the highest supported dependencies), the coding style is checked with PHP_CodeSniffer, the sources are analysed with PHPStan and the code coverage of the test suite is measured and has to stay above 95%.

Next to the unit tests there are feature tests that run realistic nested payloads through the package end to end: a whole tree renamed and renamed back with the flipped format, rows whose columns are swapped or shifted along, and the output of one transformer handed to the next.

You can run the same checks locally. With PHP and Composer installed on your machine:

If you would rather not install PHP on your machine, the shipped Dockerfile and Makefile run everything inside a container:

Another PHP version can be used with make test PHP_VERSION=8.5.

Change log

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

Contributing

Please see CONDUCT for details.

Security

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

Credits

License

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


All versions of transformer with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
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 shetabit/transformer contains the following files

Loading the files please wait ...