2017 © Pedro Peláez
 

symfony-bundle 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.

image

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.

  • Tuesday, January 26, 2016
  • by eosnewmedia
  • Repository
  • 6 Watchers
  • 8 Stars
  • 375 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

This Bundle isn't maintained anymore!, (*1)

Enm / TransformerBundle BuildStatus

SensioLabsInsight, (*2)

What can the bundle be used for?

This Bundle is used to integrate the Enm/Transformer library into a Symfony2 environment., (*3)

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., (*4)

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., (*5)

Basic Usage

The Transformer is reachable through a symfony service., (*6)

enm.transformer

For the auto-complete the "TransformerInterface" can be used for typification:, (*7)

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

The Interface will offer different Methods to you:, (*8)

  • transform($returnClass, $config, $values, $local_config = null, $result_type = 'object') : array | object | string, (*9)

  • reverseTransform($object, $config, $local_config = null, $result_type = 'object') : array | \stdClass | string, (*10)

  • getEmptyObjectStructureFromConfig($config, $result_type = 'object') : array | object | string, (*11)

  • convert($value, $to) : array | object | string, (*12)

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)., (*13)

Parameters:, (*14)

  • returnClass : object or class name (with namespace) of the object you will get back from the transformer, (*15)

  • config : configuration array for validating and building the output, (*16)

  • values : object or array or json string with values to validate, (*17)

  • local_config : configuration name from the global configuration or configuration array or configuration object or configuration json with transformer settings, (*18)

  • result_type : string with the type which should be returned by this method ("array" or "object" or "json"), (*19)

Result:, (*20)

  • object or array or json

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), (*21)

Parameters:, (*22)

  • object : object or array or json, (*23)

  • config : configuration array, (*24)

  • local_config : configuration name from the global configuration or configuration array or configuration object or configuration json with transformer settings, (*25)

  • result_type : string with the type which should be returned by this method ("array" or "object" or "json"), (*26)

Result:, (*27)

  • object or array or json

Method: getEmptyObjectStructureFromConfig()

This Method will build a structure of the needed object from your configuration array., (*28)

Parameters:, (*29)

  • config : configuration array, (*30)

  • result_type : string with the type which should be returned by this method ("array" or "object" or "json"), (*31)

Result:, (*32)

  • object or array or json

Method: convert()

This value will convert an object, an array or a json string to a standard object, an array or a json string., (*33)

Parameters:, (*34)

  • value : array or object or json, (*35)

  • to : string with the type which should be returned by this method ("array" or "object" or "json"), (*36)

Result:, (*37)

  • object or array or json

Validation

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

The config array has some parameters for all types of validation and some special type validation parameters., (*39)

Some of the parameters are required, some are optional., (*40)

The base configuration looks like:, (*41)

$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

This option is the only always required option., (*42)

With this option you have to give the data type for validation to the transformer., (*43)

Possible Values:, (*44)

  • 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

This option is optional, but if it is used, it needs a string given., (*45)

This option can be used for renaming the key to a different property name., (*46)

children

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

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

Default Options

possible for all types and always optional:, (*49)

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

required

This option needs true or false. Default value is false., (*50)

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

requiredIfAvailable

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

Generally this option tells the transformer to set a current value required., (*53)

Sub Configuration:, (*54)

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

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

Generally this option tells the transformer to set a current value required., (*56)

Sub Configuration:, (*57)

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

This option needs an array of config key names., (*58)

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., (*59)

forbiddenIfNotAvailable

This option needs an array of config key names., (*60)

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., (*61)

String Validation

Base configuration:, (*62)

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

Possible options, all optional:, (*63)

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

The Versions

26/01 2016

dev-master

9999999-dev http://www.eosnewmedia.de

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.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Philipp Marien
by Alexander Bogomolov

api json validation bundle array symfony converter object transformer serialisation

26/01 2016

dev-develop

dev-develop http://www.eosnewmedia.de

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.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Philipp Marien
by Alexander Bogomolov

api json validation bundle array symfony converter object transformer serialisation

26/01 2016

0.4.0

0.4.0.0 http://www.eosnewmedia.de

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.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Philipp Marien
by Alexander Bogomolov

api json validation bundle array symfony converter object transformer serialisation

14/07 2015

0.3.3

0.3.3.0 http://www.eosnewmedia.de

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.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Philipp Marien
by Alexander Bogomolov

api json validation bundle array symfony converter object transformer serialisation

27/10 2014

0.3.2

0.3.2.0 http://www.eosnewmedia.de

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.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Philipp Marien
by Alexander Bogomolov

api json validation bundle array symfony converter object transformer serialisation

24/10 2014

0.3.1

0.3.1.0 http://www.eosnewmedia.de

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.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Philipp Marien
by Alexander Bogomolov

api json validation bundle array symfony converter object transformer serialisation

24/10 2014

0.3.0

0.3.0.0 http://www.eosnewmedia.de

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.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Philipp Marien
by Alexander Bogomolov

api json validation bundle array symfony converter object transformer serialisation

15/10 2014

0.2.4

0.2.4.0 http://www.eosnewmedia.de

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.

  Sources   Download

MIT

The Requires

 

by Philipp Marien
by Alexander Bogomolov

api json validation bundle array symfony converter object transformer serialisation

14/10 2014

0.2.3

0.2.3.0 http://www.eosnewmedia.de

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.

  Sources   Download

MIT

The Requires

 

by Philipp Marien
by Alexander Bogomolov

api json validation serialisation

07/10 2014

0.2.2

0.2.2.0 http://www.eosnewmedia.de

  Sources   Download

MIT

The Requires

 

by Philipp Marien
by Alexander Bogomolov

api json validation serialisation

06/10 2014

0.2.1

0.2.1.0 http://www.eosnewmedia.de

  Sources   Download

MIT

The Requires

 

by Philipp Marien
by Alexander Bogomolov

api json validation serialisation

06/10 2014

0.2.0

0.2.0.0 http://www.eosnewmedia.de

  Sources   Download

MIT

The Requires

 

by Philipp Marien
by Alexander Bogomolov

api json validation serialisation