PHP code example of theiconic / synopsis

1. Go to this page and download the library: Download theiconic/synopsis 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/ */

    

theiconic / synopsis example snippets


$factory = new TheIconic\Synopsis\Factory();

class MyClass
{
    public $myProp = 1;
}

$myObject = new MyClass();
$myArray = [
    'string' => 'Hello World!',
    'integer' => 1,
    'boolean' = true,
];

$objectSynopsis = $factory->synopsize($myObject);
$arraySynopsis = $factory->synopsize($myArray);

$formatter = new TheIconic\Synopsis\Formatter\ArrayFormatter();
$formatter->format($objectSynopsis);
/*
 * [
 *     'type' => 'MyClass',
 *     'length' => 1,
 *     'value' => ''
 *     'children' => [
 *         'myProp' => [
 *             'type' => 'integer',
 *             'length' => 1,
 *             'value' => 1,
 *         ]
 *     ]
 * ]
 */
 
$formatter->format($arraySynopsis);
/*
 * [
 *     'type' => 'array',
 *     'length' => 3,
 *     'value' => ''
 *     'children' => [
 *         'string' => [
 *             'type' => 'string',
 *             'length' => 12,
 *             'value' => 'Hello World!',
 *         ]
 *         'integer' => [
 *             'type' => 'integer',
 *             'length' => 1,
 *             'value' => 1,
 *         ],
 *         'string' => [
 *             'type' => 'boolean',
 *             'length' => 4,
 *             'value' => 'true',
 *         ]
 *     ]
 * ]
 */

$factory->addObjectType(MyClass::$class, MyClassSynopsis::class);

$factory->addResourceType(MyClass::$class, MyClassSynopsis::class);

$factory->addType('string', MyStringSynopsis::class);