Skip to content

Instantly share code, notes, and snippets.

@jakubboucek
Created August 21, 2021 23:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakubboucek/98002afe087562d530b16a83c5f1523a to your computer and use it in GitHub Desktop.
Save jakubboucek/98002afe087562d530b16a83c5f1523a to your computer and use it in GitHub Desktop.
Recursive Nette Schema structure
<?php
declare(strict_types=1);
use Nette\Schema\Elements\Type;
use Nette\Schema\Expect;
require __DIR__ . '/vendor/autoload.php';
$childrenList = (new Type('array'))->default([]);
$childrenSchema = Expect::structure(
[
'id' => Expect::int()->required(),
'parent_id' => Expect::int()->required(),
'child_id' => Expect::int()->required(),
'class' => Expect::string()->required(),
// ...
'children' => $childrenList,
]
);
$childrenList->items($childrenSchema);
$schema = [
'type' => Expect::string()->required(),
'widget' => Expect::structure(
[
'id' => Expect::int()->required(),
'name' => Expect::string()->required(),
'ico' => Expect::string()->required(),
'category' => Expect::int()->required(),
'children' => $childrenList,
]
),
];
var_export($schema);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment