PHP code example of open-code-modeling / json-schema-to-php
1. Go to this page and download the library: Download open-code-modeling/json-schema-to-php 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/ */
open-code-modeling / json-schema-to-php example snippets
$decodedJson = \json_decode($jsonSchema, true);
$typeSet = Type::fromDefinition($decodedJson);
/** @var ObjectType $type */
$type = $typeSet->first();
$type->additionalProperties(); // false
$properties = $type->properties();
/** @var TypeSet $buildingIdTypeSet */
$buildingIdTypeSet = $properties['buildingId'];
/** @var StringType $buildingId */
$buildingId = $buildingIdTypeSet->first();
$buildingId->name(); // buildingId
$buildingId->type(); // string
$buildingId->pattern(); // ^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$
$buildingId->isRequired(); // true
$buildingId->isNullable(); // false
/** @var TypeSet $nameTypeSet */
$nameTypeSet = $properties['name'];
/** @var ReferenceType $name */
$name = $nameTypeSet->first();
$resolvedTypeSet = $name->resolvedType();
/** @var StringType $resolvedType */
$resolvedType = $resolvedTypeSet->first();
$resolvedType->name(); // name
$resolvedType->type(); // string
$resolvedType->isRequired(); // true
$resolvedType->isNullable(); // true
// ...