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?

@dg dg force-pushed the v3.0 branch 21 times, most recently from afdbd1f to 3109450 Compare August 31, 2021 09:33
@dg dg force-pushed the v3.0 branch 4 times, most recently from cb3f8e3 to 694b044 Compare September 19, 2021 22:17
@dg dg force-pushed the v3.0 branch 3 times, most recently from 6043798 to 4f0cb0b Compare September 29, 2021 15:39
@dg dg force-pushed the v3.0 branch 15 times, most recently from c27659e to f575f06 Compare December 14, 2021 18:46
@dg dg force-pushed the v3.0 branch 5 times, most recently from 3803a55 to 11c236b Compare December 21, 2021 12:05
@dg dg force-pushed the v3.0 branch 2 times, most recently from 24e29f2 to 14bc988 Compare October 13, 2022 01:32
@dg dg force-pushed the v3.0 branch 2 times, most recently from e841bcc to 9aba53b Compare November 2, 2022 16:28
@dg dg force-pushed the v3.0 branch 2 times, most recently from 570660e to dad71aa Compare January 21, 2023 20:03
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.

1 participant