@@ -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 = \Elasticsearch\ClientBuilder::create()->setHosts($config)->build(); |
|
| 29 | + self::$clientObject = \Elasticsearch\ClientBuilder::create()->setHosts($config)->build(); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public static function getClient() |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 | { |
| 26 | 26 | $configJson = file_get_contents("bin/configs/http-headers-config.json"); |
| 27 | 27 | |
| 28 | - self::$headers = json_decode($configJson, true); |
|
| 28 | + self::$headers = json_decode($configJson, true); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | public static function get($url, $extraHeaders = []) |
@@ -6,27 +6,27 @@ |
||
| 6 | 6 | |
| 7 | 7 | class CustomFileNameGenerator implements \FileUpload\FileNameGenerator\FileNameGenerator |
| 8 | 8 | { |
| 9 | - protected $generator; |
|
| 9 | + protected $generator; |
|
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * @param string|callable|Closure $nameGenerator |
|
| 13 | - */ |
|
| 14 | - public function __construct($nameGenerator) |
|
| 15 | - { |
|
| 16 | - $this->generator = $nameGenerator; |
|
| 17 | - } |
|
| 11 | + /** |
|
| 12 | + * @param string|callable|Closure $nameGenerator |
|
| 13 | + */ |
|
| 14 | + public function __construct($nameGenerator) |
|
| 15 | + { |
|
| 16 | + $this->generator = $nameGenerator; |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - public function getFileName($source_name, $type, $tmp_name, $index, $content_range, FileUpload $upload) |
|
| 20 | - { |
|
| 21 | - $sourceNameArray = explode(".", $source_name); |
|
| 22 | - $ext = $sourceNameArray[count($sourceNameArray) - 1]; |
|
| 23 | - if (is_string($this->generator) && !is_callable($this->generator)) { |
|
| 24 | - return $this->generator.".".$ext; |
|
| 25 | - } |
|
| 19 | + public function getFileName($source_name, $type, $tmp_name, $index, $content_range, FileUpload $upload) |
|
| 20 | + { |
|
| 21 | + $sourceNameArray = explode(".", $source_name); |
|
| 22 | + $ext = $sourceNameArray[count($sourceNameArray) - 1]; |
|
| 23 | + if (is_string($this->generator) && !is_callable($this->generator)) { |
|
| 24 | + return $this->generator.".".$ext; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - return call_user_func_array( |
|
| 28 | - $this->generator, |
|
| 29 | - func_get_args() |
|
| 30 | - ); |
|
| 31 | - } |
|
| 27 | + return call_user_func_array( |
|
| 28 | + $this->generator, |
|
| 29 | + func_get_args() |
|
| 30 | + ); |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -20,169 +20,169 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class QueryBuilder implements BuildableInterface |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * @var string Global Sql Statement |
|
| 25 | - */ |
|
| 26 | - private $sqlStatement; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var string SPACE |
|
| 30 | - */ |
|
| 31 | - const SPACE = ' '; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @param string | null $sqlStatement SQL Statement to be processed by the build method |
|
| 35 | - * |
|
| 36 | - * @throws {@todo Write exception class} |
|
| 37 | - */ |
|
| 38 | - public function __construct(string $sqlStatement = null) |
|
| 39 | - { |
|
| 40 | - self::setSqlStatement($sqlStatement); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Returns the string value of the global sqlStatement variable. |
|
| 45 | - * |
|
| 46 | - * @return string |
|
| 47 | - */ |
|
| 48 | - private function getSqlStatement() |
|
| 49 | - { |
|
| 50 | - return $this->sqlStatement; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Sets/Modifies the value of the global sqlStatement variable. |
|
| 55 | - * |
|
| 56 | - * @param string $sqlStatement to set/replace global equivalent to. |
|
| 57 | - * |
|
| 58 | - * @return null |
|
| 59 | - */ |
|
| 60 | - private function setSqlStatement(string $sqlStatement = null) |
|
| 61 | - { |
|
| 62 | - $this->sqlStatement = $sqlStatement; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Builds a QueryBuilder object. |
|
| 67 | - * {@see QueryBuildableInterface}. |
|
| 68 | - * |
|
| 69 | - * @param string | null $sqlStringToAppend |
|
| 70 | - * |
|
| 71 | - * @throws {@todo Create exceptions} |
|
| 72 | - * |
|
| 73 | - * @return QueryBuilder new instance of the QueryBuilder object. |
|
| 74 | - */ |
|
| 75 | - public function build(string $sqlStringToAppend) : BuildableInterface |
|
| 76 | - { |
|
| 77 | - $separator = (empty(self::getSqlStatement())) ? '' : self::SPACE; |
|
| 78 | - $newSqlString = self::getSqlStatement().$separator.$sqlStringToAppend; |
|
| 79 | - self::setSqlStatement($newSqlString); |
|
| 80 | - |
|
| 81 | - return $this; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * returns a `built sql` when the QueryBuilder object is casted to a string. |
|
| 86 | - * |
|
| 87 | - * @return string |
|
| 88 | - */ |
|
| 89 | - public function __toString() |
|
| 90 | - { |
|
| 91 | - return self::getSqlStatement(); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Implodes an array into a string. |
|
| 96 | - * |
|
| 97 | - * @param array $arrayToImplode |
|
| 98 | - * @param string $delimiter Optional. |
|
| 99 | - * |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - protected function getImplodedString(array $arrayToImplode, string $delimiter = ',') : string |
|
| 103 | - { |
|
| 104 | - return implode($delimiter, $arrayToImplode); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Implodes an array into a string while keeping track of the keys. |
|
| 109 | - * |
|
| 110 | - * @param array $arrayToImplode |
|
| 111 | - * @param string $delimiter Optional. |
|
| 112 | - * |
|
| 113 | - * @return string |
|
| 114 | - */ |
|
| 115 | - protected function getImplodedStringWithKeys(array $arrayToImplode, string $keyDelimiter='=', string $delimiter = ',') : string |
|
| 116 | - { |
|
| 117 | - $implodedStrings = []; |
|
| 118 | - |
|
| 119 | - foreach ($arrayToImplode as $key=>$value) |
|
| 120 | - { |
|
| 121 | - $implodedStrings[] = $key.$keyDelimiter.$value; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return implode($delimiter, $implodedStrings); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Wraps a string with specified characters. |
|
| 129 | - * |
|
| 130 | - * @param string $strBefore |
|
| 131 | - * @param string|null $strAfter |
|
| 132 | - * @param string $strToWrap |
|
| 133 | - * |
|
| 134 | - * @return string |
|
| 135 | - */ |
|
| 136 | - public static function wrapString(string $strToWrap, string $strBefore, string $strAfter = null) : string |
|
| 137 | - { |
|
| 138 | - return $strBefore.$strToWrap.(is_null($strAfter) ? $strBefore : $strAfter); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * {@inheritdoc} |
|
| 143 | - * |
|
| 144 | - * @param string $condition |
|
| 145 | - * |
|
| 146 | - * @return \EmmetBlue\Core\Builder\BuildableInterface |
|
| 147 | - */ |
|
| 148 | - public function where(string $condition) |
|
| 149 | - { |
|
| 150 | - $whereString = "WHERE $condition"; |
|
| 151 | - |
|
| 152 | - $this->queryBuilder = $this->queryBuilder->build($whereString); |
|
| 153 | - |
|
| 154 | - return $this; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * {@inheritdoc} |
|
| 159 | - * |
|
| 160 | - * @param string $condition |
|
| 161 | - * |
|
| 162 | - * @return \EmmetBlue\Core\Builder\BuildableInterface |
|
| 163 | - */ |
|
| 164 | - public function andWhere(string $condition) |
|
| 165 | - { |
|
| 166 | - $whereString = "AND $condition"; |
|
| 167 | - |
|
| 168 | - $this->queryBuilder = $this->queryBuilder->build($whereString); |
|
| 169 | - |
|
| 170 | - return $this; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * {@inheritdoc} |
|
| 175 | - * |
|
| 176 | - * @param string $condition |
|
| 177 | - * |
|
| 178 | - * @return \EmmetBlue\Core\Builder\BuildableInterface |
|
| 179 | - */ |
|
| 180 | - public function orWhere(string $condition) |
|
| 181 | - { |
|
| 182 | - $whereString = "OR $condition"; |
|
| 183 | - |
|
| 184 | - $this->queryBuilder = $this->queryBuilder->build($whereString); |
|
| 185 | - |
|
| 186 | - return $this; |
|
| 187 | - } |
|
| 23 | + /** |
|
| 24 | + * @var string Global Sql Statement |
|
| 25 | + */ |
|
| 26 | + private $sqlStatement; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @var string SPACE |
|
| 30 | + */ |
|
| 31 | + const SPACE = ' '; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @param string | null $sqlStatement SQL Statement to be processed by the build method |
|
| 35 | + * |
|
| 36 | + * @throws {@todo Write exception class} |
|
| 37 | + */ |
|
| 38 | + public function __construct(string $sqlStatement = null) |
|
| 39 | + { |
|
| 40 | + self::setSqlStatement($sqlStatement); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Returns the string value of the global sqlStatement variable. |
|
| 45 | + * |
|
| 46 | + * @return string |
|
| 47 | + */ |
|
| 48 | + private function getSqlStatement() |
|
| 49 | + { |
|
| 50 | + return $this->sqlStatement; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Sets/Modifies the value of the global sqlStatement variable. |
|
| 55 | + * |
|
| 56 | + * @param string $sqlStatement to set/replace global equivalent to. |
|
| 57 | + * |
|
| 58 | + * @return null |
|
| 59 | + */ |
|
| 60 | + private function setSqlStatement(string $sqlStatement = null) |
|
| 61 | + { |
|
| 62 | + $this->sqlStatement = $sqlStatement; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Builds a QueryBuilder object. |
|
| 67 | + * {@see QueryBuildableInterface}. |
|
| 68 | + * |
|
| 69 | + * @param string | null $sqlStringToAppend |
|
| 70 | + * |
|
| 71 | + * @throws {@todo Create exceptions} |
|
| 72 | + * |
|
| 73 | + * @return QueryBuilder new instance of the QueryBuilder object. |
|
| 74 | + */ |
|
| 75 | + public function build(string $sqlStringToAppend) : BuildableInterface |
|
| 76 | + { |
|
| 77 | + $separator = (empty(self::getSqlStatement())) ? '' : self::SPACE; |
|
| 78 | + $newSqlString = self::getSqlStatement().$separator.$sqlStringToAppend; |
|
| 79 | + self::setSqlStatement($newSqlString); |
|
| 80 | + |
|
| 81 | + return $this; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * returns a `built sql` when the QueryBuilder object is casted to a string. |
|
| 86 | + * |
|
| 87 | + * @return string |
|
| 88 | + */ |
|
| 89 | + public function __toString() |
|
| 90 | + { |
|
| 91 | + return self::getSqlStatement(); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Implodes an array into a string. |
|
| 96 | + * |
|
| 97 | + * @param array $arrayToImplode |
|
| 98 | + * @param string $delimiter Optional. |
|
| 99 | + * |
|
| 100 | + * @return string |
|
| 101 | + */ |
|
| 102 | + protected function getImplodedString(array $arrayToImplode, string $delimiter = ',') : string |
|
| 103 | + { |
|
| 104 | + return implode($delimiter, $arrayToImplode); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Implodes an array into a string while keeping track of the keys. |
|
| 109 | + * |
|
| 110 | + * @param array $arrayToImplode |
|
| 111 | + * @param string $delimiter Optional. |
|
| 112 | + * |
|
| 113 | + * @return string |
|
| 114 | + */ |
|
| 115 | + protected function getImplodedStringWithKeys(array $arrayToImplode, string $keyDelimiter='=', string $delimiter = ',') : string |
|
| 116 | + { |
|
| 117 | + $implodedStrings = []; |
|
| 118 | + |
|
| 119 | + foreach ($arrayToImplode as $key=>$value) |
|
| 120 | + { |
|
| 121 | + $implodedStrings[] = $key.$keyDelimiter.$value; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return implode($delimiter, $implodedStrings); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Wraps a string with specified characters. |
|
| 129 | + * |
|
| 130 | + * @param string $strBefore |
|
| 131 | + * @param string|null $strAfter |
|
| 132 | + * @param string $strToWrap |
|
| 133 | + * |
|
| 134 | + * @return string |
|
| 135 | + */ |
|
| 136 | + public static function wrapString(string $strToWrap, string $strBefore, string $strAfter = null) : string |
|
| 137 | + { |
|
| 138 | + return $strBefore.$strToWrap.(is_null($strAfter) ? $strBefore : $strAfter); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * {@inheritdoc} |
|
| 143 | + * |
|
| 144 | + * @param string $condition |
|
| 145 | + * |
|
| 146 | + * @return \EmmetBlue\Core\Builder\BuildableInterface |
|
| 147 | + */ |
|
| 148 | + public function where(string $condition) |
|
| 149 | + { |
|
| 150 | + $whereString = "WHERE $condition"; |
|
| 151 | + |
|
| 152 | + $this->queryBuilder = $this->queryBuilder->build($whereString); |
|
| 153 | + |
|
| 154 | + return $this; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * {@inheritdoc} |
|
| 159 | + * |
|
| 160 | + * @param string $condition |
|
| 161 | + * |
|
| 162 | + * @return \EmmetBlue\Core\Builder\BuildableInterface |
|
| 163 | + */ |
|
| 164 | + public function andWhere(string $condition) |
|
| 165 | + { |
|
| 166 | + $whereString = "AND $condition"; |
|
| 167 | + |
|
| 168 | + $this->queryBuilder = $this->queryBuilder->build($whereString); |
|
| 169 | + |
|
| 170 | + return $this; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * {@inheritdoc} |
|
| 175 | + * |
|
| 176 | + * @param string $condition |
|
| 177 | + * |
|
| 178 | + * @return \EmmetBlue\Core\Builder\BuildableInterface |
|
| 179 | + */ |
|
| 180 | + public function orWhere(string $condition) |
|
| 181 | + { |
|
| 182 | + $whereString = "OR $condition"; |
|
| 183 | + |
|
| 184 | + $this->queryBuilder = $this->queryBuilder->build($whereString); |
|
| 185 | + |
|
| 186 | + return $this; |
|
| 187 | + } |
|
| 188 | 188 | } |
@@ -27,46 +27,46 @@ |
||
| 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 | - // die($query); |
|
| 48 | - try |
|
| 49 | - { |
|
| 50 | - $parts = explode(".", $table); |
|
| 51 | - $schemaName = $parts[0]; |
|
| 52 | - $tableName = $parts[1]; |
|
| 46 | + $query = (string)$insertBuilder." VALUES ".$values; |
|
| 47 | + // die($query); |
|
| 48 | + try |
|
| 49 | + { |
|
| 50 | + $parts = explode(".", $table); |
|
| 51 | + $schemaName = $parts[0]; |
|
| 52 | + $tableName = $parts[1]; |
|
| 53 | 53 | |
| 54 | - $connection = DBConnectionFactory::getConnection(); |
|
| 54 | + $connection = DBConnectionFactory::getConnection(); |
|
| 55 | 55 | |
| 56 | - $result = $connection->prepare((string)$query)->execute(); |
|
| 56 | + $result = $connection->prepare((string)$query)->execute(); |
|
| 57 | 57 | |
| 58 | - DatabaseLog::log(Session::get('USER_ID'), Constant::EVENT_INSERT, $schemaName, $tableName, $query); |
|
| 58 | + DatabaseLog::log(Session::get('USER_ID'), Constant::EVENT_INSERT, $schemaName, $tableName, $query); |
|
| 59 | 59 | |
| 60 | - $lastInsertId = ($connection->query("SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS int) as id")->fetchColumn()); |
|
| 60 | + $lastInsertId = ($connection->query("SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS int) as id")->fetchColumn()); |
|
| 61 | 61 | |
| 62 | - return [$result, "lastInsertId"=>$lastInsertId]; |
|
| 63 | - } |
|
| 64 | - catch (\PDOException $e) |
|
| 65 | - { |
|
| 66 | - throw new SQLException(sprintf( |
|
| 67 | - "%s", |
|
| 68 | - $e->getMessage() |
|
| 69 | - ), Constant::UNDEFINED); |
|
| 70 | - } |
|
| 71 | - } |
|
| 62 | + return [$result, "lastInsertId"=>$lastInsertId]; |
|
| 63 | + } |
|
| 64 | + catch (\PDOException $e) |
|
| 65 | + { |
|
| 66 | + throw new SQLException(sprintf( |
|
| 67 | + "%s", |
|
| 68 | + $e->getMessage() |
|
| 69 | + ), Constant::UNDEFINED); |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | 72 | } |
| 73 | 73 | \ No newline at end of file |
@@ -17,65 +17,65 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class DirtChecker |
| 19 | 19 | { |
| 20 | - public $dirtFilterConditions = [">", "<", "="]; |
|
| 20 | + public $dirtFilterConditions = [">", "<", "="]; |
|
| 21 | 21 | |
| 22 | - public $workingValue; |
|
| 23 | - public $conditionValue; |
|
| 24 | - public $workingConditions = []; |
|
| 22 | + public $workingValue; |
|
| 23 | + public $conditionValue; |
|
| 24 | + public $workingConditions = []; |
|
| 25 | 25 | |
| 26 | - public function __construct(string $value, string $conditionValue, array $conditions = []) |
|
| 27 | - { |
|
| 28 | - $this->workingValue = $value; |
|
| 29 | - $this->conditionValue = $conditionValue; |
|
| 26 | + public function __construct(string $value, string $conditionValue, array $conditions = []) |
|
| 27 | + { |
|
| 28 | + $this->workingValue = $value; |
|
| 29 | + $this->conditionValue = $conditionValue; |
|
| 30 | 30 | |
| 31 | - if (!empty($conditions)){ |
|
| 32 | - foreach ($conditions as $value) { |
|
| 33 | - if (!in_array($value, $this->dirtFilterConditions)){ |
|
| 34 | - throw new \Exception("Invalid Dirt Filter Condition Provided: ".$value); |
|
| 35 | - } |
|
| 36 | - } |
|
| 37 | - $this->workingConditions = $conditions; |
|
| 38 | - } |
|
| 39 | - else { |
|
| 40 | - $this->workingConditions = $this->dirtFilterConditions; |
|
| 41 | - } |
|
| 42 | - } |
|
| 31 | + if (!empty($conditions)){ |
|
| 32 | + foreach ($conditions as $value) { |
|
| 33 | + if (!in_array($value, $this->dirtFilterConditions)){ |
|
| 34 | + throw new \Exception("Invalid Dirt Filter Condition Provided: ".$value); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | + $this->workingConditions = $conditions; |
|
| 38 | + } |
|
| 39 | + else { |
|
| 40 | + $this->workingConditions = $this->dirtFilterConditions; |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - public function isDirty() : bool |
|
| 45 | - { |
|
| 46 | - $explodedString = explode(" ", $this->workingValue); |
|
| 47 | - foreach ($explodedString as $string){ |
|
| 48 | - foreach ($this->workingConditions as $condition){ |
|
| 49 | - $switchValue = false; |
|
| 50 | - switch ($condition) { |
|
| 51 | - case '=': |
|
| 52 | - $switchValue = strpos($string, $this->conditionValue) !== false; |
|
| 53 | - break; |
|
| 54 | - case '>': |
|
| 55 | - $string = self::turnToNumber($string); |
|
| 56 | - $_condition = self::turnToNumber($this->conditionValue); |
|
| 44 | + public function isDirty() : bool |
|
| 45 | + { |
|
| 46 | + $explodedString = explode(" ", $this->workingValue); |
|
| 47 | + foreach ($explodedString as $string){ |
|
| 48 | + foreach ($this->workingConditions as $condition){ |
|
| 49 | + $switchValue = false; |
|
| 50 | + switch ($condition) { |
|
| 51 | + case '=': |
|
| 52 | + $switchValue = strpos($string, $this->conditionValue) !== false; |
|
| 53 | + break; |
|
| 54 | + case '>': |
|
| 55 | + $string = self::turnToNumber($string); |
|
| 56 | + $_condition = self::turnToNumber($this->conditionValue); |
|
| 57 | 57 | |
| 58 | - $switchValue = $string > $_condition; |
|
| 59 | - break; |
|
| 60 | - case '<': |
|
| 61 | - $string = self::turnToNumber($string); |
|
| 62 | - $_condition = self::turnToNumber($this->conditionValue); |
|
| 58 | + $switchValue = $string > $_condition; |
|
| 59 | + break; |
|
| 60 | + case '<': |
|
| 61 | + $string = self::turnToNumber($string); |
|
| 62 | + $_condition = self::turnToNumber($this->conditionValue); |
|
| 63 | 63 | |
| 64 | - $switchValue = $string < $_condition; |
|
| 65 | - break; |
|
| 66 | - } |
|
| 64 | + $switchValue = $string < $_condition; |
|
| 65 | + break; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - if (!$switchValue) { |
|
| 69 | - return true; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - } |
|
| 68 | + if (!$switchValue) { |
|
| 69 | + return true; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - return false; |
|
| 75 | - } |
|
| 74 | + return false; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - private function turnToNumber(string $string) : float |
|
| 78 | - { |
|
| 79 | - return (float) filter_var($string, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION | FILTER_FLAG_ALLOW_THOUSAND); |
|
| 80 | - } |
|
| 77 | + private function turnToNumber(string $string) : float |
|
| 78 | + { |
|
| 79 | + return (float) filter_var($string, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION | FILTER_FLAG_ALLOW_THOUSAND); |
|
| 80 | + } |
|
| 81 | 81 | } |
@@ -20,10 +20,10 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class UnallowedOperationException extends Exception |
| 22 | 22 | { |
| 23 | - public function __construct(string $message, int $databaseUser) |
|
| 24 | - { |
|
| 25 | - parent::__construct($message, 0, null); |
|
| 23 | + public function __construct(string $message, int $databaseUser) |
|
| 24 | + { |
|
| 25 | + parent::__construct($message, 0, null); |
|
| 26 | 26 | |
| 27 | - $this->log($databaseUser, Constant::ERROR_404, Constant::ERROR_NORMAL); |
|
| 28 | - } |
|
| 27 | + $this->log($databaseUser, Constant::ERROR_404, Constant::ERROR_NORMAL); |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -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 | } |