necronru/type-converter

This package is abandoned and no longer maintained. No replacement package was suggested.
There is no license information available for the latest version (0.1.0) of this package.

Maintainers

Package info

github.com/Necronru/type-converter

pkg:composer/necronru/type-converter

Statistics

Installs: 237

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0 2017-11-01 08:14 UTC

This package is not auto-updated.

Last update: 2025-12-27 07:28:33 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',
    ),
  ),
);