2017 © Pedro Peláez
 

library transformers

Property bag with automatic value normalizing and formatting

image

new-inventor/transformers

Property bag with automatic value normalizing and formatting

  • Friday, February 16, 2018
  • by George Ionov
  • Repository
  • 1 Watchers
  • 0 Stars
  • 333 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 18 Versions
  • 3 % Grown

The README.md

Data Transformers

This utility provide to you some transformers for transform your data to another representation., (*1)

Installation

composer require new-inventor/transformers, (*2)

Simple usage of normalizer

$transformer = new ToInt();
or
$transformer = ToInt::make();
$res = $transformer->transform($value);

Transformers transform values from different types to needed type and format, (*3)

Signatures of normalizer constructors

  • ArrayToCsvString(string $separator = ',', string $enclosure = '"', string $escape = '\', bool $encloseAll = false) // transform one dimension array to csv string
  • AsEmpty() // transform empty value to null
  • BoolToMixed($true = '1', $false = '0') // transform boll to value according to construct parameters
  • ChainTransformer(TransformerInterface ...$transformers) // apply transformers for value in same order as in constructor
  • CsvStringToArray(string $separator = ',', string $enclosure = '"', string $escape = '\') transforms csv string to array
  • DateTimeToString(string $format = 'd.m.Y H:i:s') // transforms \DateTime object to string
  • InnerTransformer(TransformerInterface ...$transformers)// apply transformers to array of values if pass null then value should return as is, if array length > transformers count then last transformer should be applied to array[$key] there $key > transformers count
  • StringToCamelCase()//transform string to camel case (for example 'qwe asd_zxc' transforms to 'qweAsdZxc')
  • StringToDateTime(string $format = 'd.m.Y H:i:s')//transform string to \DateTime object
  • StringToLowerCase()// run strtolower() on string
  • StringToPhone()//transform string to international phone (fore example '5-123-123-23-23' transforms to '+51231232323')
  • StringToScreamingSnakeCase()//transform string to screaming case (for example 'qwe asd_zxc' transforms to 'QWE_ASD_ZXC')
  • StringToUpperCase()// run strtoupper() on string
  • ToArray()//transform object, implementing \Iterator or \ArrayAccess or have toArray method, or scalar to array
  • ToBool()//transform variable to boolean
  • ToFloat()//transform numeric value to float
  • ToInt()//transform numeric value to int
  • ToRange()//transform value to range
  • ToString()//transform value that can be transformed to string
  • Utf8StringToAsciiString()//transform string to ascii string for example '😁' transforms to 'U+1F601'

If you transform value with wrong type then transformer throw \NewInventor\TypeChecker\Exception\TypeException If transformer can not transform value it throw \NewInventor\Transformers\Exception\TransformationException, (*4)

  • To transform complex objects/arrays use https://github.com/new-inventor/data-structure
  • To implement property bags use https://github.com/new-inventor/property-bag

The Versions

16/02 2018

dev-master

9999999-dev

Property bag with automatic value normalizing and formatting

  Sources   Download

MIT

The Requires

 

The Development Requires

16/02 2018

1.5.1

1.5.1.0

Property bag with automatic value normalizing and formatting

  Sources   Download

MIT

The Requires

 

The Development Requires

09/01 2018

1.5.0

1.5.0.0

Property bag with automatic value normalizing and formatting

  Sources   Download

MIT

The Requires

 

The Development Requires

27/10 2017

1.4.1

1.4.1.0

Property bag with automatic value normalizing and formatting

  Sources   Download

MIT

The Requires

 

The Development Requires

18/10 2017

1.4.0

1.4.0.0

Property bag with automatic value normalizing and formatting

  Sources   Download

MIT

The Requires

 

The Development Requires

16/10 2017

1.3.1

1.3.1.0

Property bag with automatic value normalizing and formatting

  Sources   Download

MIT

The Requires

 

The Development Requires

16/10 2017

1.3.0

1.3.0.0

Property bag with automatic value normalizing and formatting

  Sources   Download

MIT

The Requires

 

The Development Requires

13/10 2017

1.2.0

1.2.0.0

Property bag with automatic value normalizing and formatting

  Sources   Download

MIT

The Requires

 

The Development Requires

13/10 2017

1.1.6

1.1.6.0

Property bag with automatic value normalizing and formatting

  Sources   Download

MIT

The Requires

 

The Development Requires

13/10 2017

1.1.5

1.1.5.0

Property bag with automatic value normalizing and formatting

  Sources   Download

MIT

The Requires

 

The Development Requires

13/10 2017

1.1.4

1.1.4.0

Property bag with automatic value normalizing and formatting

  Sources   Download

MIT

The Requires

 

The Development Requires

13/10 2017

1.1.3

1.1.3.0

Property bag with automatic value normalizing and formatting

  Sources   Download

MIT

The Requires

 

The Development Requires

13/10 2017

1.1.2

1.1.2.0

Property bag with automatic value normalizing and formatting

  Sources   Download

MIT

The Requires

 

The Development Requires

13/10 2017

1.1.1

1.1.1.0

Property bag with automatic value normalizing and formatting

  Sources   Download

MIT

The Requires

 

The Development Requires

13/10 2017

1.1.0

1.1.0.0

Property bag with automatic value normalizing and formatting

  Sources   Download

MIT

The Requires

 

The Development Requires

10/10 2017

1.0.2

1.0.2.0

Property bag with automatic value normalizing and formatting

  Sources   Download

MIT

The Requires

 

The Development Requires

10/10 2017

1.0.1

1.0.1.0

Property bag with automatic value normalizing and formatting

  Sources   Download

MIT

The Requires

 

The Development Requires

10/10 2017

1.0.0

1.0.0.0

Property bag with automatic value normalizing and formatting

  Sources   Download

MIT

The Requires

 

The Development Requires