@@ -18,33 +18,33 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | interface ConnectableInterface |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Setter for the DSN string {@see $dsn} |
|
| 23 | - * |
|
| 24 | - * @param array $dsnArray |
|
| 25 | - * @return void |
|
| 26 | - */ |
|
| 27 | - public function setDsn(array $dsnArray); |
|
| 21 | + /** |
|
| 22 | + * Setter for the DSN string {@see $dsn} |
|
| 23 | + * |
|
| 24 | + * @param array $dsnArray |
|
| 25 | + * @return void |
|
| 26 | + */ |
|
| 27 | + public function setDsn(array $dsnArray); |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Establishes connection |
|
| 31 | - * |
|
| 32 | - * @param string $username optional |
|
| 33 | - * @param string $password optional |
|
| 34 | - * @throws [@todo get exceptions] |
|
| 35 | - * @return void |
|
| 36 | - */ |
|
| 37 | - public function connect(string $username, string $password=""); |
|
| 29 | + /** |
|
| 30 | + * Establishes connection |
|
| 31 | + * |
|
| 32 | + * @param string $username optional |
|
| 33 | + * @param string $password optional |
|
| 34 | + * @throws [@todo get exceptions] |
|
| 35 | + * @return void |
|
| 36 | + */ |
|
| 37 | + public function connect(string $username, string $password=""); |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Returns an instance a pdo intance of the connection object |
|
| 41 | - * |
|
| 42 | - * @return \PDO |
|
| 43 | - */ |
|
| 44 | - public function getConnection() : \PDO; |
|
| 39 | + /** |
|
| 40 | + * Returns an instance a pdo intance of the connection object |
|
| 41 | + * |
|
| 42 | + * @return \PDO |
|
| 43 | + */ |
|
| 44 | + public function getConnection() : \PDO; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Closes connection |
|
| 48 | - */ |
|
| 49 | - public function disableConnection(); |
|
| 46 | + /** |
|
| 47 | + * Closes connection |
|
| 48 | + */ |
|
| 49 | + public function disableConnection(); |
|
| 50 | 50 | } |
@@ -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 |
@@ -17,31 +17,31 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class DeleteQueryBuilder 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 | - $DeleteKeyword = "Delete"; |
|
| 31 | - $this->queryBuilder = $this->build($DeleteKeyword); |
|
| 32 | - } |
|
| 25 | + /** |
|
| 26 | + * @param string|null $tableName |
|
| 27 | + */ |
|
| 28 | + public function __construct() |
|
| 29 | + { |
|
| 30 | + $DeleteKeyword = "Delete"; |
|
| 31 | + $this->queryBuilder = $this->build($DeleteKeyword); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * {@inheritdoc} |
|
| 36 | - * |
|
| 37 | - * @param string $tableName |
|
| 38 | - * |
|
| 39 | - * @return \EmmetBlue\Core\Builder\DeleteQueryBuilder |
|
| 40 | - */ |
|
| 41 | - public function from(string $tableName) |
|
| 42 | - { |
|
| 43 | - $this->queryBuilder = $this->queryBuilder->build("FROM ".$tableName); |
|
| 34 | + /** |
|
| 35 | + * {@inheritdoc} |
|
| 36 | + * |
|
| 37 | + * @param string $tableName |
|
| 38 | + * |
|
| 39 | + * @return \EmmetBlue\Core\Builder\DeleteQueryBuilder |
|
| 40 | + */ |
|
| 41 | + public function from(string $tableName) |
|
| 42 | + { |
|
| 43 | + $this->queryBuilder = $this->queryBuilder->build("FROM ".$tableName); |
|
| 44 | 44 | |
| 45 | - return $this; |
|
| 46 | - } |
|
| 45 | + return $this; |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -17,49 +17,49 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class UpdateQueryBuilder 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(string $tableName = null) |
|
| 29 | - { |
|
| 30 | - $updateKeyword = (is_null($tableName)) ? 'UPDATE' : 'UPDATE '.$tableName; |
|
| 31 | - $this->queryBuilder = $this->build($updateKeyword); |
|
| 32 | - } |
|
| 25 | + /** |
|
| 26 | + * @param string|null $tableName |
|
| 27 | + */ |
|
| 28 | + public function __construct(string $tableName = null) |
|
| 29 | + { |
|
| 30 | + $updateKeyword = (is_null($tableName)) ? 'UPDATE' : 'UPDATE '.$tableName; |
|
| 31 | + $this->queryBuilder = $this->build($updateKeyword); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * {@inheritdoc} |
|
| 36 | - * |
|
| 37 | - * @param string $tableName |
|
| 38 | - * |
|
| 39 | - * @return \EmmetBlue\Core\Builder\UpdateQueryBuilder |
|
| 40 | - */ |
|
| 41 | - public function table(string $tableName) |
|
| 42 | - { |
|
| 43 | - $this->queryBuilder = $this->queryBuilder->build($tableName); |
|
| 34 | + /** |
|
| 35 | + * {@inheritdoc} |
|
| 36 | + * |
|
| 37 | + * @param string $tableName |
|
| 38 | + * |
|
| 39 | + * @return \EmmetBlue\Core\Builder\UpdateQueryBuilder |
|
| 40 | + */ |
|
| 41 | + public function table(string $tableName) |
|
| 42 | + { |
|
| 43 | + $this->queryBuilder = $this->queryBuilder->build($tableName); |
|
| 44 | 44 | |
| 45 | - return $this; |
|
| 46 | - } |
|
| 45 | + return $this; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * {@inheritdoc} |
|
| 50 | - * |
|
| 51 | - * @param string[] $inputValues |
|
| 52 | - * |
|
| 53 | - * @return \EmmetBlue\Core\Builder\UpdateQueryBuilder |
|
| 54 | - */ |
|
| 55 | - public function set(array $inputValues) |
|
| 56 | - { |
|
| 57 | - $valuesKeyword = 'SET '; |
|
| 48 | + /** |
|
| 49 | + * {@inheritdoc} |
|
| 50 | + * |
|
| 51 | + * @param string[] $inputValues |
|
| 52 | + * |
|
| 53 | + * @return \EmmetBlue\Core\Builder\UpdateQueryBuilder |
|
| 54 | + */ |
|
| 55 | + public function set(array $inputValues) |
|
| 56 | + { |
|
| 57 | + $valuesKeyword = 'SET '; |
|
| 58 | 58 | |
| 59 | - $valuesKeyword .= self::getImplodedStringWithKeys($inputValues); |
|
| 59 | + $valuesKeyword .= self::getImplodedStringWithKeys($inputValues); |
|
| 60 | 60 | |
| 61 | - $this->queryBuilder = $this->queryBuilder->build($valuesKeyword); |
|
| 61 | + $this->queryBuilder = $this->queryBuilder->build($valuesKeyword); |
|
| 62 | 62 | |
| 63 | - return $this; |
|
| 64 | - } |
|
| 63 | + return $this; |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -17,68 +17,68 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class InsertQueryBuilder extends QueryBuilder |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * @var \EmmetBlue\Core\Abstraction\QueryBuilder |
|
| 22 | - */ |
|
| 23 | - protected $queryBuilder; |
|
| 20 | + /** |
|
| 21 | + * @var \EmmetBlue\Core\Abstraction\QueryBuilder |
|
| 22 | + */ |
|
| 23 | + protected $queryBuilder; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @param string|null $tableName |
|
| 27 | - */ |
|
| 28 | - public function __construct(string $tableName = null) |
|
| 29 | - { |
|
| 30 | - $insertKeyword = (is_null($tableName)) ? 'INSERT' : 'INSERT INTO '.$tableName; |
|
| 31 | - $this->queryBuilder = $this->build($insertKeyword); |
|
| 32 | - } |
|
| 25 | + /** |
|
| 26 | + * @param string|null $tableName |
|
| 27 | + */ |
|
| 28 | + public function __construct(string $tableName = null) |
|
| 29 | + { |
|
| 30 | + $insertKeyword = (is_null($tableName)) ? 'INSERT' : 'INSERT INTO '.$tableName; |
|
| 31 | + $this->queryBuilder = $this->build($insertKeyword); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * {@inheritdoc} |
|
| 36 | - * |
|
| 37 | - * @param string $tableName |
|
| 38 | - * @param string[] $tableColumns Optional, provide this to specify the |
|
| 39 | - * columns that should be acted on |
|
| 40 | - * |
|
| 41 | - * @return \EmmetBlue\Core\Abstraction\InsertQueryBuilder |
|
| 42 | - */ |
|
| 43 | - public function into(string $tableName, array $tableColumns = []) |
|
| 44 | - { |
|
| 45 | - $intoKeyword = 'INTO '.$tableName; |
|
| 34 | + /** |
|
| 35 | + * {@inheritdoc} |
|
| 36 | + * |
|
| 37 | + * @param string $tableName |
|
| 38 | + * @param string[] $tableColumns Optional, provide this to specify the |
|
| 39 | + * columns that should be acted on |
|
| 40 | + * |
|
| 41 | + * @return \EmmetBlue\Core\Abstraction\InsertQueryBuilder |
|
| 42 | + */ |
|
| 43 | + public function into(string $tableName, array $tableColumns = []) |
|
| 44 | + { |
|
| 45 | + $intoKeyword = 'INTO '.$tableName; |
|
| 46 | 46 | |
| 47 | - if (!empty($tableColumns)) { |
|
| 48 | - $intoKeyword .= $this->wrapString(self::getImplodedString($tableColumns), '(', ')'); |
|
| 49 | - } |
|
| 47 | + if (!empty($tableColumns)) { |
|
| 48 | + $intoKeyword .= $this->wrapString(self::getImplodedString($tableColumns), '(', ')'); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - $this->queryBuilder = $this->queryBuilder->build($intoKeyword); |
|
| 51 | + $this->queryBuilder = $this->queryBuilder->build($intoKeyword); |
|
| 52 | 52 | |
| 53 | - return $this; |
|
| 54 | - } |
|
| 53 | + return $this; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * {@inheritdoc} |
|
| 58 | - * |
|
| 59 | - * @param string[] $inputValues |
|
| 60 | - * |
|
| 61 | - * @return \EmmetBlue\Core\Abstraction\InsertQueryBuilder |
|
| 62 | - */ |
|
| 63 | - public function values(array $inputValues) |
|
| 64 | - { |
|
| 65 | - $valuesKeyword = 'VALUES '; |
|
| 66 | - $isMultidimentional = is_array($inputValues[0]); |
|
| 56 | + /** |
|
| 57 | + * {@inheritdoc} |
|
| 58 | + * |
|
| 59 | + * @param string[] $inputValues |
|
| 60 | + * |
|
| 61 | + * @return \EmmetBlue\Core\Abstraction\InsertQueryBuilder |
|
| 62 | + */ |
|
| 63 | + public function values(array $inputValues) |
|
| 64 | + { |
|
| 65 | + $valuesKeyword = 'VALUES '; |
|
| 66 | + $isMultidimentional = is_array($inputValues[0]); |
|
| 67 | 67 | |
| 68 | - if (!$isMultidimentional) { |
|
| 69 | - $valuesKeyword .= $this->wrapString(self::getImplodedString($inputValues), '(', ')'); |
|
| 70 | - } else { |
|
| 71 | - $tempValuesKeywords = []; |
|
| 72 | - foreach ($inputValues as $inputValue) { |
|
| 73 | - $tempValuesKeywords[] = $this->wrapString(self::getImplodedString($inputValue), '(', ')'); |
|
| 74 | - } |
|
| 68 | + if (!$isMultidimentional) { |
|
| 69 | + $valuesKeyword .= $this->wrapString(self::getImplodedString($inputValues), '(', ')'); |
|
| 70 | + } else { |
|
| 71 | + $tempValuesKeywords = []; |
|
| 72 | + foreach ($inputValues as $inputValue) { |
|
| 73 | + $tempValuesKeywords[] = $this->wrapString(self::getImplodedString($inputValue), '(', ')'); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - $valuesKeyword .= self::getImplodedString($tempValuesKeywords); |
|
| 77 | - unset($tempValuesKeywords); |
|
| 78 | - } |
|
| 76 | + $valuesKeyword .= self::getImplodedString($tempValuesKeywords); |
|
| 77 | + unset($tempValuesKeywords); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - $this->queryBuilder = $this->queryBuilder->build($valuesKeyword); |
|
| 80 | + $this->queryBuilder = $this->queryBuilder->build($valuesKeyword); |
|
| 81 | 81 | |
| 82 | - return $this; |
|
| 83 | - } |
|
| 82 | + return $this; |
|
| 83 | + } |
|
| 84 | 84 | } |
@@ -13,36 +13,36 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class BuilderFactory |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 19 | - protected $builder; |
|
| 16 | + /** |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | + protected $builder; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @param string $builder |
|
| 23 | - * @param string $builderType |
|
| 24 | - * @throws \Exception |
|
| 25 | - */ |
|
| 26 | - public function __construct(string $builder, string $builderType) |
|
| 27 | - { |
|
| 28 | - $builder = __NAMESPACE__."\\$builder\\$builderType$builder"; |
|
| 29 | - $builder = new $builder; |
|
| 21 | + /** |
|
| 22 | + * @param string $builder |
|
| 23 | + * @param string $builderType |
|
| 24 | + * @throws \Exception |
|
| 25 | + */ |
|
| 26 | + public function __construct(string $builder, string $builderType) |
|
| 27 | + { |
|
| 28 | + $builder = __NAMESPACE__."\\$builder\\$builderType$builder"; |
|
| 29 | + $builder = new $builder; |
|
| 30 | 30 | |
| 31 | - if (!($builder instanceof BuildableInterface)) |
|
| 32 | - { |
|
| 33 | - throw new \Exception(); |
|
| 34 | - } |
|
| 31 | + if (!($builder instanceof BuildableInterface)) |
|
| 32 | + { |
|
| 33 | + throw new \Exception(); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - $this->builder = $builder; |
|
| 37 | - } |
|
| 36 | + $this->builder = $builder; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Returns a new instance of the requested builder object |
|
| 41 | - * |
|
| 42 | - * @return EmmetBlue\Core\Database\Builder\BuildableInterface |
|
| 43 | - */ |
|
| 44 | - public function getBuilder() : BuildableInterface |
|
| 45 | - { |
|
| 46 | - return $this->builder; |
|
| 47 | - } |
|
| 39 | + /** |
|
| 40 | + * Returns a new instance of the requested builder object |
|
| 41 | + * |
|
| 42 | + * @return EmmetBlue\Core\Database\Builder\BuildableInterface |
|
| 43 | + */ |
|
| 44 | + public function getBuilder() : BuildableInterface |
|
| 45 | + { |
|
| 46 | + return $this->builder; |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |