Connection example



    private function setupDB(Connection $orgConnection): Connection
    {
        // Be sure that we are on the no migrations db         static::assertStringContainsString('_no_migrations', $this->databaseName, 'Wrong DB ' . $this->databaseName);

        $orgConnection->executeStatement('DROP DATABASE IF EXISTS `' . $this->databaseName . '`');

        $orgConnection->executeStatement('CREATE DATABASE `' . $this->databaseName . '` DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci');

        $connection = new Connection(
            array_merge(
                $orgConnection->getParams(),
                [
                    'url' => $_SERVER['DATABASE_URL'],
                    'dbname' => $this->databaseName,
                ]
            ),
            $orgConnection->getDriver(),
            $orgConnection->getConfiguration(),
        );

        
/** * @param array<string, mixed> $options */
    public function createTransport(string $dsn, array $options, SerializerInterface $serializer): TransportInterface
    {
        unset($options['transport_name']$options['use_notify']);

        // Always allow PostgreSQL-specific keys, to be able to transparently fallback to the native driver when LISTEN/NOTIFY isn't available         $configuration = Connection::buildConfiguration($dsn$options);

        $connection = new Connection($configuration$this->connection);

        return new DoctrineTransport($connection$serializer);
    }

    /** * @param array<string, mixed> $options */
    public function supports(string $dsn, array $options): bool
    {
        return str_starts_with($dsn, 'doctrine://');
    }
}
Home | Imprint | This part of the site doesn't use cookies.