Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SchemaExtension #258

Open
wants to merge 2 commits into
base: v3.0
Choose a base branch
from
Open

SchemaExtension #258

wants to merge 2 commits into from

Conversation

mabar
Copy link
Contributor

@mabar mabar commented Mar 16, 2021

  • new feature 🎉
  • BC break? no
  • doc PR: Okay, but later please.

Any key in neon can be validated with neon-defined nette/schema, via SchemaExtension:

extensions:
	schema: Nette\DI\Extensions\SchemaExtension

schema:
	string: string()
	structure: structure([
		string: string(),
		stringWithDefault: schema(string("default value"), required(false))
		int: int(),
		float: float(),
		bool: bool(),
		array: arrayOf(string())
		list: listOf(string())
		type: type("string|int")
		schema1: schema(string())
		schema2: schema(string(), nullable())
		schema3: schema(string(), nullable(), required(false))
		schema4: schema(int(), min(10), max(20))

Behavior differs from direct use of nette/schema

  • all keys defined in schema are required by default (should make the most common usecase of neon-defined schema simpler)
  • additional configuration which is done via chained method can be achieved via schema(), eg. Expect::int()->min(10)->max(20) -> schema(int(), min(10), max(20))

Requirements of schema above could be satisfied with this example configuration:

string: string
structure:
	string: text
	int: 123
	float: 123.456
	bool: true
	array: [key: string, anotherString]
	list: [string, anotherString]
	type: string
	schema1: string
	schema2: null
	#schema3 is not required
	schema4: 15

Keys not defined in schema are allowed and accept any value just like before this PR. So e.g. this is allowed:

services:
	- Example

TODOs

  • docs
  • bootstrap integration

Big thanks to author of original extension which validates parameters in PHPStan, @ondrejmirtes

@mabar
Copy link
Contributor Author

mabar commented Mar 16, 2021

Build failures seem unrelated to the PR.

I also had to remove deprecation from Compiler::getConfig() as it seems to be only way how can extension access whole config.

@mabar
Copy link
Contributor Author

mabar commented May 19, 2021

@dg Are any changes needed or are you just waiting for next release or smth?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant