Skip to content

Symfony bundle - Handle driver configuration with Reference class #311

@MarosPixel

Description

@MarosPixel

Describe the bug
Sending driver as reference doesn't work in Symfony Bundle configuration. Nextras receives driver as plain string, does not transform it into object from container.

nextras_dbal:
    connections:
            name: example
            driver: '@App\AcmeDriver'

When I check Nextras\Dbal\Connection method, this class allows usage of IDriver instance:

	private function createDriver(): IDriver
	{
		if (!isset($this->config['driver'])) {
			throw new InvalidArgumentException('Undefined driver. Choose from: mysqli, pgsql, sqlsrv, pdo_mysql, pdo_pgsql.');
		} elseif ($this->config['driver'] instanceof IDriver) {
			return $this->config['driver'];
		} else {
			$driver = $this->config['driver'];
			$name = ucfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', (string) $driver))));
			/** @var class-string<IDriver> $class */
			$class = "Nextras\\Dbal\\Drivers\\{$name}\\{$name}Driver";
			return new $class();
		}
	}

Versions::

  • symfony/*: 7.3
  • nextras/dbal: 5.0.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions