2017 © Pedro Peláez
 

library type-converter

image

necronru/type-converter

  • Thursday, November 2, 2017
  • by Necronru
  • Repository
  • 0 Watchers
  • 0 Stars
  • 212 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 12 % Grown

The README.md

Contract type cast array library

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

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

The Versions