necronru/type-converter

There is no license information available for the latest version (0.1.0) of this package.

0.1.0 2017-11-01 08:14 UTC

This package is not auto-updated.

Last update: 2020-03-27 04:28:20 UTC


README

Usage


class Awesome {
  public function getInt(): int {}
  public function getBool(): bool {}
  public function getString(): string {}
  public function getFloat(): float {}
  public function getAwesomes(): array {}
  public function addAwesome(Awesome $awesome) {} // symfony property access mutator, needs for arrayOf recognize
}

$converter = (new Necronru\TypeConverter\TypeConverterBuilder())->build();

$data = [
    'int' => "1",
    'bool' => 'true',
    'string' => 1,
    'awesomes' => [
      [
        'int' => "1",
        'bool' => 'true',
        'string' => 1,
      ]
    ]
];

var_export($converter->convert($data, Awesome::class));

Result:

array (
  'int' => 1,
  'bool' => true,
  'string' => '1',
  'awesomes' => 
  array (
    0 => 
    array (
      'int' => 1,
      'bool' => true,
      'string' => '1',
    ),
  ),
);