1. Go to this page and download the library: Download fenzland/data-parser library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fenzland / data-parser example snippets
use Fenzland\DataParser\Unifier;
use Fenzland\DataParser\Transformer;
$unifier= Unifier::make_( $unifying_meta );
$unifier->unify( $data );
$transformer= Transformer::make_( $transforming_meta );
$transformer->transform( $data );
[
"key"=> [
// Type of value. Available scalar values are:
// 'bool', 'boolean',
// 'int', 'integer',
// 'float', 'double',
// 'string',
// 'auto',
// 'null',
'type'=> "string",
// Default value
'default'=> "default_value",
// Hard value
// 'value'=> "hard_value",
],
];
[
"key"=> true,
// is simplified form of
"key"=> [
'type'=> 'bool',
'default'=> true,
],
"key"=> 5,
// is simplified form of
"key"=> [
'type'=> 'int',
'default'=> 5,
],
"key"=> 1.0,
// is simplified form of
"key"=> [
'type'=> 'float',
'default'=> 1.0,
],
"key"=> "default_value",
// is simplified form of
"key"=> [
'type'=> 'string',
'default'=> "default_value",
],
"key"=> null,
// is simplified form of
"key"=> [
'type'=> 'null',
'value'=> null,
],
];
[
"key"=> [
'type'=> 'map',
'items'=> [
"column_0"=> /* a unifying meta */,
"column_1"=> /* a unifying meta */,
],
],
];
[
"key"=> [
'type'=> 'array',
'item'=> [
// a unifying meta
'type'=> ...,
'default'=> ...,
],
],
];
[
"key"=> [
'type'=> 'array',
'item'=> [
'type'=> 'map',
'items'=> [
"column_0"=> /* a unifying meta */,
"column_1"=> /* a unifying meta */,
],
],
],
];
[
"key"=> [
'type'=> 'array',
'item'=> /* a unifying meta */,
'slice'=> [ 0, -2 ], // Will call array_slice( $array, 0, -2 );
],
];
// meta
[
"foo"=> [
'type'=> 'value',
'keys'=> [ "Foo", "Bar", ],
'meta'=> [
// a unifying meta
'type'=> 'string',
],
],
];
// Transform
[
"Foo"=> [
"Bar"=> 8,
],
];
// Into
[
"foo"=> "8",
];
[
"key"=> "Foo",
// and
"key"=> [
'type'=> 'value',
'keys'=> "Foo",
'meta'=> [
'type'=> 'auto',
],
],
// are simplified form of
"key"=> [
'type'=> 'value',
'keys'=> [ "Foo", ],
'meta'=> [
'type'=> 'auto',
],
],
];
[
"key"=> [
'type'=> 'map',
'items'=> [
'column_0'=> /* a transforming meta */,
'column_1'=> /* a transforming meta */,
],
],
];