Я думаю, что вы можете добавить его в конструктор, например: // App / Services / Config / Database / Connection.php
<?php
namespace App\Service\Config\Database;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Configuration;
use Doctrine\Common\EventManager;
use App\Service\ConnectionService;
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
class Connection extends \Doctrine\DBAL\Connection
{
/**
*@var ConnectionService
*/
protected $connectionService;
public function __construct(
ConnectionService $connectionService
array $params,
Driver $driver,
?Configuration $config = null,
?EventManager $eventManager = null
)
{
$company = "api";
$db_name = "speyce_" . $company;
$params['dbname'] = $db_name;
parent::__construct($params, $driver, $config, $eventManager);
$this->$connectionService = $connectionService;
}
}
Или с помощью инжектора установки:
namespace App\Service\Config\Database;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Configuration;
use Doctrine\Common\EventManager;
use App\Service\ConnectionService;
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
class Connection extends \Doctrine\DBAL\Connection
{
/**
*@var ConnectionService
*/
protected $connectionService;
public function __construct(
array $params,
Driver $driver,
?Configuration $config = null,
?EventManager $eventManager = null
)
{
$company = "api";
$db_name = "speyce_" . $company;
$params['dbname'] = $db_name;
parent::__construct($params, $driver, $config, $eventManager);
}
public function setConnectionService(ConnectionService $cs){
$this->connectionService = $cs
}
}
В твоих services.yml
connection.service:
class: App\Service\ConnectionService
App\Service\Config\Database\Connection:
calls:
- ['setConnectionService', ["@connection.service"]]