Skip to content

Conversation

@h4kuna
Copy link
Contributor

@h4kuna h4kuna commented Sep 14, 2023

  • bug fix / new feature? new feature
  • BC break? no
  • doc PR: nette/docs#???

Example

In example I used classes from my library, if you want to try, let's use composer require h4kuna/number-format:dev-mater, but i think it is not necessary.

I want to define custom collection of formats

services:
	format.date:
		factory: h4kuna\Format\Date\Formatters\DateTimeFormatter('j.n.Y')
		autowired: false
	format.time:
		factory: h4kuna\Format\Date\Formatters\DateTimeFormatter('H:i:s')
		autowired: false

	date.formats: h4kuna\Format\Date\FormatsAccessor(
		date: @format.date
		time: @format.time
	)

	# set to template, but it is not need for example
	latte.latteFactory:
		setup:
			- addFilter('date', @date.formats::get('date'))
			- addFilter('time', @date.formats::get('time'))

The original way is too chatty, the patch allow

services:
	date.formats: h4kuna\Format\Date\FormatsAccessor(
		date: h4kuna\Format\Date\Formatters\DateTimeFormatter('j.n.Y')
		time: h4kuna\Format\Date\Formatters\DateTimeFormatter('H:i:s')
	)

I don't need class with option autowired: true explicitly to register to container. But behavior is same like above.

What do you think?

@dg
Copy link
Member

dg commented Sep 14, 2023

I have for a long time in the TODO to simplify the multi-factory. To make it defined the same way as a classic generated factory. Maybe like this:

services:
	date.formats: 
		implements: h4kuna\Format\Date\FormatsAccessor
		contains:
			date: h4kuna\Format\Date\Formatters\DateTimeFormatter('j.n.Y')
			time: h4kuna\Format\Date\Formatters\DateTimeFormatter('H:i:s')

Compared to the syntax with parentheses, the advantage is that you can easily add, for example, setup:

		contains:
			date: h4kuna\Format\Date\Formatters\DateTimeFormatter('j.n.Y')
			time: 
				factory: h4kuna\Format\Date\Formatters\DateTimeFormatter('H:i:s')
				setup:
					- foo

@h4kuna
Copy link
Contributor Author

h4kuna commented Sep 14, 2023

For my use case, the my way is sufficient. I would like this option to be possible. For me is important that the services are autowired: off.

I understand correctly that you are looking for a keyword for a key contains? Because this is an array of services which is one parameter. That is, it cannot be called arguments.

Your second example is standard what I would expect to work. But i don't need in this moment.

@dg dg force-pushed the master branch 8 times, most recently from 9062d04 to cd3f6d4 Compare September 28, 2023 16:13
@dg dg force-pushed the master branch 2 times, most recently from 0982df1 to 710c346 Compare October 2, 2023 20:05
@dg dg force-pushed the master branch 3 times, most recently from 680bc12 to 5066242 Compare October 15, 2023 12:34
@dg dg force-pushed the master branch 3 times, most recently from b109822 to 7f11e6e Compare November 3, 2023 00:16
@dg dg force-pushed the master branch 2 times, most recently from ef39d2d to f729b1e Compare December 14, 2023 12:50
@dg dg force-pushed the master branch 4 times, most recently from 5726063 to 9e58785 Compare February 5, 2024 23:38
@dg dg merged commit 8db41c0 into nette:master Feb 5, 2024
dg pushed a commit that referenced this pull request Feb 5, 2024
dg pushed a commit that referenced this pull request Feb 6, 2024
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.

2 participants