Download the PHP package ehyiah/mapping-bundle without Composer

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

MappingBundle

Symfony bundle to automap an object into another object easily.

It was mainly built in order to avoid passing full entities to symfony forms when you want to edit them. But you can use it in many ways.

It was designed to be as easy as possible, all the mapping is located into a single object that is "aware" of the target class and properties destinations. There is no configuration outside of the main object.

The main service have two methods :

Installation

Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.

Applications that use Symfony Flex

Open a command console, enter your project directory and execute:

Applications that don't use Symfony Flex

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:

Usage

In order to use this bundle, you will need to mark an object (basically a DTO) with the attribute Ehyiah\MappingBundle\Attributes\MappingAware

And in the same class, simply tag every properties you want to map to the target object with the same attribute. If the properties in the target class and the mapped DTO have the same name, there is nothing else to do (see property example). If the properties have a different name, you can use the option to specify the name in the target class.

As the mapping logic is using the propertyAccess component, you can specify nested properties in the target class. see and properties in the example below.

If you want to ignore null values when mapping from an object to the other, juste use the ignoreNullValue option on each properties you need to.

Simple Usage

1 - Create a DTO that will 'hold' the mapping logic

2 - Inject the into your code, and call the methods.

If you call function of the service tagged with in a controller, handler or wherever you need it, the service will take properties tagged with MappingAware attribute and will put the values stored in the DTO into the properties in the entity and flush them (default value).

Advanced usage

Replace the Built-in service

A Default service implementing exist in the bundle. But you may need to create a service that implements the to replace the default built-in.

Create your own service

To create your own service :

Transformers

Sometimes you need to modify data between the objects.

Example : in your SourceObject you have a string and need a Datetime in the TargetObject. Or the opposite

Well there is a simple way to do this via Transformers. You can easily create them or use some of prebuilt. To create them just create a class and implements

Transformers will have 2 methods and . and you can pass an array of options that will be used in both.

method is used in mapToTarget

method is used in mapFromTarget

In each method you have access ot the SourceObject and the TargetObject.

Going Further with Transformers

Transformers can be "open-minded" or "narrow-minded". For a better understanding there is an easy-to-understand example built-in with and .

Which one to choose is entirely to your mind ! The only difference between them is how you code the transform and reverseTransform methods.

Narrow-minded transformers

If you pick as examples the : It is said as a narrow-minded transformer as it will only accept to transform String to DateTime and reverseTransform DateTime to String. It will pick a string from the sourceObject and transform it into a DateTime object in the target object (via the mapToTarget method). And will pick the DateTime object from the target object and reverseTransform it into the sourceObject (via the mapFromTarget method)

If you try to do the opposite an Exception will be thrown.

Open-minded transformers

If you pick as examples the : It is said as an open-minded transformer as it will accept :

List Of built-in Transformers

Open-minded :

Transformer transform and reverseTransform options
DateTimeTransformer string to DateTime OR DateTime to string (use to transform the string with the provided format)
example
a valid DateTimeZone object example :
BooleanTransformer string|int to boolean OR boolean to string|int or example:

: true or false
EnumTransformer Enum|Enum[] into string|string[] OR string|string[] to enum|enum[] the class of the enum example :

Narrow-minded:

Transformer transform transform available options reverseTransform reverseTransform available options
StringToDateTimeTransformer string to DateTime a valid DateTimeZone object example : DateTime to string (use to transform the string with the provided format)
example
StringToBooleanTransformer string to Boolean : true or false Boolean to string or example:
StringToEnumTransformer string or array of strings to enum or array of enum the class of the enum example : enum or array of enum to string or array of strings the class of the enum example :
in case you would need to return the NAME instead of the VALUE example:
CollectionTransformer collection of object to collection of object the expected class for elements in the collection (mandatory), the collection property from where you would load data to simulate collection of object to collection of object the current class of elements in the collection (mandatory)

Mapped collection inside Mapped object

If you need to have sub mapped elements inside your initial mapped class, the is the perfect fit.


All versions of mapping-bundle with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
doctrine/orm Version ^2.10|3.0
symfony/property-access Version ^6.1|^7.0
symfony/monolog-bundle Version ^3.1
symfony/yaml Version ^6.1|^7.0
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 ehyiah/mapping-bundle contains the following files

Loading the files please wait ....