Download the PHP package pixelshaped/flat-mapper-bundle without Composer

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

Latest Stable Version CI codecov

Flat Mapper Bundle

This bundle aims to solve the problem of building nested DTOs from flat arrays (such as database queries results).

One of its purposes is to help you create DTOs the same way you would with the Doctrine NEW keyword, except at depth. Other ways to do that generally imply mapping entities to DTOs which is less performant (memory and CPU wise). You can find benchmarks for this package at Pixelshaped/flat-mapper-benchmark.

You can also use it to map SQL queries to objects, it has no dependency on a particular ORM.

How to use?

At a glance

Given a DTO such as AuthorDTO

Will give you an array of AuthorDTO hydrated with all their BookDTO books (See complete example).

Installation

Configuration

This bundle can work without any configuration, but will display better performance if mapping validation is disabled and some cache service is autowired.

If you use Symfony, you can create a configuration file to do so:

If you don't, you can still benefit from this when instantiating FlatMapper, i.e.:

Mapping pre-caching

The mapping for a DTO is created the first time the function is called. Subsequent calls during the same script execution won't recreate the mapping. If a cache service is configured, mapping will be loaded from the cache for next script executions.

If you want to cache all your DTOs in advance to avoid doing it on your hotpaths, you can do:

This should be regarded as optional. Mapping information be created in any case when calling:

Add mapping to your DTOs

This bundle comes with several attributes that you can use to add mapping to your DTOs:

Hydrating nested DTOs

Given:

Calling FlatMapper with the following result set:

Will output:

Hydrating Column Arrays

Given ScalarArrayDTO

Calling FlatMapper with the following result set:

Will output:

Working with Doctrine Queries

Given the following DTO class:

The query:

Will give you an array of CustomerDTO, with the $shoppingListIds property populated with an array of corresponding ShoppingList IDs.

Working with pagination

You can still use Doctrine to paginate your DQL query:

Will get you an array of 10 CustomerWithAddressesDTO (granted you do have 10 in your db).

Usage without Symfony

You can use this package without Symfony. Just instantiate the FlatMapper class and use its methods.

Alternatives

Doctrine provides a solution to build DTOs directly from a QueryBuilder:

Given a DTO class such as CustomerDTO:

Doctrine can execute a query that produces an array array<CustomerDTO>:

Unfortunately, if you need to retrieve DTOs with non-scalar properties, such as:

then, the solution provided by Doctrine doesn't work. The creation of this bundle arose from that situation.

When I started coding this, I looked for alternatives but found only partial ones:

Do not hesitate to suggest alternatives or to contribute.


All versions of flat-mapper-bundle with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
symfony/cache-contracts Version ^2.5 || ^3.3
symfony/config Version ^5.4 || ^6.0 || ^7.0
symfony/dependency-injection Version ^5.4 || ^6.0 || ^7.0
symfony/http-kernel Version ^5.4 || ^6.0 || ^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 pixelshaped/flat-mapper-bundle contains the following files

Loading the files please wait ....