Download the PHP package earc/parameter-transformer without Composer

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

eArc-parameter-transformer

Lightweight parameter transformer component. Use type hints to auto-wire objects, functions and methods.

Table of Contents

install

bootstrap

earc/parameter-transformer uses earc/di for dependency injection and tagging.

basic usage

All transforming functionality of the earc/parameter-transformer is bundled into the service ParameterTransformer. The parameter transformer exposes five methods:

All methods take three arguments:

auto wire functions and methods

auto update objects

configure and extend transformation

The transformation is configured via the Configuration object and extended via the ParameterTransformerFactoryInterface and the ParameterTransformerFactoryServiceInterface. To use this properly you have to understand how the transformation process works.

how the input array is determined

If an input array is provided via the seconds service method parameter, this input is taken. Otherwise php://input is used to create an input array.

You can provide an alternative fallback via the setDefaultResource() method:

how the input value is chosen

  1. The name of the variable is used to retrieve the starting value from the input. For example if the variable is named $product the $input['product'] is taken as value.

You can configure this behaviour via the setMapping() method:

The mapping is applied to the key before choosing the input value.

  1. If the key does not exist, the next positional key (int) is used.
  2. If neither the named key nor the next positional key exists a NoInputException is thrown.

You can change this behaviour via the setNoInputIsAllowed() method:

Instead of throwing an exception a null value is used.

how type hints are transformed

  1. If null is type hinted plus the starting value is the string 'null' the starting value will be treated as null.
  2. For build in primitive types the starting value is cast to the result value if it is not null.
  3. If it's not a build in primitive type plus a predefined type hint value exists, the predefined type hint value is used as result value.

You set the predefined type hint values via the setPredefinedTypeHints() method:

If you want to provide a complete Service-Container to enhance this library with the power of your dependency injection system, you should use the ParameterTransformerFactoryServiceInterface to provide a dynamic solution (see 5.).

  1. If a type hinted class implements the ParameterTransformerFactoryInterface the buildFromParameter() method is used to build the result value.

You can implement this if there is a way to build or retrieve an object via a single parameter, for example an entity.

  1. For all services implementing the ParameterTransformerFactoryServiceInterface and tagged by it will have the buildFromParameter() called until one of them returns an object. This object is used as result value.

This is especially useful for entities.

  1. If the type hinted class can be build via earc/di the result of di_get() will be taken as result value.

  2. If it is a union type one type hint after the other is taken for evaluation (1.-6.). The first result different from the input value (!=) and not null is the result value.

  3. If the result value is null and there is a default value hinted, the default value is the new result value.

  4. If the result is a null value, but the type hint does not allow null a NullValueException is thrown.

You can disable this behaviour via the setNullIsAllowed() method:

  1. Transformed input values are removed from the input array.

how callables and functions are transformed

  1. If the target is a class string, the constructor method retrieved.
  2. For the parameters and their type hints type hint transformation is applied.
  3. The result is returned as ordered array with the parameter names as keys.

how objects are transformed

In contrast to callables and functions there is no result array. The transformation is applied to the object directly.

  1. The methods are processed first and then the properties.

You can change this behaviour via the setMethodsFirst() method:

  1. All public methods that have exactly one parameter are processed until the complete input array is processed.

You can change this behaviour via the setFilterMethods() the setMaxParameterCount() and the setNoInputIsAllowed() method:

If the maximal parameter count is greater than one, the methods are processed in the order of their parameter count.

To use only property transformation set the maximal parameter count to zero.

If the input array is empty and no input is allowed null values are used for input.

  1. If no exception was thrown, the method is invoked with the result array.

  2. Foreach public property the type hint is evaluated until the complete input array is processed. The current values are replaced by the result values.

You can change this behaviour by the setFilterProperties() and setUsePropertyTransformation() methods:

additional info

There is no recursion implemented. Building type hinted classes via the earc/parameter-transformer has to be done explicit. The input data can hold complex data-structures thus preprocessing is an option if the object structure is known.

To map data from an input array to an arbitrary object can be done more efficient using earc/cast if it can be done by considering the property names without the type hints.

releases

release 0.0


All versions of parameter-transformer with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
earc/di Version ^3.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 earc/parameter-transformer contains the following files

Loading the files please wait ....