@@ -17,84 +17,84 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class SelectQueryBuilder extends QueryBuilder |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * @var \EmmetBlue\Core\Builder\QueryBuilder |
|
| 22 | - */ |
|
| 23 | - protected $queryBuilder; |
|
| 20 | + /** |
|
| 21 | + * @var \EmmetBlue\Core\Builder\QueryBuilder |
|
| 22 | + */ |
|
| 23 | + protected $queryBuilder; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @param string|null $tableName |
|
| 27 | - */ |
|
| 28 | - public function __construct() |
|
| 29 | - { |
|
| 30 | - $SelectKeyword = "SELECT"; |
|
| 31 | - $this->queryBuilder = $this->build($SelectKeyword); |
|
| 32 | - } |
|
| 25 | + /** |
|
| 26 | + * @param string|null $tableName |
|
| 27 | + */ |
|
| 28 | + public function __construct() |
|
| 29 | + { |
|
| 30 | + $SelectKeyword = "SELECT"; |
|
| 31 | + $this->queryBuilder = $this->build($SelectKeyword); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * {@inheritdoc} |
|
| 36 | - * |
|
| 37 | - * @param int $topValue |
|
| 38 | - * |
|
| 39 | - * @return \EmmetBlue\Core\Builder\SelectQueryBuilder |
|
| 40 | - */ |
|
| 41 | - public function top(int $topValue) |
|
| 42 | - { |
|
| 43 | - $this->queryBuilder = $this->queryBuilder->build("TOP ".$topValue); |
|
| 34 | + /** |
|
| 35 | + * {@inheritdoc} |
|
| 36 | + * |
|
| 37 | + * @param int $topValue |
|
| 38 | + * |
|
| 39 | + * @return \EmmetBlue\Core\Builder\SelectQueryBuilder |
|
| 40 | + */ |
|
| 41 | + public function top(int $topValue) |
|
| 42 | + { |
|
| 43 | + $this->queryBuilder = $this->queryBuilder->build("TOP ".$topValue); |
|
| 44 | 44 | |
| 45 | - return $this; |
|
| 46 | - } |
|
| 47 | - /** |
|
| 48 | - * This method handles situations that requires to |
|
| 49 | - * select all from the table. |
|
| 50 | - * @param * |
|
| 51 | - */ |
|
| 52 | - public function all() |
|
| 53 | - { |
|
| 54 | - $this->queryBuilder = $this->queryBuilder->build("*"); |
|
| 55 | - return $this; |
|
| 56 | - } |
|
| 57 | - /** |
|
| 58 | - * {@inheritdoc} |
|
| 59 | - * |
|
| 60 | - * @param string $columns |
|
| 61 | - * |
|
| 62 | - * @return \EmmetBlue\Core\Builder\SelectQueryBuilder |
|
| 63 | - */ |
|
| 64 | - public function columns(string ...$columns) |
|
| 65 | - { |
|
| 66 | - $this->queryBuilder = $this->queryBuilder->build(self::getImplodedString($columns)); |
|
| 45 | + return $this; |
|
| 46 | + } |
|
| 47 | + /** |
|
| 48 | + * This method handles situations that requires to |
|
| 49 | + * select all from the table. |
|
| 50 | + * @param * |
|
| 51 | + */ |
|
| 52 | + public function all() |
|
| 53 | + { |
|
| 54 | + $this->queryBuilder = $this->queryBuilder->build("*"); |
|
| 55 | + return $this; |
|
| 56 | + } |
|
| 57 | + /** |
|
| 58 | + * {@inheritdoc} |
|
| 59 | + * |
|
| 60 | + * @param string $columns |
|
| 61 | + * |
|
| 62 | + * @return \EmmetBlue\Core\Builder\SelectQueryBuilder |
|
| 63 | + */ |
|
| 64 | + public function columns(string ...$columns) |
|
| 65 | + { |
|
| 66 | + $this->queryBuilder = $this->queryBuilder->build(self::getImplodedString($columns)); |
|
| 67 | 67 | |
| 68 | - return $this; |
|
| 69 | - } |
|
| 68 | + return $this; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * {@inheritdoc} |
|
| 73 | - * |
|
| 74 | - * @param string $tableName |
|
| 75 | - * |
|
| 76 | - * @return \EmmetBlue\Core\Builder\SelectQueryBuilder |
|
| 77 | - */ |
|
| 78 | - public function from(string $tableName) |
|
| 79 | - { |
|
| 80 | - $this->queryBuilder = $this->queryBuilder->build("FROM ".$tableName); |
|
| 71 | + /** |
|
| 72 | + * {@inheritdoc} |
|
| 73 | + * |
|
| 74 | + * @param string $tableName |
|
| 75 | + * |
|
| 76 | + * @return \EmmetBlue\Core\Builder\SelectQueryBuilder |
|
| 77 | + */ |
|
| 78 | + public function from(string $tableName) |
|
| 79 | + { |
|
| 80 | + $this->queryBuilder = $this->queryBuilder->build("FROM ".$tableName); |
|
| 81 | 81 | |
| 82 | - return $this; |
|
| 83 | - } |
|
| 82 | + return $this; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * {@inheritdoc} |
|
| 87 | - * |
|
| 88 | - * @param string $tableName |
|
| 89 | - * @param string $condition |
|
| 90 | - * |
|
| 91 | - * @return \EmmetBlue\Core\Builder\SelectQueryBuilder |
|
| 92 | - */ |
|
| 93 | - public function innerJoin(string $tableName, string $condition) |
|
| 94 | - { |
|
| 95 | - $string = "INNER JOIN ".$tableName." ON ".$condition; |
|
| 96 | - $this->queryBuilder = $this->queryBuilder->build($string); |
|
| 85 | + /** |
|
| 86 | + * {@inheritdoc} |
|
| 87 | + * |
|
| 88 | + * @param string $tableName |
|
| 89 | + * @param string $condition |
|
| 90 | + * |
|
| 91 | + * @return \EmmetBlue\Core\Builder\SelectQueryBuilder |
|
| 92 | + */ |
|
| 93 | + public function innerJoin(string $tableName, string $condition) |
|
| 94 | + { |
|
| 95 | + $string = "INNER JOIN ".$tableName." ON ".$condition; |
|
| 96 | + $this->queryBuilder = $this->queryBuilder->build($string); |
|
| 97 | 97 | |
| 98 | - return $this; |
|
| 99 | - } |
|
| 98 | + return $this; |
|
| 99 | + } |
|
| 100 | 100 | } |
@@ -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 | } |
@@ -20,10 +20,10 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class UnexpectedErrorException extends Exception |
| 22 | 22 | { |
| 23 | - public function __construct(string $message, int $databaseUser) |
|
| 24 | - { |
|
| 25 | - parent::__construct($message, 0, $previous); |
|
| 23 | + public function __construct(string $message, int $databaseUser) |
|
| 24 | + { |
|
| 25 | + parent::__construct($message, 0, $previous); |
|
| 26 | 26 | |
| 27 | - $this->log($databaseUser, Constant::ERROR_401, Constant::ERROR_HIGH); |
|
| 28 | - } |
|
| 27 | + $this->log($databaseUser, Constant::ERROR_401, Constant::ERROR_HIGH); |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -20,10 +20,10 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class SQLException 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_401, Constant::ERROR_NORMAL); |
|
| 28 | - } |
|
| 27 | + $this->log($databaseUser, Constant::ERROR_401, Constant::ERROR_NORMAL); |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -20,10 +20,10 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class UndefinedValueException 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 | } |
@@ -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 | } |
@@ -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 | } |