- Added a new MsSQL adapter

- Some bugfixes were made within annotations.
- Added a new Object Instanciator which allows to manipulate and define how an object from an entity must be instanciated with given value.
This commit is contained in:
Dave Mc Nicoll committed 2020-01-29 16:11:16 -05:00
1 parent 9df7e65dcf
commit 5bd60129ea
22 files changed
+547 -103

No files matched your search

+188
View File
@@ -0,0 +1,188 @@
<?php
namespace Ulmus\Adapter;
use Ulmus\Common\PdoObject;
use Ulmus\Exception\AdapterConfigurationException;
class MsSQL implements AdapterInterface {
public int $port;
public int $transactionIsolation;
public int $connectionPooling = 0;
public bool $encrypt;
public bool $multipleActiveResultSets;
public bool $traceOn;
public string $app;
public string $server;
public string $database;
public string $username;
public string $password;
public string $traceFile;
public string $failoverPartner;
public string $wsid;
public function __construct(
?string $server = null,
?string $database = null,
?string $username = null,
?string $password = null,
?int $port = null
) {
if ($server) {
$this->server = $server;
}
if ($database) {
$this->database = $database;
}
if ($port) {
$this->port = $port;
}
if ($username) {
$this->username = $username;
}
if ($password) {
$this->password = $password;
}
}
public function connect() : PdoObject
{
try {
$pdo = new PdoObject($this->buildDataSourceName(), $this->username, $this->password);
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);
$pdo->setAttribute(\PDO::SQLSRV_ATTR_ENCODING, \PDO::SQLSRV_ENCODING_UTF8);
}
catch(PDOException $ex){
throw $ex;
}
return $pdo;
}
public function buildDataSourceName() : string
{
$parts[] = "Server={$this->server}" . ( isset($this->port) ? ",{$this->port}" : "" );
$parts[] = "Database={$this->database}";
$parts[] = "ConnectionPooling={$this->connectionPooling}";
if ( $this->app ?? false ) {
$parts[] = "APP={$this->app}";
}
if ( $this->encrypt ?? false ) {
$parts[] = "Encrypt=1";
}
if ( $this->failoverPartner ?? false ) {
$parts[] = "Failover_Partner={$this->failoverPartner}";
}
if ( $this->loginTimeout ?? false ) {
$parts[] = "LoginTimeout={$this->loginTimeout}";
}
if ( $this->multipleActiveResultSets ?? false ) {
$parts[] = "MultipleActiveResultSets=1";
}
if ( $this->quotedId ?? false ) {
$parts[] = "QuotedId=1";
}
if ( $this->traceFile ?? false ) {
$parts[] = "TraceFile={$this->traceFile}";
}
if ( $this->traceOn ?? false ) {
$parts[] = "TraceOn=1";
}
if ( $this->transactionIsolation ?? false ) {
$parts[] = "TransactionIsolation={$this->transactionIsolation}";
}
if ( $this->trustServerCertificate ?? false ) {
$parts[] = "TrustServerCertificate=1";
}
if ( $this->WSID ?? false ) {
$parts[] = "WSID={$this->wsid}";
}
return "sqlsrv:" . implode(';', $parts);
}
public function setup(array $configuration) : void
{
$configuration = array_change_key_case($configuration, \CASE_LOWER);
if ( false === ( $this->server = $configuration['server'] ?? false ) ) {
throw new AdapterConfigurationException("Your `server` setting is missing. It is a mandatory parameter for this driver.");
}
elseif ( false === ( $this->database = $configuration['database'] ?? false ) ) {
throw new AdapterConfigurationException("Your `database` setting is missing. The adapter won't connect without it.");
}
elseif ( false === ( $this->username = $configuration['username'] ?? false ) ) {
throw new AdapterConfigurationException("Your `username` is missing from your configuration array");
}
elseif ( false === ( $this->password = $configuration['password'] ?? false ) ) {
throw new AdapterConfigurationException("Your `password` is missing from your configuration array");
}
if ( false !== ( $configuration['app'] ?? false ) ) {
$this->app = $configuration['app'];
}
if ( false !== ( $configuration['port'] ?? false ) ) {
$this->port = $configuration['port'];
}
if ( false !== ( $configuration['failover_partner'] ?? false ) ) {
$this->failoverPartner = $configuration['failover_partner'];
}
if ( false !== ( $configuration['wsid'] ?? false ) ) {
$this->wsid = $configuration['wsid'];
}
if ( false !== ( $configuration['transaction_isolation'] ?? false ) ) {
$this->transactionIsolation = $configuration['transaction_isolation'];
}
if ( false !== ( $configuration['connection_pooling'] ?? false ) ) {
$this->connectionPooling = $configuration['connection_pooling'];
}
if ( false !== ( $configuration['encrypt'] ?? false ) ) {
$this->encrypt = $configuration['encrypt'];
}
if ( false !== ( $configuration['multiple_active_result_sets'] ?? false ) ) {
$this->multipleActiveResultSets = $configuration['multiple_active_result_sets'];
}
if ( false !== ( $configuration['trace_on'] ?? false ) ) {
$this->traceOn = $configuration['trace_on'];
}
}
}