Download the PHP package cerbero/transformer without Composer

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

Author PHP Version Build Status Coverage Status Quality Score Latest Version PSR-12 Total Downloads

SensioLabsInsight

Framework agnostic package to transform arrays, objects, arrays of arrays or arrays of objects by manipulating, casting and mapping their properties and keys.

Install

Via Composer

Usage

Transformers can be created by extending the AbstractTransformer class:

The method getStructure() lets you define how you want the data to be transformed. For example, imagine that this array:

has to be transformed into:

All you need to do is implement getStructure() as follows:

In the example above:

After defining the new structure, you can transform arrays, objects, arrays of arrays or arrays of objects by calling the transform() method:

or if you prefer to transform data into a specific object, you may call the method transformInto():

Normalize many sources

Sometimes you may need to normalize data from different sources. In this case only source keys might change, whilst expected keys and transformations remain the same. To avoid repeating code for every source, you may extend the abstract transformer as you normally would but without specifying the source keys:

The example above defines only expected keys and related transformations, no source keys. If no transformation is needed, null can be set as value.

Finally to map expected keys with keys of different sources, you may now extend your new transformer for each source and implement the method getKeysMap():

Transformations

Any function or class method can be used as a transformation, for example trim, substr:2, Class::staticMethod, Namespace\Class::instanceMethod are all valid transformations. Please note that the value to transform is passed as first parameter of the invoked function or method.

Furthermore this package comes with some builtin transformations:

Transformation Description Syntax
arr Decode a JSON or wrap the value into an array arr
bool Cast the value to a boolean bool
date Transform the value into a DateTime object or format a date date date:Y-m-d date:Y-m-d,UTC date:Y-m-d,UTC,UTC
default Fallback to a default value if the value is null or not found default:foo
enum Enumerate the value with defined associations enum:denied=0,approved=1,pending=2
float Cast the value to a float and optionally truncate decimals float float:2
int Cast the value to an integer int
object Decode a JSON or convert the value to an object object
string Encode a JSON or convert the value to a string string

Custom transformations

When functions, methods and builtin transformations are not enough, you may implement your own transformations by adding methods to your transformer, for example:

prefix is now a custom transformation that receives a prefix as parameter and prepend it to the value to transform. It can now be applied by using the syntax prefix:foo so that the $prefix parameter equals 'foo'. The above example only needs a parameter but you may pass as many arguments as you wish following the syntax prefix:foo,bar,baz.

Please note that $this->value holds the value obtained from the last transformation applied, so when you pipe more transformations the value is updated by every transformation it passes through.

Another handy property you may use in a custom transformation is $this->item, which holds the array or object that contains $this->value. It might be useful for example when a custom transformation requires another value from the original item to transform the current value.

Sometimes you may need the same custom transformation in different transformers. You might consider to extract such logic into a class so that it can be easily called from any transformer by using an alias, just like the builtin transformations:

The custom transformation above extends the AbstractTransformation class and the parameters are passed in the apply() method as an array. Since PrefixTransformation follows the convention Name + Transformation, it can now be used with the alias prefix as we did before e.g.: prefix:foo.

Both the properties $this->value and $this->item are available in the transformation class, just like when you define custom transformations in your transformer.

Most likely your transformation classes are going to have their own namespace, it can be defined by implementing the method getCustomTransformationNamespace() in your transformer:

Change log

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

Testing

Contributing

Please see CODE_OF_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 ^7.1||^8.0
illuminate/support Version >=5.5
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 cerbero/transformer contains the following files

Loading the files please wait ....