necronru/type-converter

该包最新版本(0.1.0)没有提供许可证信息。

0.1.0 2017-11-01 08:14 UTC

This package is not auto-updated.

Last update: 2024-09-21 01:39:51 UTC


README

使用方法

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));

结果

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