Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into column-definition-builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Oct 15, 2024
2 parents 08395bf + b9c2ce9 commit 6d3bf21
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/active-record.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

env:
COMPOSER_ROOT_VERSION: dev-master
EXTENSIONS: pdo, pdo_mysql, pdo_oci, pdo_pgsql, pdo_sqlite, pdo_sqlsrv-5.10.1
EXTENSIONS: pdo, pdo_mysql, pdo_oci, pdo_pgsql, pdo_sqlite, pdo_sqlsrv-5.12

runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -77,6 +77,11 @@ jobs:
options: --name=mssql --health-cmd="/opt/mssql-tools18/bin/sqlcmd -C -S localhost -U SA -P 'YourStrong!Passw0rd' -Q 'SELECT 1'" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- name: Install ODBC driver.
run: |
sudo curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18
- name: Checkout.
uses: actions/checkout@v3

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
- Enh #881: Refactor `ColumnSchemaInterface` and `AbstractColumnSchema` (@Tigrov)
- New #882: Move `ArrayColumnSchema` and `StructuredColumnSchema` classes from `db-pgsql` package (@Tigrov)
- New #883: Add `ColumnDefinitionBuilder` class and `QueryBuilderInterface::buildColumnDefinition()` method (@Tigrov)
- End #882: Move `ArrayColumnSchema` and `StructuredColumnSchema` classes from `db-pgsql` package (@Tigrov)
- Enh #885: Refactor `AbstractDsn` class (@Tigrov)

## 1.3.0 March 21, 2024

Expand Down
38 changes: 19 additions & 19 deletions src/Connection/AbstractDsn.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

use Stringable;

use function implode;

/**
* It's typically used to parse a DSN string, which is a string that has all the necessary information to connect
* to a database, such as the database driver, hostname, database name, port, and options.
Expand All @@ -17,37 +15,37 @@
abstract class AbstractDsn implements DsnInterface, Stringable
{
/**
* @psalm-param string[] $options
* @param string $driver The database driver name.
* @param string $host The database host name or IP address.
* @param string|null $databaseName The database name to connect to.
* @param string|null $port The database port. Null if isn't set.
* @param string[] $options The database connection options. Default value to an empty array.
*
* @psalm-param array<string,string> $options
*/
public function __construct(
private string $driver,
private string $host,
private string|null $databaseName = null,
private string|null $port = null,
private array $options = []
private readonly string $driver,
private readonly string $host,
private readonly string|null $databaseName = null,
private readonly string|null $port = null,
private readonly array $options = []
) {
}

public function asString(): string
{
$dsn = "$this->driver:" . "host=$this->host";
$dsn = "$this->driver:host=$this->host";

if ($this->databaseName !== null && $this->databaseName !== '') {
$dsn .= ';' . "dbname=$this->databaseName";
$dsn .= ";dbname=$this->databaseName";
}

if ($this->port !== null) {
$dsn .= ';' . "port=$this->port";
$dsn .= ";port=$this->port";
}

$parts = [];

foreach ($this->options as $key => $value) {
$parts[] = "$key=$value";
}

if (!empty($parts)) {
$dsn .= ';' . implode(';', $parts);
$dsn .= ";$key=$value";
}

return $dsn;
Expand Down Expand Up @@ -86,7 +84,9 @@ public function getHost(): string
}

/**
* @return array The database connection options. Default value to an empty array.
* @return string[] The database connection options. Default value to an empty array.
*
* @psalm-return array<string,string>
*/
public function getOptions(): array
{
Expand Down

0 comments on commit 6d3bf21

Please sign in to comment.