PHP code example of martinstarecek / schematic

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

    

martinstarecek / schematic example snippets


use RoundingWell\Schematic\Schema;

$schema = Schema::fromFile('car.json');

assert($schema->isObject());

$properties = $schema->properties();

assert(is_array($properties));
assert(isset($properties['make']));
assert(isset($properties['owners']));

assert($schema->isRequired('make'));
assert($schema->isRequired('year') === false);

$items = $properties['owners']->items();

assert($items->isObject());

use RoundingWell\Schematic\Generator;

$generator = new Generator();

$classes = $generator->generate($schema, 'Acme\Model\Car', 'Acme\Model');

$files = $generator->write($classes, 'src/');

use RoundingWell\Schematic\Generator;
use RoundingWell\Schematic\Schema;

$generator = new Generator();
$schema = Schema::fromFile('car.json');
$classes = $generator->generate($schema);
$files = $generator->write($classes, 'src/', 'Acme\Model');



namespace Acme\Model;

class Car
{
    /**
     * @var string
     */
    public $vin;
    /**
     * @var string|null
     */
    public $make;
    /**
     * @var string|null
     */
    public $model;
    /**
     * @var int|null
     */
    public $year;
    /**
     * @var \Acme\Model\Car\Owner[]
     */
    public $owners;
}



namespace Acme\Model\Car;

class Owner
{
    /**
     * @var string
     */
    public $name;
    /**
     * @var bool|null
     */
    public $isCurrentOwner;
}