- 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:
1 parent
9df7e65dcf
commit
5bd60129ea
22 files changed
+547
-103
No files matched your search
@@ -7,4 +7,5 @@ use Ulmus\Common\PdoObject;
|
||||
interface AdapterInterface {
|
||||
public function connect() : PdoObject;
|
||||
public function buildDataSourceName() : string;
|
||||
public function setup(array $configuration) : void;
|
||||
}
|
||||
@@ -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'];
|
||||
}
|
||||
}
|
||||
}
|
||||
+58
-5
@@ -4,13 +4,22 @@ namespace Ulmus\Adapter;
|
||||
|
||||
use Ulmus\Common\PdoObject;
|
||||
|
||||
use Ulmus\Exception\AdapterConfigurationException;
|
||||
|
||||
class MySQL implements AdapterInterface {
|
||||
|
||||
public string $hostname;
|
||||
|
||||
public string $database;
|
||||
|
||||
public string $username;
|
||||
|
||||
public string $password;
|
||||
|
||||
public string $charset;
|
||||
|
||||
public string $unixSocket;
|
||||
|
||||
public int $port;
|
||||
|
||||
public function __construct(
|
||||
@@ -49,20 +58,34 @@ class MySQL implements AdapterInterface {
|
||||
public function connect() : PdoObject
|
||||
{
|
||||
try {
|
||||
$obj = new PdoObject($this->buildDataSourceName(), $this->username, $this->password);
|
||||
$pdo = new PdoObject($this->buildDataSourceName(), $this->username, $this->password);
|
||||
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
$pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
|
||||
$pdo->setAttribute(\PDO::ATTR_AUTOCOMMIT, false);
|
||||
$pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);
|
||||
$pdo->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
|
||||
}
|
||||
catch(PDOException $ex){
|
||||
throw $ex;
|
||||
}
|
||||
|
||||
return $obj;
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
|
||||
public function buildDataSourceName() : string
|
||||
{
|
||||
$parts[] = "host={$this->hostname}";
|
||||
if ( false !== ($this->unixSocket ?? false) ) {
|
||||
|
||||
}
|
||||
else {
|
||||
$parts[] = "host={$this->hostname}";
|
||||
|
||||
if ( false !== ( $this->port ?? false ) ) {
|
||||
$parts[] = "port={$this->port}";
|
||||
}
|
||||
}
|
||||
|
||||
$parts[] = "dbname={$this->database}";
|
||||
$parts[] = "port={$this->port}";
|
||||
|
||||
if ( $this->socket ?? false ) {
|
||||
$parts[] = "socket={$this->socket}";
|
||||
@@ -74,4 +97,34 @@ class MySQL implements AdapterInterface {
|
||||
|
||||
return "mysql:" . implode(';', $parts);
|
||||
}
|
||||
|
||||
public function setup(array $configuration) : void
|
||||
{
|
||||
$configuration = array_change_key_case($configuration, \CASE_LOWER);
|
||||
|
||||
# Either Unix Socket is used, or Host / Port
|
||||
if ( false !== ( $this->unixSocket = $connection['unix_socket'] ?? false ) ) {
|
||||
if ( false === ( $this->hostname = $connection['host'] ?? false ) ) {
|
||||
throw new AdapterConfigurationException("Your `host` name is missing from your configuration array");
|
||||
}
|
||||
|
||||
if ( false !== ( $configuration['port'] ?? false ) ) {
|
||||
$this->port = $configuration['port'];
|
||||
}
|
||||
}
|
||||
|
||||
if ( false === ( $this->database = $connection['database'] ?? false ) ) {
|
||||
throw new AdapterConfigurationException("Your `database` name is missing from your configuration array");
|
||||
}
|
||||
elseif ( false === ( $this->username = $connection['username'] ?? false ) ) {
|
||||
throw new AdapterConfigurationException("Your `username` is missing from your configuration array");
|
||||
}
|
||||
elseif ( false === ( $this->password = $connection['password'] ?? false ) ) {
|
||||
throw new AdapterConfigurationException("Your `password` is missing from your configuration array");
|
||||
}
|
||||
|
||||
if ( false !== ( $configuration['charset'] ?? false ) ) {
|
||||
$this->charset = $configuration['charset'];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user