PHP code example of reenexe / compare-data-structure

1. Go to this page and download the library: Download reenexe/compare-data-structure 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/ */

    

reenexe / compare-data-structure example snippets


[
    'assoc' => [
        'id'    => 'integer',
        'name'  => 'string',
        'location'  => 'integer',
        'gender'    => [
            'set' => ['men', 'women', null]
        ],
        'joined'    => [
            'assoc' => [
                'source'    => 'integer|null',
                'at'        => 'string'
            ]
        ],
        'friends' => [
            'type' => 'null',
            'values' => [
                'id'    => 'integer',
                'name'  => 'string'
            ]
        ],
        'interests' => [
            'type' => 'null',
            'values' => 'string'
        ],
        'games' => [
            'type'  => 'null',
            'values' => [
                'title' => 'string'
            ]
        ],
        'books' => [
            'values' => [
                'author' => 'string',
                'title'  => 'string',
            ]
        ],
        'social' => [
            'set' => [
                'GitHub', 'LinkedIn', 'Facebook', 'Google', 'Twitter',
            ]
        ]
    ]
]

'integer'

array_merge(
    range(1, 100),
    range('a', 'z'),
    [true, false]
)

['values' => 'integer|string|boolean']

/**
 * @return StructureDiffInfo
 */
Comparator::check($data, $structure)

/**
 * @method public bool StructureDiffInfo::isEqual
 * @method public string StructureDiffInfo::getMessage
 * @method public string StructureDiffInfo::getPath
 */

use ReenExe\CompareDataStructure\Comparator;

class Test extends PHPUnit_Framework_TestCase{

    public function testSimple()
    {
        $diff = Comparator::check(1, 'integer');
        $this->assertTrue($diff->isEqual(), $diff);
    }
}

    Comparator::addCustom(array $custom)

Comparator::addCustom(                [
    'profile' => [
        'assoc' => [
            'id' => 'integer',
            'name' => 'string'
        ]
    ]
]);
...
Comparator::check($profile, 'profile');
...
Comparator::check($response, 'profile');
...

Comparator::check(
    $data = [
        'value' => 1,
        'next' => [
            'value' => 3,
            'next' => [
                'value' => 5,
                'next' => null
            ]
        ]
    ],
    $structure = 'link',
    $custom = [
        'link' => [
            'assoc' => [
                'value' => 'integer',
                'next'  => 'link|null'
            ]
        ]
    ]
);