- 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

+14 -30
View File
@@ -19,6 +19,7 @@ class ConnectionAdapter
public function __construct(string $name = "default", array $configuration = [])
{
$this->name = $name;
$this->configuration = $configuration;
if ( $name === "default" ) {
@@ -26,62 +27,45 @@ class ConnectionAdapter
}
}
public function resolveConfiguration()
public function resolveConfiguration() : void
{
$connection = $this->configuration['connections'][$this->name] ?? [];
if ( $adapterName = $connection['adapter'] ?? false ) {
if ( false !== ( $adapterName = $connection['adapter'] ?? false ) ) {
$this->adapter = $this->instanciateAdapter($adapterName);
}
else {
throw new \InvalidArgumentException("Adapter not found within your configuration array.");
}
if ( false === $this->adapter->hostname = $connection['host'] ?? false ) {
throw new \InvalidArgumentException("Your `host` name is missing from your configuration array");
}
if ( false === $this->adapter->port = $connection['port'] ?? false ) {
throw new \InvalidArgumentException("Your `port` number is missing from your configuration array");
}
if ( false === $this->adapter->database = $connection['database'] ?? false ) {
throw new \InvalidArgumentException("Your `database` name is missing from your configuration array");
}
if ( false === $this->adapter->username = $connection['username'] ?? false ) {
throw new \InvalidArgumentException("Your `username` is missing from your configuration array");
}
if ( false === $this->adapter->password = $connection['password'] ?? false ) {
throw new \InvalidArgumentException("Your `password` is missing from your configuration array");
}
$this->adapter->setup($connection);
}
/**
* Connect the adapter
* @return self
*/
public function connect()
public function connect() : self
{
$this->pdo = $this->adapter->connect();
$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$this->pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
$this->pdo->setAttribute(\PDO::ATTR_AUTOCOMMIT, false);
$this->pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);
$this->pdo->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
return $this;
}
public function adapter() : AdapterInterface
{
return $this->adapter;
}
/**
* Instanciate an adapter which interact with the data source
* @param string $name An Ulmus adapter or full class name implementing AdapterInterface
* @return AdapterInterface
*/
protected function instanciateAdapter($name)
protected function instanciateAdapter($name) : AdapterInterface
{
$class = substr($name, 0, 2) === "\\" ? $name : "\\Ulmus\\Adapter\\$name";
return new $class();
}
}