- 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

+58 -5
View File
@@ -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'];
}
}
}