PHP code example of paysera / lib-object-wrapper

1. Go to this page and download the library: Download paysera/lib-object-wrapper 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/ */

    

paysera / lib-object-wrapper example snippets


$jsonString = json_encode([
    // ...
]);
/** @var stdClass $jsonData */
$jsonData = json_decode($jsonString);

$data = new ObjectWrapper($jsonData);

// Use like an associative array if needed
foreach ($data as $key => $value) {
    var_dump(isset($data[$value]));
    var_dump($data[$value]);
}

var_dump($data['non_existing']);    // just null - no notice

var_dump($data->getRequired('dump(get_class($data->getObject('inner_data'))); // another ObjectWrapper instance or null

var_dump($data->getArrayOfString('keys'));    // array of strings
var_dump($data->getArrayOfOject('children')); // array of ObjectWrapper instances

try {
    $data->getRequiredObject('inner_data')->getArrayOfObject('list')[0]->getRequiredString('key');
} catch (MissingItemException $e) {
    echo $e->getMessage(); // Missing