@@ -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 |
@@ -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 | } |
@@ -21,110 +21,110 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class SQlServer 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 | - $server = $this->dsn[0]; |
|
| 66 | - $database = $this->dsn[1]; |
|
| 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 | + $server = $this->dsn[0]; |
|
| 66 | + $database = $this->dsn[1]; |
|
| 67 | 67 | |
| 68 | - $this->loginData['username'] = $username; |
|
| 69 | - $this->loginData['password'] = $password; |
|
| 68 | + $this->loginData['username'] = $username; |
|
| 69 | + $this->loginData['password'] = $password; |
|
| 70 | 70 | |
| 71 | - try |
|
| 72 | - { |
|
| 73 | - $this->connectionObject = new \PDO("sqlsrv:Server=$server;Database=$database;ConnectionPooling=0", $username, $password); |
|
| 74 | - } |
|
| 75 | - catch (\PDOException $e) |
|
| 76 | - { |
|
| 77 | - throw new SQLException("Unable to connect to database", 400, $e); |
|
| 78 | - } |
|
| 71 | + try |
|
| 72 | + { |
|
| 73 | + $this->connectionObject = new \PDO("sqlsrv:Server=$server;Database=$database;ConnectionPooling=0", $username, $password); |
|
| 74 | + } |
|
| 75 | + catch (\PDOException $e) |
|
| 76 | + { |
|
| 77 | + throw new SQLException("Unable to connect to database", 400, $e); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - $dsn = $this->dsn; |
|
| 81 | - unset($dsn[0], $dsn[1]); |
|
| 80 | + $dsn = $this->dsn; |
|
| 81 | + unset($dsn[0], $dsn[1]); |
|
| 82 | 82 | |
| 83 | - foreach ($dsn as $attribute) |
|
| 84 | - { |
|
| 85 | - foreach ($attribute as $key=>$value) |
|
| 86 | - { |
|
| 87 | - $this->connectionObject->setAttribute($key, $value); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - } |
|
| 83 | + foreach ($dsn as $attribute) |
|
| 84 | + { |
|
| 85 | + foreach ($attribute as $key=>$value) |
|
| 86 | + { |
|
| 87 | + $this->connectionObject->setAttribute($key, $value); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Returns an instance a pdo intance of the connection object |
|
| 94 | - * |
|
| 95 | - * @return \PDO |
|
| 96 | - */ |
|
| 97 | - public function getConnection() : \PDO |
|
| 98 | - { |
|
| 99 | - if ($this->connectionObject instanceof \PDO) |
|
| 100 | - { |
|
| 101 | - return $this->connectionObject; |
|
| 102 | - } |
|
| 92 | + /** |
|
| 93 | + * Returns an instance a pdo intance of the connection object |
|
| 94 | + * |
|
| 95 | + * @return \PDO |
|
| 96 | + */ |
|
| 97 | + public function getConnection() : \PDO |
|
| 98 | + { |
|
| 99 | + if ($this->connectionObject instanceof \PDO) |
|
| 100 | + { |
|
| 101 | + return $this->connectionObject; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - $this->connect( |
|
| 105 | - $this->loginData['username'] ?? '', |
|
| 106 | - $this->loginData['password'] ?? '' |
|
| 107 | - ); |
|
| 104 | + $this->connect( |
|
| 105 | + $this->loginData['username'] ?? '', |
|
| 106 | + $this->loginData['password'] ?? '' |
|
| 107 | + ); |
|
| 108 | 108 | |
| 109 | - return $this->connectionObject; |
|
| 110 | - } |
|
| 109 | + return $this->connectionObject; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Closes connection |
|
| 114 | - */ |
|
| 115 | - public function disableConnection() |
|
| 116 | - { |
|
| 117 | - $this->connectionObject = null; |
|
| 118 | - } |
|
| 112 | + /** |
|
| 113 | + * Closes connection |
|
| 114 | + */ |
|
| 115 | + public function disableConnection() |
|
| 116 | + { |
|
| 117 | + $this->connectionObject = null; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Sets attributes for the PDO object |
|
| 122 | - * |
|
| 123 | - * @param \PDO $attribute |
|
| 124 | - * @param \PDO $value |
|
| 125 | - */ |
|
| 126 | - public function setAttribute(\PDO $attribute, \PDO $value) |
|
| 127 | - { |
|
| 128 | - $this->connectionObject->setAttribute($attribute, $value); |
|
| 129 | - } |
|
| 120 | + /** |
|
| 121 | + * Sets attributes for the PDO object |
|
| 122 | + * |
|
| 123 | + * @param \PDO $attribute |
|
| 124 | + * @param \PDO $value |
|
| 125 | + */ |
|
| 126 | + public function setAttribute(\PDO $attribute, \PDO $value) |
|
| 127 | + { |
|
| 128 | + $this->connectionObject->setAttribute($attribute, $value); |
|
| 129 | + } |
|
| 130 | 130 | } |
@@ -24,9 +24,9 @@ |
||
| 24 | 24 | { |
| 25 | 25 | $configJson = file_get_contents("bin/configs/elasticsearch-config.json"); |
| 26 | 26 | |
| 27 | - $config = json_decode($configJson); |
|
| 27 | + $config = json_decode($configJson); |
|
| 28 | 28 | |
| 29 | - self::$clientObject = $config; |
|
| 29 | + self::$clientObject = $config; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public static function getClient() |