gfg / mapper
Mapper lib
Installs: 3 528
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 6
Forks: 0
Open Issues: 0
Requires (Dev)
- pdepend/pdepend: @stable
- phploc/phploc: @stable
- phpmd/phpmd: @stable
- phpunit/php-invoker: @stable
- phpunit/phpunit: @stable
- sebastian/phpcpd: @stable
- squizlabs/php_codesniffer: @stable
This package is not auto-updated.
Last update: 2019-02-20 19:24:19 UTC
README
Mapper
Tiny lib for mapping stuff
Example code:
<?php include_once 'vendor/autoload.php'; use GFG\Mapper\Data; class MyMapper implements Data\MapperInterface { public function get($key) { echo $key, PHP_EOL; return rand(); } } $mapper = new MyMapper(); $data = [ 'brand' => 1, 'myOptions' => [1, 2, 3, 4], 'myObject' => [ 1 => 3, 4 => [5, 6, 7] ], 'myArray' => [ [ 't1' => 1, 't2' => 2 ], [ 't1' => 3, 't2' => 4 ] ] ]; $structure = [ 'brand' => [ 'type' => 'single', 'prefix' => 'brand' ], 'myOptions' => [ 'type' => 'option', 'prefix' => 'my_options' ], 'myObject' => [ 'type' => ['assoc-single','assoc-option'], 'prefix' => 'my_object', 'use' => 'raw' ], 'myArray' => [ 'type' => 'arrayList', 'prefix' => 'my_array', 'inner' => [ 't1' => [ 'type' => 'single', 'prefix' => 't1' ], 't2' => [ 'type' => 'single', 'prefix' => 't2' ] ] ] ]; $manager = new Data\Manager($mapper, new Data\MapperFactory()); $manager->map($data, $structure); print_r($data);
Result:
brand_1
my_options_1
my_options_2
my_options_3
my_options_4
my_object_1
my_object_1_3
my_object_4
my_object_4_5
my_object_4_6
my_object_4_7
my_array_t1_1
my_array_t2_2
my_array_t1_3
my_array_t2_4
Array
(
[brand] => 1654437351
[myOptions] => Array
(
[0] => 1035778678
[1] => 542862853
[2] => 1503382077
[3] => 1275923644
)
[myObject] => Array
(
[1209860241] => 1577618151
[1119581297] => Array
(
[0] => 1151221332
[1] => 1743959005
[2] => 1583281629
)
)
[myArray] => Array
(
[0] => Array
(
[t1] => 1036570191
[t2] => 1379588832
)
[1] => Array
(
[t1] => 777473865
[t2] => 720358133
)
)
)