I could make an instance of PDO
and inject it successfully. I defined the PDO::class
directly and injected it in the constructor with __const
You have multiple options:
1. Extending PDO
use PDO;
class PDO2 extends PDO
{
// must be empty
}
The container definition:
use PDO2;
// ...
return [
PDO::class => function (ContainerInterface $container) {
return new PDO(...);
},
PDO2::class => function (ContainerInterface $container) {
return new PDO2(...);
},
];
Usage
use PDO;
use PDO2;
class MyRepository
{
private $pdo;
private $pdo2;
public function __construct(PDO $pdo, PDO2 $pdo2)
{
$this->pdo = $pdo;
$this->pdo2 = $pdo2;
}
}
2. Autowired objects
See Matthieu Napoli's answer: https://stackoverflow.com/a/57758106/1461181