@@ -18,33 +18,33 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | interface ConnectableInterface |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Setter for the DSN string {@see $dsn} |
|
| 23 | - * |
|
| 24 | - * @param array $dsnArray |
|
| 25 | - * @return void |
|
| 26 | - */ |
|
| 27 | - public function setDsn(array $dsnArray); |
|
| 21 | + /** |
|
| 22 | + * Setter for the DSN string {@see $dsn} |
|
| 23 | + * |
|
| 24 | + * @param array $dsnArray |
|
| 25 | + * @return void |
|
| 26 | + */ |
|
| 27 | + public function setDsn(array $dsnArray); |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Establishes connection |
|
| 31 | - * |
|
| 32 | - * @param string $username optional |
|
| 33 | - * @param string $password optional |
|
| 34 | - * @throws [@todo get exceptions] |
|
| 35 | - * @return void |
|
| 36 | - */ |
|
| 37 | - public function connect(string $username, string $password=""); |
|
| 29 | + /** |
|
| 30 | + * Establishes connection |
|
| 31 | + * |
|
| 32 | + * @param string $username optional |
|
| 33 | + * @param string $password optional |
|
| 34 | + * @throws [@todo get exceptions] |
|
| 35 | + * @return void |
|
| 36 | + */ |
|
| 37 | + public function connect(string $username, string $password=""); |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Returns an instance a pdo intance of the connection object |
|
| 41 | - * |
|
| 42 | - * @return \PDO |
|
| 43 | - */ |
|
| 44 | - public function getConnection() : \PDO; |
|
| 39 | + /** |
|
| 40 | + * Returns an instance a pdo intance of the connection object |
|
| 41 | + * |
|
| 42 | + * @return \PDO |
|
| 43 | + */ |
|
| 44 | + public function getConnection() : \PDO; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Closes connection |
|
| 48 | - */ |
|
| 49 | - public function disableConnection(); |
|
| 46 | + /** |
|
| 47 | + * Closes connection |
|
| 48 | + */ |
|
| 49 | + public function disableConnection(); |
|
| 50 | 50 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare(strict_types=1); |
|
| 1 | +<?php declare(strict_types = 1); |
|
| 2 | 2 | /** |
| 3 | 3 | * @license MIT |
| 4 | 4 | * @author Samuel Adeshina <[email protected]> |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @throws [@todo get exceptions] |
| 35 | 35 | * @return void |
| 36 | 36 | */ |
| 37 | - public function connect(string $username, string $password=""); |
|
| 37 | + public function connect(string $username, string $password = ""); |
|
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * Returns an instance a pdo intance of the connection object |
@@ -20,22 +20,22 @@ |
||
| 20 | 20 | { |
| 21 | 21 | public $connection; |
| 22 | 22 | |
| 23 | - public function __construct(string $adapter, array $dsnArray, string $username=null, string $password=null) |
|
| 24 | - { |
|
| 25 | - $class = __NAMESPACE__."\\Adapters\\$adapter"; |
|
| 26 | - $adapterObject = new $class; |
|
| 23 | + public function __construct(string $adapter, array $dsnArray, string $username=null, string $password=null) |
|
| 24 | + { |
|
| 25 | + $class = __NAMESPACE__."\\Adapters\\$adapter"; |
|
| 26 | + $adapterObject = new $class; |
|
| 27 | 27 | |
| 28 | - if ($adapterObject instanceof ConnectableInterface) |
|
| 29 | - { |
|
| 30 | - $adapterObject->setDsn($dsnArray); |
|
| 31 | - $adapterObject->connect($username, $password); |
|
| 32 | - } |
|
| 28 | + if ($adapterObject instanceof ConnectableInterface) |
|
| 29 | + { |
|
| 30 | + $adapterObject->setDsn($dsnArray); |
|
| 31 | + $adapterObject->connect($username, $password); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - $this->connection = $adapterObject->getConnection(); |
|
| 35 | - } |
|
| 34 | + $this->connection = $adapterObject->getConnection(); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - public function getConnection() : \PDO |
|
| 38 | - { |
|
| 39 | - return $this->connection; |
|
| 40 | - } |
|
| 37 | + public function getConnection() : \PDO |
|
| 38 | + { |
|
| 39 | + return $this->connection; |
|
| 40 | + } |
|
| 41 | 41 | } |
| 42 | 42 | \ No newline at end of file |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare(strict_types=1); |
|
| 1 | +<?php declare(strict_types = 1); |
|
| 2 | 2 | /** |
| 3 | 3 | * @license MIT |
| 4 | 4 | * @author Samuel Adeshina <[email protected](clent, data)om> |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | { |
| 21 | 21 | public $connection; |
| 22 | 22 | |
| 23 | - public function __construct(string $adapter, array $dsnArray, string $username=null, string $password=null) |
|
| 23 | + public function __construct(string $adapter, array $dsnArray, string $username = null, string $password = null) |
|
| 24 | 24 | { |
| 25 | 25 | $class = __NAMESPACE__."\\Adapters\\$adapter"; |
| 26 | 26 | $adapterObject = new $class; |
@@ -1,4 +1,4 @@ |
||
| 1 | -<?php declare(strict_types=1); |
|
| 1 | +<?php declare(strict_types = 1); |
|
| 2 | 2 | /** |
| 3 | 3 | * @license MIT |
| 4 | 4 | * @author Samuel Adeshina <[email protected]> |
@@ -37,6 +37,8 @@ |
||
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * |
| 40 | + * @param string $key |
|
| 41 | + * @return string |
|
| 40 | 42 | */ |
| 41 | 43 | public static function get($key) |
| 42 | 44 | { |
@@ -17,37 +17,37 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class Session |
| 19 | 19 | { |
| 20 | - protected $session; |
|
| 20 | + protected $session; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * |
|
| 24 | - */ |
|
| 25 | - public static function init($session = "") |
|
| 26 | - { |
|
| 27 | - $this->session = $session; |
|
| 28 | - } |
|
| 22 | + /** |
|
| 23 | + * |
|
| 24 | + */ |
|
| 25 | + public static function init($session = "") |
|
| 26 | + { |
|
| 27 | + $this->session = $session; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * |
|
| 32 | - */ |
|
| 33 | - public static function save($key, $value) |
|
| 34 | - { |
|
| 35 | - $session[$key] = $value; |
|
| 36 | - } |
|
| 30 | + /** |
|
| 31 | + * |
|
| 32 | + */ |
|
| 33 | + public static function save($key, $value) |
|
| 34 | + { |
|
| 35 | + $session[$key] = $value; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * |
|
| 40 | - */ |
|
| 41 | - public static function get($key) |
|
| 42 | - { |
|
| 43 | - return $session[$key] ?? ''; |
|
| 44 | - } |
|
| 38 | + /** |
|
| 39 | + * |
|
| 40 | + */ |
|
| 41 | + public static function get($key) |
|
| 42 | + { |
|
| 43 | + return $session[$key] ?? ''; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * |
|
| 48 | - */ |
|
| 49 | - public static function delete($key) |
|
| 50 | - { |
|
| 51 | - unset($session[$key]); |
|
| 52 | - } |
|
| 46 | + /** |
|
| 47 | + * |
|
| 48 | + */ |
|
| 49 | + public static function delete($key) |
|
| 50 | + { |
|
| 51 | + unset($session[$key]); |
|
| 52 | + } |
|
| 53 | 53 | } |
@@ -20,43 +20,43 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class DatabaseConnectionFactory |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * @var \PDO $connectionObject |
|
| 25 | - */ |
|
| 26 | - private static $connectionObject; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Gets the config values defined in the database-config.json file |
|
| 30 | - * and uses the values to create a new connection object. |
|
| 31 | - */ |
|
| 32 | - public static function bootstrap() |
|
| 33 | - { |
|
| 34 | - $databaseConfigJson = file_get_contents("bin/configs/database-config.json"); |
|
| 35 | - |
|
| 36 | - $databaseConfig = json_decode($databaseConfigJson); |
|
| 37 | - |
|
| 38 | - $adapter = $databaseConfig->adapter; |
|
| 39 | - $server = $databaseConfig->server; |
|
| 40 | - $database = $databaseConfig->database; |
|
| 41 | - $username = $databaseConfig->username; |
|
| 42 | - $password = $databaseConfig->password; |
|
| 43 | - |
|
| 44 | - self::$connectionObject = new Connection($adapter, [$server, $database], $username, $password); |
|
| 45 | - |
|
| 46 | - if ($databaseConfig->showError) |
|
| 47 | - { |
|
| 48 | - self::$connectionObject->getConnection()->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
|
| 49 | - } |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Returns a new connection object |
|
| 54 | - * |
|
| 55 | - * @return \PDO |
|
| 56 | - */ |
|
| 57 | - public static function getConnection() : \PDO |
|
| 58 | - { |
|
| 59 | - self::bootstrap(); |
|
| 60 | - return self::$connectionObject->getConnection(); |
|
| 61 | - } |
|
| 23 | + /** |
|
| 24 | + * @var \PDO $connectionObject |
|
| 25 | + */ |
|
| 26 | + private static $connectionObject; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Gets the config values defined in the database-config.json file |
|
| 30 | + * and uses the values to create a new connection object. |
|
| 31 | + */ |
|
| 32 | + public static function bootstrap() |
|
| 33 | + { |
|
| 34 | + $databaseConfigJson = file_get_contents("bin/configs/database-config.json"); |
|
| 35 | + |
|
| 36 | + $databaseConfig = json_decode($databaseConfigJson); |
|
| 37 | + |
|
| 38 | + $adapter = $databaseConfig->adapter; |
|
| 39 | + $server = $databaseConfig->server; |
|
| 40 | + $database = $databaseConfig->database; |
|
| 41 | + $username = $databaseConfig->username; |
|
| 42 | + $password = $databaseConfig->password; |
|
| 43 | + |
|
| 44 | + self::$connectionObject = new Connection($adapter, [$server, $database], $username, $password); |
|
| 45 | + |
|
| 46 | + if ($databaseConfig->showError) |
|
| 47 | + { |
|
| 48 | + self::$connectionObject->getConnection()->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Returns a new connection object |
|
| 54 | + * |
|
| 55 | + * @return \PDO |
|
| 56 | + */ |
|
| 57 | + public static function getConnection() : \PDO |
|
| 58 | + { |
|
| 59 | + self::bootstrap(); |
|
| 60 | + return self::$connectionObject->getConnection(); |
|
| 61 | + } |
|
| 62 | 62 | } |
@@ -1,4 +1,4 @@ |
||
| 1 | -<?php declare(strict_types=1); |
|
| 1 | +<?php declare(strict_types = 1); |
|
| 2 | 2 | /** |
| 3 | 3 | * @license MIT |
| 4 | 4 | * @author Samuel Adeshina <[email protected]> |
@@ -19,14 +19,14 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | interface BuildableInterface |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * Builds a query object. |
|
| 24 | - * Must return a string defining an sql statement which |
|
| 25 | - * must also obey {@see DatabaseQueryableInterface} contract. |
|
| 26 | - * |
|
| 27 | - * @throws {@todo Come up with exceptions thrown by this method} |
|
| 28 | - * |
|
| 29 | - * @return BuildableInterface |
|
| 30 | - */ |
|
| 31 | - public function build(string $sqlStringToAppend); |
|
| 22 | + /** |
|
| 23 | + * Builds a query object. |
|
| 24 | + * Must return a string defining an sql statement which |
|
| 25 | + * must also obey {@see DatabaseQueryableInterface} contract. |
|
| 26 | + * |
|
| 27 | + * @throws {@todo Come up with exceptions thrown by this method} |
|
| 28 | + * |
|
| 29 | + * @return BuildableInterface |
|
| 30 | + */ |
|
| 31 | + public function build(string $sqlStringToAppend); |
|
| 32 | 32 | } |
@@ -1,4 +1,4 @@ |
||
| 1 | -<?php declare(strict_types=1); |
|
| 1 | +<?php declare(strict_types = 1); |
|
| 2 | 2 | /** |
| 3 | 3 | * @license MIT |
| 4 | 4 | * @author Samuel Adeshina <[email protected]> |
@@ -21,106 +21,106 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class SQLite implements ConnectableInterface |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * @var string $dsn |
|
| 26 | - */ |
|
| 27 | - protected $dsn; |
|
| 24 | + /** |
|
| 25 | + * @var string $dsn |
|
| 26 | + */ |
|
| 27 | + protected $dsn; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var \PDO $connectionObject |
|
| 31 | - */ |
|
| 32 | - protected $connectionObject; |
|
| 29 | + /** |
|
| 30 | + * @var \PDO $connectionObject |
|
| 31 | + */ |
|
| 32 | + protected $connectionObject; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var array loginData |
|
| 36 | - */ |
|
| 37 | - private $loginData = []; |
|
| 34 | + /** |
|
| 35 | + * @var array loginData |
|
| 36 | + */ |
|
| 37 | + private $loginData = []; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Setter for the DSN string {@see $dsn} |
|
| 41 | - * |
|
| 42 | - * MSSQl Server DSN Structure: sqlsrv:Server={srv};Database={db}" |
|
| 43 | - * `$dsnArray[0] = {srv}` |
|
| 44 | - * `$dsnArray[1] = {db}` |
|
| 45 | - * Attributes = [2 - infinity] |
|
| 46 | - * |
|
| 47 | - * @param array $dsnArray |
|
| 48 | - * @return void |
|
| 49 | - */ |
|
| 50 | - public function setDsn(array $dsnArray) |
|
| 51 | - { |
|
| 52 | - $this->dsn = $dsnArray; |
|
| 53 | - } |
|
| 39 | + /** |
|
| 40 | + * Setter for the DSN string {@see $dsn} |
|
| 41 | + * |
|
| 42 | + * MSSQl Server DSN Structure: sqlsrv:Server={srv};Database={db}" |
|
| 43 | + * `$dsnArray[0] = {srv}` |
|
| 44 | + * `$dsnArray[1] = {db}` |
|
| 45 | + * Attributes = [2 - infinity] |
|
| 46 | + * |
|
| 47 | + * @param array $dsnArray |
|
| 48 | + * @return void |
|
| 49 | + */ |
|
| 50 | + public function setDsn(array $dsnArray) |
|
| 51 | + { |
|
| 52 | + $this->dsn = $dsnArray; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Establishes connection |
|
| 57 | - * |
|
| 58 | - * @param string $username |
|
| 59 | - * @param string $password optional |
|
| 60 | - * @throws \EmmetBlue\Core\Exception\SQLException |
|
| 61 | - * @return void |
|
| 62 | - */ |
|
| 63 | - public function connect(string $username="", string $password="") |
|
| 64 | - { |
|
| 65 | - $dbLocation = $this->dsn[0]; |
|
| 55 | + /** |
|
| 56 | + * Establishes connection |
|
| 57 | + * |
|
| 58 | + * @param string $username |
|
| 59 | + * @param string $password optional |
|
| 60 | + * @throws \EmmetBlue\Core\Exception\SQLException |
|
| 61 | + * @return void |
|
| 62 | + */ |
|
| 63 | + public function connect(string $username="", string $password="") |
|
| 64 | + { |
|
| 65 | + $dbLocation = $this->dsn[0]; |
|
| 66 | 66 | |
| 67 | - try |
|
| 68 | - { |
|
| 69 | - $this->connectionObject = new \PDO("sqlite:$dbLocation"); |
|
| 70 | - } |
|
| 71 | - catch (\PDOException $e) |
|
| 72 | - { |
|
| 73 | - throw new SQLException("Unable to connect to database", 400, $e); |
|
| 74 | - } |
|
| 67 | + try |
|
| 68 | + { |
|
| 69 | + $this->connectionObject = new \PDO("sqlite:$dbLocation"); |
|
| 70 | + } |
|
| 71 | + catch (\PDOException $e) |
|
| 72 | + { |
|
| 73 | + throw new SQLException("Unable to connect to database", 400, $e); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - $dsn = $this->dsn; |
|
| 77 | - unset($dsn[0]); |
|
| 76 | + $dsn = $this->dsn; |
|
| 77 | + unset($dsn[0]); |
|
| 78 | 78 | |
| 79 | - foreach ($dsn as $attribute) |
|
| 80 | - { |
|
| 81 | - foreach ($attribute as $key=>$value) |
|
| 82 | - { |
|
| 83 | - $this->connectionObject->setAttribute($key, $value); |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - } |
|
| 79 | + foreach ($dsn as $attribute) |
|
| 80 | + { |
|
| 81 | + foreach ($attribute as $key=>$value) |
|
| 82 | + { |
|
| 83 | + $this->connectionObject->setAttribute($key, $value); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Returns an instance a pdo intance of the connection object |
|
| 90 | - * |
|
| 91 | - * @return \PDO |
|
| 92 | - */ |
|
| 93 | - public function getConnection() : \PDO |
|
| 94 | - { |
|
| 95 | - if ($this->connectionObject instanceof \PDO) |
|
| 96 | - { |
|
| 97 | - return $this->connectionObject; |
|
| 98 | - } |
|
| 88 | + /** |
|
| 89 | + * Returns an instance a pdo intance of the connection object |
|
| 90 | + * |
|
| 91 | + * @return \PDO |
|
| 92 | + */ |
|
| 93 | + public function getConnection() : \PDO |
|
| 94 | + { |
|
| 95 | + if ($this->connectionObject instanceof \PDO) |
|
| 96 | + { |
|
| 97 | + return $this->connectionObject; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - $this->connect( |
|
| 101 | - $this->loginData['username'] ?? '', |
|
| 102 | - $this->loginData['password'] ?? '' |
|
| 103 | - ); |
|
| 100 | + $this->connect( |
|
| 101 | + $this->loginData['username'] ?? '', |
|
| 102 | + $this->loginData['password'] ?? '' |
|
| 103 | + ); |
|
| 104 | 104 | |
| 105 | - return $this->connectionObject; |
|
| 106 | - } |
|
| 105 | + return $this->connectionObject; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Closes connection |
|
| 110 | - */ |
|
| 111 | - public function disableConnection() |
|
| 112 | - { |
|
| 113 | - $this->connectionObject = null; |
|
| 114 | - } |
|
| 108 | + /** |
|
| 109 | + * Closes connection |
|
| 110 | + */ |
|
| 111 | + public function disableConnection() |
|
| 112 | + { |
|
| 113 | + $this->connectionObject = null; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * Sets attributes for the PDO object |
|
| 118 | - * |
|
| 119 | - * @param \PDO $attribute |
|
| 120 | - * @param \PDO $value |
|
| 121 | - */ |
|
| 122 | - public function setAttribute(\PDO $attribute, \PDO $value) |
|
| 123 | - { |
|
| 124 | - $this->connectionObject->setAttribute($attribute, $value); |
|
| 125 | - } |
|
| 116 | + /** |
|
| 117 | + * Sets attributes for the PDO object |
|
| 118 | + * |
|
| 119 | + * @param \PDO $attribute |
|
| 120 | + * @param \PDO $value |
|
| 121 | + */ |
|
| 122 | + public function setAttribute(\PDO $attribute, \PDO $value) |
|
| 123 | + { |
|
| 124 | + $this->connectionObject->setAttribute($attribute, $value); |
|
| 125 | + } |
|
| 126 | 126 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare(strict_types=1); |
|
| 1 | +<?php declare(strict_types = 1); |
|
| 2 | 2 | /** |
| 3 | 3 | * @license MIT |
| 4 | 4 | * @author Samuel Adeshina <[email protected]> |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @throws \EmmetBlue\Core\Exception\SQLException |
| 61 | 61 | * @return void |
| 62 | 62 | */ |
| 63 | - public function connect(string $username="", string $password="") |
|
| 63 | + public function connect(string $username = "", string $password = "") |
|
| 64 | 64 | { |
| 65 | 65 | $dbLocation = $this->dsn[0]; |
| 66 | 66 | |
@@ -71,8 +71,7 @@ |
||
| 71 | 71 | try |
| 72 | 72 | { |
| 73 | 73 | $this->connectionObject = new \PDO("sqlsrv:Server=$server;Database=$database", $username, $password); |
| 74 | - } |
|
| 75 | - catch (\PDOException $e) |
|
| 74 | + } catch (\PDOException $e) |
|
| 76 | 75 | { |
| 77 | 76 | throw new SQLException("Unable to connect to database", 400, $e); |
| 78 | 77 | } |
@@ -71,8 +71,7 @@ |
||
| 71 | 71 | try |
| 72 | 72 | { |
| 73 | 73 | $this->connectionObject = new \PDO("sqlsrv:Server=$server;Database=$database", $username, $password); |
| 74 | - } |
|
| 75 | - catch (\PDOException $e) |
|
| 74 | + } catch (\PDOException $e) |
|
| 76 | 75 | { |
| 77 | 76 | throw new SQLException("Unable to connect to database", 400, $e); |
| 78 | 77 | } |
@@ -27,45 +27,45 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class DatabaseQueryFactory |
| 29 | 29 | { |
| 30 | - public static function insert(string $table, array $data) |
|
| 31 | - { |
|
| 32 | - $insertBuilder = (new Builder("QueryBuilder","Insert"))->getBuilder(); |
|
| 33 | - $columns = []; |
|
| 34 | - $values = []; |
|
| 30 | + public static function insert(string $table, array $data) |
|
| 31 | + { |
|
| 32 | + $insertBuilder = (new Builder("QueryBuilder","Insert"))->getBuilder(); |
|
| 33 | + $columns = []; |
|
| 34 | + $values = []; |
|
| 35 | 35 | |
| 36 | - foreach ($data as $index=>$datum) |
|
| 37 | - { |
|
| 38 | - $columns[] = $index; |
|
| 39 | - $values[] = $datum; |
|
| 40 | - } |
|
| 36 | + foreach ($data as $index=>$datum) |
|
| 37 | + { |
|
| 38 | + $columns[] = $index; |
|
| 39 | + $values[] = $datum; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - $columns = "(".implode(", ", $columns).")"; |
|
| 43 | - $values = "(".implode(", ", $values).")"; |
|
| 44 | - $insertBuilder->into($table.$columns); |
|
| 42 | + $columns = "(".implode(", ", $columns).")"; |
|
| 43 | + $values = "(".implode(", ", $values).")"; |
|
| 44 | + $insertBuilder->into($table.$columns); |
|
| 45 | 45 | |
| 46 | - $query = (string)$insertBuilder." VALUES ".$values; |
|
| 47 | - try |
|
| 48 | - { |
|
| 49 | - $parts = explode(".", $table); |
|
| 50 | - $schemaName = $parts[0]; |
|
| 51 | - $tableName = $parts[1]; |
|
| 46 | + $query = (string)$insertBuilder." VALUES ".$values; |
|
| 47 | + try |
|
| 48 | + { |
|
| 49 | + $parts = explode(".", $table); |
|
| 50 | + $schemaName = $parts[0]; |
|
| 51 | + $tableName = $parts[1]; |
|
| 52 | 52 | |
| 53 | - $connection = DBConnectionFactory::getConnection(); |
|
| 53 | + $connection = DBConnectionFactory::getConnection(); |
|
| 54 | 54 | |
| 55 | - $result = $connection->prepare((string)$query)->execute(); |
|
| 55 | + $result = $connection->prepare((string)$query)->execute(); |
|
| 56 | 56 | |
| 57 | - DatabaseLog::log(Session::get('USER_ID'), Constant::EVENT_INSERT, $schemaName, $tableName, $query); |
|
| 57 | + DatabaseLog::log(Session::get('USER_ID'), Constant::EVENT_INSERT, $schemaName, $tableName, $query); |
|
| 58 | 58 | |
| 59 | - $lastInsertId = ($connection->query("SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS int) as id")->fetchColumn()); |
|
| 59 | + $lastInsertId = ($connection->query("SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS int) as id")->fetchColumn()); |
|
| 60 | 60 | |
| 61 | - return [$result, "lastInsertId"=>$lastInsertId]; |
|
| 62 | - } |
|
| 63 | - catch (\PDOException $e) |
|
| 64 | - { |
|
| 65 | - throw new SQLException(sprintf( |
|
| 66 | - "%s", |
|
| 67 | - $e->getMessage() |
|
| 68 | - ), Constant::UNDEFINED); |
|
| 69 | - } |
|
| 70 | - } |
|
| 61 | + return [$result, "lastInsertId"=>$lastInsertId]; |
|
| 62 | + } |
|
| 63 | + catch (\PDOException $e) |
|
| 64 | + { |
|
| 65 | + throw new SQLException(sprintf( |
|
| 66 | + "%s", |
|
| 67 | + $e->getMessage() |
|
| 68 | + ), Constant::UNDEFINED); |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | 71 | } |
| 72 | 72 | \ No newline at end of file |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare(strict_types=1); |
|
| 1 | +<?php declare(strict_types = 1); |
|
| 2 | 2 | /** |
| 3 | 3 | * @license MIT |
| 4 | 4 | * @author Samuel Adeshina <[email protected]> |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | { |
| 30 | 30 | public static function insert(string $table, array $data) |
| 31 | 31 | { |
| 32 | - $insertBuilder = (new Builder("QueryBuilder","Insert"))->getBuilder(); |
|
| 32 | + $insertBuilder = (new Builder("QueryBuilder", "Insert"))->getBuilder(); |
|
| 33 | 33 | $columns = []; |
| 34 | 34 | $values = []; |
| 35 | 35 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | $values = "(".implode(", ", $values).")"; |
| 44 | 44 | $insertBuilder->into($table.$columns); |
| 45 | 45 | |
| 46 | - $query = (string)$insertBuilder." VALUES ".$values; |
|
| 46 | + $query = (string) $insertBuilder." VALUES ".$values; |
|
| 47 | 47 | try |
| 48 | 48 | { |
| 49 | 49 | $parts = explode(".", $table); |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | $connection = DBConnectionFactory::getConnection(); |
| 54 | 54 | |
| 55 | - $result = $connection->prepare((string)$query)->execute(); |
|
| 55 | + $result = $connection->prepare((string) $query)->execute(); |
|
| 56 | 56 | |
| 57 | 57 | DatabaseLog::log(Session::get('USER_ID'), Constant::EVENT_INSERT, $schemaName, $tableName, $query); |
| 58 | 58 | |
@@ -22,12 +22,12 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | class DatabaseLog implements LogInterface |
| 24 | 24 | { |
| 25 | - public static function log(string $databaseUserId, string $event, string $objectSchema, string $object, string $tSql) |
|
| 26 | - { |
|
| 27 | - $insertBuilder = (new Builder("QueryBuilder", "Insert"))->getBuilder(); |
|
| 28 | - try { |
|
| 29 | - $insertBuilder |
|
| 30 | - ->into(' |
|
| 25 | + public static function log(string $databaseUserId, string $event, string $objectSchema, string $object, string $tSql) |
|
| 26 | + { |
|
| 27 | + $insertBuilder = (new Builder("QueryBuilder", "Insert"))->getBuilder(); |
|
| 28 | + try { |
|
| 29 | + $insertBuilder |
|
| 30 | + ->into(' |
|
| 31 | 31 | [Logs].[DatabaseLog] |
| 32 | 32 | ( |
| 33 | 33 | PostTime, |
@@ -38,21 +38,21 @@ discard block |
||
| 38 | 38 | TSQL |
| 39 | 39 | ) |
| 40 | 40 | ') |
| 41 | - ->values([ |
|
| 42 | - 'GETDATE()', |
|
| 43 | - QB::wrapString($databaseUserId, "'"), |
|
| 44 | - QB::wrapString((string)$event, "'"), |
|
| 45 | - QB::wrapString($objectSchema, "'"), |
|
| 46 | - QB::wrapString($object, "'"), |
|
| 47 | - QB::wrapString(str_replace("'", "\"", $tSql), "'") |
|
| 48 | - ]); |
|
| 41 | + ->values([ |
|
| 42 | + 'GETDATE()', |
|
| 43 | + QB::wrapString($databaseUserId, "'"), |
|
| 44 | + QB::wrapString((string)$event, "'"), |
|
| 45 | + QB::wrapString($objectSchema, "'"), |
|
| 46 | + QB::wrapString($object, "'"), |
|
| 47 | + QB::wrapString(str_replace("'", "\"", $tSql), "'") |
|
| 48 | + ]); |
|
| 49 | 49 | |
| 50 | - DBConnectionFactory::getConnection()->query((string)$insertBuilder); |
|
| 51 | - } catch (\PDOException $e) { |
|
| 52 | - echo $e->getMessage(); |
|
| 53 | - throw new SQLException(sprintf( |
|
| 54 | - "Unable to store database log" |
|
| 55 | - ), 1); |
|
| 56 | - } |
|
| 57 | - } |
|
| 50 | + DBConnectionFactory::getConnection()->query((string)$insertBuilder); |
|
| 51 | + } catch (\PDOException $e) { |
|
| 52 | + echo $e->getMessage(); |
|
| 53 | + throw new SQLException(sprintf( |
|
| 54 | + "Unable to store database log" |
|
| 55 | + ), 1); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare (strict_types=1); |
|
| 1 | +<?php declare (strict_types = 1); |
|
| 2 | 2 | /** |
| 3 | 3 | * @license MIT |
| 4 | 4 | * @author Samuel Adeshina <[email protected]> |
@@ -41,13 +41,13 @@ discard block |
||
| 41 | 41 | ->values([ |
| 42 | 42 | 'GETDATE()', |
| 43 | 43 | QB::wrapString($databaseUserId, "'"), |
| 44 | - QB::wrapString((string)$event, "'"), |
|
| 44 | + QB::wrapString((string) $event, "'"), |
|
| 45 | 45 | QB::wrapString($objectSchema, "'"), |
| 46 | 46 | QB::wrapString($object, "'"), |
| 47 | 47 | QB::wrapString(str_replace("'", "\"", $tSql), "'") |
| 48 | 48 | ]); |
| 49 | 49 | |
| 50 | - DBConnectionFactory::getConnection()->query((string)$insertBuilder); |
|
| 50 | + DBConnectionFactory::getConnection()->query((string) $insertBuilder); |
|
| 51 | 51 | } catch (\PDOException $e) { |
| 52 | 52 | echo $e->getMessage(); |
| 53 | 53 | throw new SQLException(sprintf( |