Created
August 21, 2021 23:48
-
-
Save jakubboucek/98002afe087562d530b16a83c5f1523a to your computer and use it in GitHub Desktop.
Recursive Nette Schema structure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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