@@ -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 | } |
@@ -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,43 +21,43 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class DatabaseConnectionFactory |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * @var \PDO $connectionObject |
|
| 26 | - */ |
|
| 27 | - private static $connectionObject; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Gets the config values defined in the database-config.json file |
|
| 31 | - * and uses the values to create a new connection object. |
|
| 32 | - */ |
|
| 33 | - public static function bootstrap() |
|
| 34 | - { |
|
| 35 | - $databaseConfigJson = file_get_contents(Constant::getGlobals()["config-dir"]["database-config"]); |
|
| 36 | - |
|
| 37 | - $databaseConfig = json_decode($databaseConfigJson); |
|
| 38 | - |
|
| 39 | - $adapter = $databaseConfig->adapter; |
|
| 40 | - $server = $databaseConfig->server; |
|
| 41 | - $database = $databaseConfig->database; |
|
| 42 | - $username = $databaseConfig->username; |
|
| 43 | - $password = $databaseConfig->password; |
|
| 44 | - |
|
| 45 | - self::$connectionObject = new Connection($adapter, [$server, $database], $username, $password); |
|
| 46 | - |
|
| 47 | - if ($databaseConfig->showError) |
|
| 48 | - { |
|
| 49 | - self::$connectionObject->getConnection()->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Returns a new connection object |
|
| 55 | - * |
|
| 56 | - * @return \PDO |
|
| 57 | - */ |
|
| 58 | - public static function getConnection() : \PDO |
|
| 59 | - { |
|
| 60 | - self::bootstrap(); |
|
| 61 | - return self::$connectionObject->getConnection(); |
|
| 62 | - } |
|
| 24 | + /** |
|
| 25 | + * @var \PDO $connectionObject |
|
| 26 | + */ |
|
| 27 | + private static $connectionObject; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Gets the config values defined in the database-config.json file |
|
| 31 | + * and uses the values to create a new connection object. |
|
| 32 | + */ |
|
| 33 | + public static function bootstrap() |
|
| 34 | + { |
|
| 35 | + $databaseConfigJson = file_get_contents(Constant::getGlobals()["config-dir"]["database-config"]); |
|
| 36 | + |
|
| 37 | + $databaseConfig = json_decode($databaseConfigJson); |
|
| 38 | + |
|
| 39 | + $adapter = $databaseConfig->adapter; |
|
| 40 | + $server = $databaseConfig->server; |
|
| 41 | + $database = $databaseConfig->database; |
|
| 42 | + $username = $databaseConfig->username; |
|
| 43 | + $password = $databaseConfig->password; |
|
| 44 | + |
|
| 45 | + self::$connectionObject = new Connection($adapter, [$server, $database], $username, $password); |
|
| 46 | + |
|
| 47 | + if ($databaseConfig->showError) |
|
| 48 | + { |
|
| 49 | + self::$connectionObject->getConnection()->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Returns a new connection object |
|
| 55 | + * |
|
| 56 | + * @return \PDO |
|
| 57 | + */ |
|
| 58 | + public static function getConnection() : \PDO |
|
| 59 | + { |
|
| 60 | + self::bootstrap(); |
|
| 61 | + return self::$connectionObject->getConnection(); |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -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 | |
@@ -67,8 +67,7 @@ |
||
| 67 | 67 | try |
| 68 | 68 | { |
| 69 | 69 | $this->connectionObject = new \PDO("sqlite:$dbLocation"); |
| 70 | - } |
|
| 71 | - catch (\PDOException $e) |
|
| 70 | + } catch (\PDOException $e) |
|
| 72 | 71 | { |
| 73 | 72 | throw new SQLException("Unable to connect to database", 400, $e); |
| 74 | 73 | } |
@@ -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,18 +21,18 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class UserIDValidator implements ValidatorInterface |
| 23 | 23 | { |
| 24 | - public function isValidUserId(string $userId) |
|
| 25 | - { |
|
| 26 | - $selectQuery = (new Builder('QueryBuilder', 'Select'))->getBuilder(); |
|
| 24 | + public function isValidUserId(string $userId) |
|
| 25 | + { |
|
| 26 | + $selectQuery = (new Builder('QueryBuilder', 'Select'))->getBuilder(); |
|
| 27 | 27 | |
| 28 | - $selectQuery |
|
| 29 | - ->top(1) |
|
| 30 | - ->columns('StaffID') |
|
| 31 | - ->from('[Staffs].[Staff]') |
|
| 32 | - ->where( |
|
| 33 | - 'StaffID', |
|
| 34 | - '='. |
|
| 35 | - $userId |
|
| 36 | - ); |
|
| 37 | - } |
|
| 28 | + $selectQuery |
|
| 29 | + ->top(1) |
|
| 30 | + ->columns('StaffID') |
|
| 31 | + ->from('[Staffs].[Staff]') |
|
| 32 | + ->where( |
|
| 33 | + 'StaffID', |
|
| 34 | + '='. |
|
| 35 | + $userId |
|
| 36 | + ); |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -1,4 +1,4 @@ |
||
| 1 | -<?php declare (strict_types=1); |
|
| 1 | +<?php declare (strict_types = 1); |
|
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | 4 | * @license MIT |
@@ -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]> |