Skip to content

Commit b3ddf17

Browse files
committed
ADD Instance connection param
1 parent d18a94f commit b3ddf17

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Using $_ENV global variable
5353
```php
5454
$_ENV['DATABASE_SCHOOL_DRIVER'] = 'driver';
5555
$_ENV['DATABASE_SCHOOL_HOST'] = 'host';
56+
$_ENV['DATABASE_SCHOOL_INST'] = 'instanceName';
5657
$_ENV['DATABASE_SCHOOL_PORT'] = 'port';
5758
$_ENV['DATABASE_SCHOOL_USER'] = 'user';
5859
$_ENV['DATABASE_SCHOOL_PSWD'] = 'password';

src/ConnectParams.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class ConnectParams
1616
private $port;
1717
private $database;
1818
private $encoding;
19+
private $instance;
1920

2021
public function __construct(
2122
DriverInterface $driver,
@@ -24,7 +25,8 @@ public function __construct(
2425
?string $password = null,
2526
?string $database = null,
2627
?int $port = null,
27-
?string $encoding = null
28+
?string $encoding = null,
29+
?string $instance = null
2830
) {
2931
$this->driver = $driver;
3032
$this->host = $host;
@@ -33,6 +35,7 @@ public function __construct(
3335
$this->database = $database;
3436
$this->port = $port;
3537
$this->encoding = $encoding;
38+
$this->instance = $instance;
3639
}
3740

3841
public static function fromEnv(string $alias, ?array $env = null)
@@ -48,19 +51,21 @@ public static function fromEnv(string $alias, ?array $env = null)
4851
$encdKey = "DATABASE_{$alias}_ENCD";
4952
$pswdKey = "DATABASE_{$alias}_PSWD";
5053
$pwflKey = "DATABASE_{$alias}_PSWD_FILE";
54+
$instKey = "DATABASE_{$alias}_INST";
5155

5256
$host = $env[$hostKey] ?? $driver->getDefaultHost();
5357
$port = $env[$portKey] ?? $driver->getDefaultPort();
5458
$user = $env[$userKey] ?? $driver->getDefaultUser();
5559
$name = $env[$nameKey] ?? $alias;
5660
$encd = $env[$encdKey] ?? null;
61+
$inst = $env[$instKey] ?? null;
5762

5863
$pswd = $env[$pswdKey] ?? $driver->getDefaultPswd();
5964
if (!empty($env[$pwflKey]) && file_exists($env[$pwflKey])) {
6065
$pswd = file_get_contents($env[$pwflKey]);
6166
}
6267

63-
return new ConnectParams($driver, $host, $user, $pswd, $name, $port, $encd);
68+
return new ConnectParams($driver, $host, $user, $pswd, $name, $port, $encd, $inst);
6469
}
6570

6671
/**
@@ -159,4 +164,14 @@ public function getEncoding(): ?string
159164
{
160165
return $this->encoding;
161166
}
167+
168+
public function setInstance(?string $instance)
169+
{
170+
$this->instance = $instance;
171+
}
172+
173+
public function getInstance(): ?string
174+
{
175+
return $this->instance;
176+
}
162177
}

0 commit comments

Comments
 (0)