Database connection class hard-wired in Nette Extension

8 years ago

Kacer_Bob
Member | 6
+
0
-

Hi,
is there any reason why class ‘Nette\Database\Connection’ is hard-wired into NetteExtension?
I'd like to use my own descendant of that class, but I'm not able to change used class in config.neon.
I expected that if I use following definition I'll get object of specified class:

<?php
nette:
	database:
		default:
			class: \MyDatabase\Class
?>

8 years ago

HosipLan
Moderator | 4693
+
0
-

No, you won't. You'd have to change class of the service. That part you're trying si parameters for extensions.

services:
	nette.database.default:
		class: MyDatabase\MyClass

But after this, makes no sense for you to let Nette configure NDB, because you'd have to pass the parameters “by hand”. So just create new configured service, and don't configure the section in nette:.

services:
	connection:
		class: MyDatabase\MyClass("host=localhost;...", ...)