More complex setup of service

6 years ago

mkoubik
Generous Backer | 734
+
0
-

How do I call chain of methods in service's setup? I use it for doctrine's connection.
This:

services:
	doctrine.conenction:
		factory: ...
		setup:
			- getDatabasePlatform()->registerDoctrinetypeMapping(enum, string)

doesn't work.

And this:

services:
	doctrine.connection:
		factory: ...
		setup:
			- @doctrine.platform::registerDoctrinetypeMapping(enum, string)

	doctrine.platform:
		factory: @doctrine.connection::getDatabasePlatform()

(obviously) complains about circular reference.

6 years ago

Majkl578
Moderator | 1379
+
0
-

One option might be:

setup:
    - "?->getDatabasePlatform()->registerDoctrinetypeMapping(?, ?)"(@self, "enum", "string")

6 years ago

Filip Procházka
Moderator | 4693
+
0
-

Or you could just use kdyby/doctrine ;)

doctrine:
	types:
		myType: My\Cool\Type

Theese complicated setups are better done in compiler extensions.

Last edited by Filip Procházka (2013-09-17 00:42)

6 years ago

Honza Marek
Member | 1674
+
0
-

You should implement factory in PHP instead of programming in neon.

6 years ago

mkoubik
Generous Backer | 734
+
0
-

I know, but the goal of this is simplicity:

  • require doctrine/orm
  • include one neon config (seems more clear to me than extension)
  • done

6 years ago

enumag
Member | 2128
+
0
-

@mkoubik: Well with Kdyby/Doctrine it's even more simple:

  • require kdyby/doctrine
  • register extension + add database username, pass, … (about 5 lines total in config.neon)
  • done ;-)

6 years ago

mkoubik
Generous Backer | 734
+
0
-

Yeah, but kdyby/doctrine is full of stuff i don't need.

Also I don't like using extensions for things that don't need to be integrated to nette (I use kdyby/console though). All I need is to get the entity manager to DI container, everything else is job for my domain/persistence logic.

Last edited by mkoubik (2013-09-17 22:23)

6 years ago

Filip Procházka
Moderator | 4693
+
0
-

mkoubik wrote:

include one neon config (seems more clear to me than extension)

Well, it's not :) And you're spending preciouse hours on something that has been already done and it's much better already, because shitload of people is using it and reporting stuff.

Yeah, but kdyby/doctrine is full of stuff i don't need.

<OT>You may think that, but you're wrong :) I'm gonna interrogate you at some posobota :P</OT>

Last edited by Filip Procházka (2013-09-18 13:43)

6 years ago

mkoubik
Generous Backer | 734
+
0
-

It's because doctrine is full of stuff I don't need (but also full of stuf that I desperately need and that are not included in no existing php orm). Kdyby/Doctrine is great for builduing anemic CRUD model, but full of antipatterns from DDD's point of view. Looking forward to discussing it.