PHPackages                             enm/transformer-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. enm/transformer-bundle

AbandonedArchivedSymfony-bundle[API Development](/categories/api)

enm/transformer-bundle
======================

This bundle can be used for transforming an array, an object or a json-string into a needed array, object or json-string and validating the values and the schema against a configuration array.

0.4.0(10y ago)74131MITPHPPHP &gt;=5.4

Since Oct 6Pushed 7y ago3 watchersCompare

[ Source](https://github.com/eosnewmedia/TransformerBundle)[ Packagist](https://packagist.org/packages/enm/transformer-bundle)[ Docs](http://www.eosnewmedia.de)[ RSS](/packages/enm-transformer-bundle/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (9)Dependencies (5)Versions (12)Used By (0)

This Bundle isn't maintained anymore!

Enm / TransformerBundle [![BuildStatus](https://camo.githubusercontent.com/cfd185c27fbf2eef7db28492af017d5b720b9c8fb770f301e66e72f23a9b9c52/68747470733a2f2f7472617669732d63692e6f72672f656f736e65776d656469612f5472616e73666f726d657242756e646c652e737667)](https://travis-ci.org/eosnewmedia/TransformerBundle)
=================================================================================================================================================================================================================================================================================================================

[](#enm--transformerbundle-)

[![SensioLabsInsight](https://camo.githubusercontent.com/39e68d426901d10c5fba350d6b75c349dd9130f0880feef3121324dbc618bd0a/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f63313337366335662d656235612d346334642d393564652d3030373133383462633333612f6269672e706e67)](https://insight.sensiolabs.com/projects/c1376c5f-eb5a-4c4d-95de-0071384bc33a)

What can the bundle be used for?
--------------------------------

[](#what-can-the-bundle-be-used-for)

This Bundle is used to integrate the [Enm/Transformer](https://github.com/eosnewmedia/Transformer) library into a Symfony2 environment.

The Library can be used for validating an array, an object or a json-string and get an array, an object or a json-string back with the validated values.

This will be useful for example with a REST-API. You could give a JSON string in and out and the transformer can secure that all values are valid.

Basic Usage
-----------

[](#basic-usage)

The Transformer is reachable through a symfony service.

```
enm.transformer

```

For the auto-complete the "TransformerInterface" can be used for typification:

```
__construct(\Enm\TransformerBundle\Interfaces\TransformerInterface $transformer){
  $this->transformer = $transformer;
}

```

The Interface will offer different Methods to you:

- transform($returnClass, $config, $values, $local\_config = null, $result\_type = 'object') : array | object | string
- reverseTransform($object, $config, $local\_config = null, $result\_type = 'object') : array | \\stdClass | string
- getEmptyObjectStructureFromConfig($config, $result\_type = 'object') : array | object | string
- convert($value, $to) : array | object | string

### Method: transform()

[](#method-transform)

This method will validate the given values and build the result from the correct values (including property renaming, value normalizing and value converting if configured).

Parameters:

- returnClass : object or class name (with namespace) of the object you will get back from the transformer
- config : configuration array for validating and building the output
- values : object or array or json string with values to validate
- local\_config : configuration name from the global configuration or configuration array or configuration object or configuration json with transformer settings
- result\_type : string with the type which should be returned by this method ("array" or "object" or "json")

Result:

- object or array or json

### Method: reverseTransform()

[](#method-reversetransform)

This method returns the values of the object in the original structure (original naming before the transformation), but in the chosen format (object or array or json)

Parameters:

- object : object or array or json
- config : configuration array
- local\_config : configuration name from the global configuration or configuration array or configuration object or configuration json with transformer settings
- result\_type : string with the type which should be returned by this method ("array" or "object" or "json")

Result:

- object or array or json

### Method: getEmptyObjectStructureFromConfig()

[](#method-getemptyobjectstructurefromconfig)

This Method will build a structure of the needed object from your configuration array.

Parameters:

- config : configuration array
- result\_type : string with the type which should be returned by this method ("array" or "object" or "json")

Result:

- object or array or json

### Method: convert()

[](#method-convert)

This value will convert an object, an array or a json string to a standard object, an array or a json string.

Parameters:

- value : array or object or json
- to : string with the type which should be returned by this method ("array" or "object" or "json")

Result:

- object or array or json

Validation
----------

[](#validation)

For validation you can use a configuration array, which have to be given to the transform or reverseTransform method.

The config array has some parameters for all types of validation and some special type validation parameters.

Some of the parameters are required, some are optional.

The base configuration looks like:

```
$config = array(
  'key' => array(
    'type' => '', // required
    'renameTo' => '', // optional
    'children' => array(), // only in use with types "object", "collection" and (if you want it) "individual"
    'options' => array() // optional
  )
)

```

#### type

[](#type)

This option is the only always required option.

With this option you have to give the data type for validation to the transformer.

Possible Values:

- string
- integer
- float
- bool
- array
- object
- collection // array of equal objects
- date
- individual // can be any type. validation will not be performed by default, but you can add own validation (see later)

#### renameTo

[](#renameto)

This option is optional, but if it is used, it needs a string given.

This option can be used for renaming the key to a different property name.

#### children

[](#children)

This option is only possible if type is object, collection or individual. If type is object or collection, this option is required.

This option needs a complete configuration array for child elements (see object and collection validation)

### Default Options

[](#default-options)

possible for all types and always optional:

```
$config['key']['options'] => array(
  'required' => true,
  'requiredIfAvailable' => array(
    'and' => array(),
    'or' => array()
  ),
  'requiredIfNotAvailable' => array(
    'and' => array(),
    'or' => array()
  ),
  'forbiddenIfAvailable' => array(),
  'forbiddenIfNotAvailable' => array()
)

```

#### required

[](#required)

This option needs true or false. Default value is false.

If set to true, this option requires the transformer to validate that the current value is not NULL

#### requiredIfAvailable

[](#requiredifavailable)

This option have to be an array, which requires a sub configuration if set.

Generally this option tells the transformer to set a current value required.

Sub Configuration:

```
array(
  'and' => array(),
  'or' => array()
)

```

- and: all keys given here have to be available to set the current value required
- or: one of the keys given here has to be available to set the current value required

#### requiredIfNotAvailable

[](#requiredifnotavailable)

This option have to be an array, which requires a sub configuration if set.

Generally this option tells the transformer to set a current value required.

Sub Configuration:

```
array(
  'and' => array(),
  'or' => array()
)

```

- and: all keys given here must not be available to set the current value required
- or: one of the keys given here must not be available to set the current value required

#### forbiddenIfAvailable

[](#forbiddenifavailable)

This option needs an array of config key names.

It requires the transformer to validate that the current key will not have a value or a value equal to NULL if one of the given keys has a value.

#### forbiddenIfNotAvailable

[](#forbiddenifnotavailable)

This option needs an array of config key names.

It requires the transformer to validate that the current key will not have a value or a value equal to NULL if one of the given keys does not have a value.

### String Validation

[](#string-validation)

Base configuration:

```
$config = array(
  'key' => array(
    'type' => 'string',
  )
)

```

Possible options, all optional:

```
$config['key']['options'] = array(
  'stringValidation' => '' // email|url|ip
)

```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 84.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~52 days

Recently: every ~114 days

Total

10

Last Release

3764d ago

PHP version history (2 changes)0.2.3PHP &gt;=5.5

0.3.3PHP &gt;=5.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/c18ae5f024ce04dbd7c18fb39db1ebe9c4feb654d0cc6f54f206404355d2500b?d=identicon)[eosnewmedia](/maintainers/eosnewmedia)

![](https://www.gravatar.com/avatar/21ec4e897f4ee0a0d0bcaf844242946502ff852e9bee8fb2e1ef9a2fc2fb5f16?d=identicon)[pmarien](/maintainers/pmarien)

![](https://www.gravatar.com/avatar/05ab3e2474096da64cdd9fd9b06fcc5abedc75a05e6273790cff6d35b6a98981?d=identicon)[abogomolov](/maintainers/abogomolov)

---

Top Contributors

[![bogomolov-dev](https://avatars.githubusercontent.com/u/127733?v=4)](https://github.com/bogomolov-dev "bogomolov-dev (16 commits)")[![pmarien](https://avatars.githubusercontent.com/u/8394874?v=4)](https://github.com/pmarien "pmarien (2 commits)")[![h4cc](https://avatars.githubusercontent.com/u/2981491?v=4)](https://github.com/h4cc "h4cc (1 commits)")

---

Tags

jsonapisymfonybundlevalidationarrayconverterobjecttransformerserialisation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/enm-transformer-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/enm-transformer-bundle/health.svg)](https://phpackages.com/packages/enm-transformer-bundle)
```

###  Alternatives

[kreait/firebase-bundle

Symfony Bundle for the Firebase Admin SDK

1534.7M2](/packages/kreait-firebase-bundle)[harmbandstra/swagger-ui-bundle

Exposes swagger UI inside your Symfony project through a route (eg. /docs)

42867.3k](/packages/harmbandstra-swagger-ui-bundle)[stfalcon-studio/api-bundle

Base classes and helper services to build API application via Symfony.

1032.1k](/packages/stfalcon-studio-api-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
