diff options
| author | Kevin J Hoerr <kjhoerr@protonmail.com> | 2017-07-05 20:55:44 -0400 |
|---|---|---|
| committer | Kevin J Hoerr <kjhoerr@protonmail.com> | 2017-07-05 20:55:44 -0400 |
| commit | e35b049df539e60b28909daf8ce05b4451ba54f6 (patch) | |
| tree | 8bdaa222e956893df52b1e8e9708b8e4e030fdae | |
| parent | 09e9319a5516d264e5793b4bff88c77540250ae0 (diff) | |
| download | august-offensive-e35b049df539e60b28909daf8ce05b4451ba54f6.tar.gz august-offensive-e35b049df539e60b28909daf8ce05b4451ba54f6.tar.bz2 august-offensive-e35b049df539e60b28909daf8ce05b4451ba54f6.zip | |
Changed cred to disappearable object, fix compile errors
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | index.php | 11 | ||||
| -rw-r--r-- | private/model/Connection.php | 15 | ||||
| -rw-r--r-- | private/model/creds.php | 106 | ||||
| -rw-r--r-- | private/view/Result.php | 3 |
5 files changed, 23 insertions, 113 deletions
@@ -1 +1,2 @@ private/model/creds.php +.idea @@ -16,10 +16,10 @@ use AugustOffensive\model; */ class Api { - /** @var \Connection $connection the model database interface */ + /** @var model\Connection $connection the model database interface */ private $connection; - /** @var \Result $view the view interface that outputs result of the query */ + /** @var view\Result $view the view interface that outputs result of the query */ private $view; /** @@ -29,14 +29,15 @@ class Api */ public function __construct () { - $connection = new model\Connection(); - $view = new view\Result($connection); + $this->connection = new model\Connection(); + $this->view = new view\Result($this->connection); // Provide hook for connecting through controller to justify query - $result = $view->collect(); + $result = $this->view->collect(); // Leak the data echo $result; + return $this; } } diff --git a/private/model/Connection.php b/private/model/Connection.php index 26c9e1b..32cbf33 100644 --- a/private/model/Connection.php +++ b/private/model/Connection.php @@ -9,7 +9,7 @@ namespace AugustOffensive\model; */ class Connection { - /** @var PDO $_conn \PDO connection to database. */ + /** @var \PDO $_conn PDO connection to database. */ private $_conn; /** * Initiates connection to PostGreSQL database. @@ -19,15 +19,15 @@ class Connection public function __construct () { // Establish connection to db - include './creds.php'; + include 'creds.php'; try { $_conn = new \PDO( - "pgsql: host=" . $cred->getHost() . - (($cred->getPort() !== '') ? ";port=" . $cred->getPort() : '') . - ";dbname=" . $cred->getDBName(), - $cred->getLogin(), - $cred->getPassword() + "pgsql: host=" . $cred->host . + (($cred->port !== '') ? ";port=" . $cred->port : '') . + ";dbname=" . $cred->dbName, + $cred->login, + $cred->password ); // we destroy $cred as quickly as possible $cred = null; @@ -36,5 +36,6 @@ class Connection $cred = null; die(json_encode(array("Result-Type" => "Error", "Content" => array($e)))); } + return $this; } } diff --git a/private/model/creds.php b/private/model/creds.php index 5f36632..8bca994 100644 --- a/private/model/creds.php +++ b/private/model/creds.php @@ -2,104 +2,10 @@ declare(strict_types=1); -namespace AugustOffensive\model; - -/** - * Holds the credentials for connecting to the database - */ -class Cred -{ - /** @var string $host The destination host that holds the database. */ - private $host; - /** @var string $port The destination port for the database on the host. */ - private $port; - /** @var string $dbname The name of the database of which to connect. */ - private $dbname; - /** @var string $login The username for accessing the database. - * - * It is recommended to change the login to a more restrictive account once - * the tables have been created (e.g. an account that can only insert, - * select, and update on that specific database). - */ - private $login; - /** @var string $password The password to the account for access. */ - private $password; - - /** - * Sets the values of the credentials. - * - * @return Cred - */ - public function __construct () - { - $host = 'localhost'; - $port = '5432'; - $dbname = 'ao'; - $login = 'r_access'; - $password = 'secret'; - } - - /** - * Destructor ensures clean wipe of credentials from existing. - * - * @return void - */ - public function __destruct () - { - $host = ''; - $port = ''; - $dbname = ''; - $login = ''; - $password = ''; - } - - /** - * Returns the value of the host of the database. - * - * @return string $host - */ - public function getHost () - { - return $host; - } - /** - * Returns the value of the port of the host of which to connect. - * - * @return string $port - */ - public function getPort () - { - return $port; - } - /** - * Returns the value of the name of the database of which to connect. - * - * @return string $dbname - */ - public function getDBName () - { - return $dbname; - } - /** - * Returns the value of the username of the account of the database. - * - * @return string $login - */ - public function getLogin () - { - return $login; - } - /** - * Returns the value of the password of the account of the database. - * - * @return string password - */ - public function getPassword () - { - return $password; - } -} - -// destroy as quickly as possible -$cred = new Cred(); +$cred = new \stdClass(); +$cred->host = "localhost"; +$cred->port = "5432"; +$cred->dbName = ""; +$cred->login = ""; +$cred->password = ""; diff --git a/private/view/Result.php b/private/view/Result.php index a86a5bd..2d12c28 100644 --- a/private/view/Result.php +++ b/private/view/Result.php @@ -15,7 +15,7 @@ class Result /** * Prepares the output and environment for the front end of the service. * - * @param \Connection $connection "needs to know" model exists + * @param model\Connection $connection "needs to know" model exists * * @return Result */ @@ -23,6 +23,7 @@ class Result { header("Content-Type: application/json"); // + return $this; } /** |
