@@ -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]> |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * @throws \EmmetBlue\Core\Exception\SQLException |
| 56 | 56 | * @return void |
| 57 | 57 | */ |
| 58 | - public function connect(string $username, string $password="") |
|
| 58 | + public function connect(string $username, string $password = "") |
|
| 59 | 59 | { |
| 60 | 60 | $host = $this->dsn[0]; |
| 61 | 61 | $database = $this->dsn[1]; |
@@ -21,105 +21,105 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class MySQL 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 | - * @param array $dsnArray |
|
| 43 | - * @return void |
|
| 44 | - */ |
|
| 45 | - public function setDsn(array $dsnArray) |
|
| 46 | - { |
|
| 47 | - $this->dsn = $dsnArray; |
|
| 48 | - } |
|
| 39 | + /** |
|
| 40 | + * Setter for the DSN string {@see $dsn} |
|
| 41 | + * |
|
| 42 | + * @param array $dsnArray |
|
| 43 | + * @return void |
|
| 44 | + */ |
|
| 45 | + public function setDsn(array $dsnArray) |
|
| 46 | + { |
|
| 47 | + $this->dsn = $dsnArray; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Establishes connection |
|
| 52 | - * |
|
| 53 | - * @param string $username |
|
| 54 | - * @param string $password optional |
|
| 55 | - * @throws \EmmetBlue\Core\Exception\SQLException |
|
| 56 | - * @return void |
|
| 57 | - */ |
|
| 58 | - public function connect(string $username, string $password="") |
|
| 59 | - { |
|
| 60 | - $host = $this->dsn[0]; |
|
| 61 | - $database = $this->dsn[1]; |
|
| 50 | + /** |
|
| 51 | + * Establishes connection |
|
| 52 | + * |
|
| 53 | + * @param string $username |
|
| 54 | + * @param string $password optional |
|
| 55 | + * @throws \EmmetBlue\Core\Exception\SQLException |
|
| 56 | + * @return void |
|
| 57 | + */ |
|
| 58 | + public function connect(string $username, string $password="") |
|
| 59 | + { |
|
| 60 | + $host = $this->dsn[0]; |
|
| 61 | + $database = $this->dsn[1]; |
|
| 62 | 62 | |
| 63 | - $this->loginData['username'] = $username; |
|
| 64 | - $this->loginData['password'] = $password; |
|
| 63 | + $this->loginData['username'] = $username; |
|
| 64 | + $this->loginData['password'] = $password; |
|
| 65 | 65 | |
| 66 | - try |
|
| 67 | - { |
|
| 68 | - $this->connectionObject = new \PDO("mysql:host=$host;dbname=$database;", $username, $password); |
|
| 69 | - } |
|
| 70 | - catch (\PDOException $e) |
|
| 71 | - { |
|
| 72 | - throw new SQLException("Unable to connect to database", 400, $e); |
|
| 73 | - } |
|
| 66 | + try |
|
| 67 | + { |
|
| 68 | + $this->connectionObject = new \PDO("mysql:host=$host;dbname=$database;", $username, $password); |
|
| 69 | + } |
|
| 70 | + catch (\PDOException $e) |
|
| 71 | + { |
|
| 72 | + throw new SQLException("Unable to connect to database", 400, $e); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - $dsn = $this->dsn; |
|
| 76 | - unset($dsn[0], $dsn[1]); |
|
| 75 | + $dsn = $this->dsn; |
|
| 76 | + unset($dsn[0], $dsn[1]); |
|
| 77 | 77 | |
| 78 | - foreach ($dsn as $attribute) |
|
| 79 | - { |
|
| 80 | - foreach ($attribute as $key=>$value) |
|
| 81 | - { |
|
| 82 | - $this->connectionObject->setAttribute($key, $value); |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - } |
|
| 78 | + foreach ($dsn as $attribute) |
|
| 79 | + { |
|
| 80 | + foreach ($attribute as $key=>$value) |
|
| 81 | + { |
|
| 82 | + $this->connectionObject->setAttribute($key, $value); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Returns an instance a pdo intance of the connection object |
|
| 89 | - * |
|
| 90 | - * @return \PDO |
|
| 91 | - */ |
|
| 92 | - public function getConnection() : \PDO |
|
| 93 | - { |
|
| 94 | - if ($this->connectionObject instanceof \PDO) |
|
| 95 | - { |
|
| 96 | - return $this->connectionObject; |
|
| 97 | - } |
|
| 87 | + /** |
|
| 88 | + * Returns an instance a pdo intance of the connection object |
|
| 89 | + * |
|
| 90 | + * @return \PDO |
|
| 91 | + */ |
|
| 92 | + public function getConnection() : \PDO |
|
| 93 | + { |
|
| 94 | + if ($this->connectionObject instanceof \PDO) |
|
| 95 | + { |
|
| 96 | + return $this->connectionObject; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - $this->connect( |
|
| 100 | - $this->loginData['username'] ?? '', |
|
| 101 | - $this->loginData['password'] ?? '' |
|
| 102 | - ); |
|
| 99 | + $this->connect( |
|
| 100 | + $this->loginData['username'] ?? '', |
|
| 101 | + $this->loginData['password'] ?? '' |
|
| 102 | + ); |
|
| 103 | 103 | |
| 104 | - return $this->connectionObject; |
|
| 105 | - } |
|
| 104 | + return $this->connectionObject; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Closes connection |
|
| 109 | - */ |
|
| 110 | - public function disableConnection() |
|
| 111 | - { |
|
| 112 | - $this->connectionObject = null; |
|
| 113 | - } |
|
| 107 | + /** |
|
| 108 | + * Closes connection |
|
| 109 | + */ |
|
| 110 | + public function disableConnection() |
|
| 111 | + { |
|
| 112 | + $this->connectionObject = null; |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Sets attributes for the PDO object |
|
| 117 | - * |
|
| 118 | - * @param \PDO $attribute |
|
| 119 | - * @param \PDO $value |
|
| 120 | - */ |
|
| 121 | - public function setAttribute(\PDO $attribute, \PDO $value) |
|
| 122 | - { |
|
| 123 | - $this->connectionObject->setAttribute($attribute, $value); |
|
| 124 | - } |
|
| 115 | + /** |
|
| 116 | + * Sets attributes for the PDO object |
|
| 117 | + * |
|
| 118 | + * @param \PDO $attribute |
|
| 119 | + * @param \PDO $value |
|
| 120 | + */ |
|
| 121 | + public function setAttribute(\PDO $attribute, \PDO $value) |
|
| 122 | + { |
|
| 123 | + $this->connectionObject->setAttribute($attribute, $value); |
|
| 124 | + } |
|
| 125 | 125 | } |
@@ -66,8 +66,7 @@ |
||
| 66 | 66 | try |
| 67 | 67 | { |
| 68 | 68 | $this->connectionObject = new \PDO("mysql:host=$host;dbname=$database;", $username, $password); |
| 69 | - } |
|
| 70 | - catch (\PDOException $e) |
|
| 69 | + } catch (\PDOException $e) |
|
| 71 | 70 | { |
| 72 | 71 | throw new SQLException("Unable to connect to database", 400, $e); |
| 73 | 72 | } |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | public function __construct(array $sender, array $recipients, array $message){ |
| 24 | 24 | $smtpConfigJson = file_get_contents(Constant::getGlobals()["config-dir"]["smtp-config"]); |
| 25 | 25 | |
| 26 | - $smtpConfig = json_decode($smtpConfigJson); |
|
| 26 | + $smtpConfig = json_decode($smtpConfigJson); |
|
| 27 | 27 | |
| 28 | 28 | $mail = new \PHPMailer; |
| 29 | 29 | $mail->SMTPDebug = $smtpConfig->debug; |
@@ -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]> |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | class MailerFactory |
| 21 | 21 | { |
| 22 | 22 | private $mail; |
| 23 | - public function __construct(array $sender, array $recipients, array $message){ |
|
| 23 | + public function __construct(array $sender, array $recipients, array $message) { |
|
| 24 | 24 | $smtpConfigJson = file_get_contents(Constant::getGlobals()["config-dir"]["smtp-config"]); |
| 25 | 25 | |
| 26 | 26 | $smtpConfig = json_decode($smtpConfigJson); |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | $this->mail = $mail; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - public function send(){ |
|
| 55 | - if (!$this->mail->send()){ |
|
| 54 | + public function send() { |
|
| 55 | + if (!$this->mail->send()) { |
|
| 56 | 56 | return $this->mail->ErrorInfo; |
| 57 | 57 | } |
| 58 | 58 | |
@@ -22,12 +22,12 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | class DatabaseLog implements LogInterface |
| 24 | 24 | { |
| 25 | - public static function logDeprecated(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 logDeprecated(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,25 +38,25 @@ 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 | |
| 59 | - public static function log(string $databaseUserId, string $event, string $objectSchema, string $object, string $tSql){ |
|
| 59 | + public static function log(string $databaseUserId, string $event, string $objectSchema, string $object, string $tSql){ |
|
| 60 | 60 | |
| 61 | - } |
|
| 61 | + } |
|
| 62 | 62 | } |
@@ -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( |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - public static function log(string $databaseUserId, string $event, string $objectSchema, string $object, string $tSql){ |
|
| 59 | + public static function log(string $databaseUserId, string $event, string $objectSchema, string $object, string $tSql) { |
|
| 60 | 60 | |
| 61 | 61 | } |
| 62 | 62 | } |
@@ -19,50 +19,50 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class Constant |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * Events |
|
| 24 | - */ |
|
| 25 | - const EVENT_INSERT = 'EVENT: INSERT DML EVENT'; |
|
| 26 | - const EVENT_SELECT = 'EVENT: SELECT DML EVENT'; |
|
| 27 | - const EVENT_UPDATE = 'EVENT: UPDATE DML EVENT'; |
|
| 22 | + /** |
|
| 23 | + * Events |
|
| 24 | + */ |
|
| 25 | + const EVENT_INSERT = 'EVENT: INSERT DML EVENT'; |
|
| 26 | + const EVENT_SELECT = 'EVENT: SELECT DML EVENT'; |
|
| 27 | + const EVENT_UPDATE = 'EVENT: UPDATE DML EVENT'; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @author Lucky Bardeson |
|
| 31 | - */ |
|
| 32 | - const EVENT_DELETE = 'EVENT: DELETE DML EVENT'; |
|
| 29 | + /** |
|
| 30 | + * @author Lucky Bardeson |
|
| 31 | + */ |
|
| 32 | + const EVENT_DELETE = 'EVENT: DELETE DML EVENT'; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Error Numbers |
|
| 36 | - */ |
|
| 37 | - const ERROR_401 = 'ERROR_401: Resource Inaccessible'; |
|
| 38 | - const ERROR_402 = 'ERROR_402: Resource Requirements Not Met'; |
|
| 39 | - const ERROR_403 = 'ERROR_403: Resource Not Writable'; |
|
| 40 | - const ERROR_404 = 'ERROR_404: Resource Not Found'; |
|
| 34 | + /** |
|
| 35 | + * Error Numbers |
|
| 36 | + */ |
|
| 37 | + const ERROR_401 = 'ERROR_401: Resource Inaccessible'; |
|
| 38 | + const ERROR_402 = 'ERROR_402: Resource Requirements Not Met'; |
|
| 39 | + const ERROR_403 = 'ERROR_403: Resource Not Writable'; |
|
| 40 | + const ERROR_404 = 'ERROR_404: Resource Not Found'; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Error Severities |
|
| 44 | - */ |
|
| 45 | - const ERROR_HIGH = 'ERROR_SEVERITY: HIGH'; |
|
| 46 | - const ERROR_LOW = 'ERROR_SEVERITY: LOW'; |
|
| 47 | - const ERROR_NORMAL = 'ERROR_SEVERITY: NORMAL'; |
|
| 42 | + /** |
|
| 43 | + * Error Severities |
|
| 44 | + */ |
|
| 45 | + const ERROR_HIGH = 'ERROR_SEVERITY: HIGH'; |
|
| 46 | + const ERROR_LOW = 'ERROR_SEVERITY: LOW'; |
|
| 47 | + const ERROR_NORMAL = 'ERROR_SEVERITY: NORMAL'; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * |
|
| 51 | - */ |
|
| 52 | - const UNDEFINED = 0; |
|
| 49 | + /** |
|
| 50 | + * |
|
| 51 | + */ |
|
| 52 | + const UNDEFINED = 0; |
|
| 53 | 53 | |
| 54 | - public static function getGlobals($config = "configs") { |
|
| 55 | - if (is_file("globals.json")){ |
|
| 56 | - $globalLoc = json_decode(file_get_contents("globals.json"), true); |
|
| 54 | + public static function getGlobals($config = "configs") { |
|
| 55 | + if (is_file("globals.json")){ |
|
| 56 | + $globalLoc = json_decode(file_get_contents("globals.json"), true); |
|
| 57 | 57 | |
| 58 | - if (isset($globalLoc["globals"])){ |
|
| 59 | - $file = $globalLoc["globals".".json"; |
|
| 58 | + if (isset($globalLoc["globals"])){ |
|
| 59 | + $file = $globalLoc["globals".".json"; |
|
| 60 | 60 | |
| 61 | - return json_decode(file_get_contents($file), true); |
|
| 62 | - } |
|
| 63 | - } |
|
| 61 | + return json_decode(file_get_contents($file), true); |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - throw new Exception\UndefinedValueException("No configuration data set.", 0); |
|
| 65 | + throw new Exception\UndefinedValueException("No configuration data set.", 0); |
|
| 66 | 66 | |
| 67 | - } |
|
| 67 | + } |
|
| 68 | 68 | } |
@@ -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]> |
@@ -52,10 +52,10 @@ discard block |
||
| 52 | 52 | const UNDEFINED = 0; |
| 53 | 53 | |
| 54 | 54 | public static function getGlobals($config = "configs") { |
| 55 | - if (is_file("globals.json")){ |
|
| 55 | + if (is_file("globals.json")) { |
|
| 56 | 56 | $globalLoc = json_decode(file_get_contents("globals.json"), true); |
| 57 | 57 | |
| 58 | - if (isset($globalLoc["globals"])){ |
|
| 58 | + if (isset($globalLoc["globals"])) { |
|
| 59 | 59 | $file = $globalLoc["globals".".json"; |
| 60 | 60 | |
| 61 | 61 | return json_decode(file_get_contents($file), true); |