How to use Nette\Schema for getting structured default values?
- medhi
- Generous Backer | 255
Nette\Schema is awesome, but I would like to use it also for gathering
default values. It works, I pass empty array as data to process and it returns
default values set by ->default()
parameter:
BUT, it doesn't work, if elements are marked as required. It ends with error
The mandatory item 'text' is missing.
. It's logical, but how to
proceed, when I just want to get structured default values, no
matter if they are mandatory or not?
It would be nice to have something like
$defaults = $processor->getDefaults()
.
- medhi
- Generous Backer | 255
David Grudl wrote:
Set structure as optional,
Expect::structure(...)->required(false)
This still throws an exception (I forgot the
->setRequired(true)
on the justify
element in the
original question):
When fetching default values, it should not matter, if they are required or not.
- David Grudl
- Nette Core | 8229
Hmm, it will probably be better to do it like
Expect::anyOf([], Expect::structure([...]))
- David Grudl
- Nette Core | 8229
Sorry, I misread your post. There is no such function for gathering default value. Please create an issue.
- medhi
- Generous Backer | 255
David Grudl wrote:
Sorry, I misread your post. There is no such function for gathering default value. Please create an issue.
Issue created https://github.com/…ma/issues/39
Thanks