tl;dr: Nette Database always creates its own new instance of the PDO object. This issue addresses the question of whether it is possible to change the logic so that Nette Database can works as a wrapper for an existing PDO.
I specialize to maintenance and modernization of older applications that cannot be refactored from the ground up, but require gradual reworking in parts.
I often encounter the limitation of Nette Database that its instance can only be initiated via DSN and always requires the creation of its own PDO object.
However, from code analysis, it seems obvious to me that there is no objective reason for this and there is no obstacle to Nette Database being able to accept an existing PDO object.
So far, I have bypass this limitation by rewriting the original PDO initialization in the legacy application so that the Nette Database object was created first, from which I obtained the object via Connection::getPdo() and passed it to the legacy application.
I am currently working on a project where I no longer have the option to change the logic of creating a PDO object. Therefore, I have no choice but to try to modify Nette Database so that I can use it in the project for modernizing cocebase.
Questions:
- is there any blocker in the Nette Database codebase that prevents my suggestion and I have looked at it?
- is it okay for you to change the signature of the
\Nette\Database\Connection class constructor as below or i better to create child with rewrited signature?
public function __construct(
private readonly string|PDO $dsn,
#[\SensitiveParameter]
private readonly ?string $user = null,
#[\SensitiveParameter]
private readonly ?string $password = null,
private readonly array $options = [],
)
tl;dr: Nette Database always creates its own new instance of the PDO object. This issue addresses the question of whether it is possible to change the logic so that Nette Database can works as a wrapper for an existing PDO.
I specialize to maintenance and modernization of older applications that cannot be refactored from the ground up, but require gradual reworking in parts.
I often encounter the limitation of Nette Database that its instance can only be initiated via DSN and always requires the creation of its own PDO object.
However, from code analysis, it seems obvious to me that there is no objective reason for this and there is no obstacle to Nette Database being able to accept an existing PDO object.
So far, I have bypass this limitation by rewriting the original PDO initialization in the legacy application so that the Nette Database object was created first, from which I obtained the object via
Connection::getPdo()and passed it to the legacy application.I am currently working on a project where I no longer have the option to change the logic of creating a PDO object. Therefore, I have no choice but to try to modify Nette Database so that I can use it in the project for modernizing cocebase.
Questions:
\Nette\Database\Connectionclass constructor as below or i better to create child with rewrited signature?