[mod] Mysql connections moved to dependencies
This commit is contained in:
parent
09f11ebe49
commit
d7be1f1d9c
@ -5,31 +5,10 @@ class SessionApplication{
|
|||||||
private $pdo = '';
|
private $pdo = '';
|
||||||
private $cryptographyService;
|
private $cryptographyService;
|
||||||
|
|
||||||
function __construct($mysqlSettings, $cryptographyService){
|
function __construct($mysql, $cryptographyService){
|
||||||
// Services
|
// Services
|
||||||
$this->cryptographyService = $cryptographyService;
|
$this->cryptographyService = $cryptographyService;
|
||||||
|
$this->pdo = $mysql;
|
||||||
// The database parameters
|
|
||||||
$this->host = $mysqlSettings['host'];
|
|
||||||
$this->database = $mysqlSettings['database'];
|
|
||||||
$this->user = $mysqlSettings['user'];
|
|
||||||
$this->password = $mysqlSettings['password'];
|
|
||||||
$this->charset = $mysqlSettings['charset'];
|
|
||||||
$this->pdoConnectionOptions = $mysqlSettings['pdoConnectionOptions'];
|
|
||||||
|
|
||||||
// Generic error messages
|
|
||||||
$this->databaseConnectionErrorMessage = $mysqlSettings['databaseConnectionErrorMessage'];
|
|
||||||
$this->databaseSelectQueryErrorMessage = $mysqlSettings['databaseSelectQueryErrorMessage'];
|
|
||||||
$this->databaseInsertQueryErrorMessage = $mysqlSettings['databaseInsertQueryErrorMessage'];
|
|
||||||
|
|
||||||
// Initiate the connection
|
|
||||||
$dsn = "mysql:host=$this->host;dbname=$this->database;charset=$this->charset";
|
|
||||||
try {
|
|
||||||
$this->pdo = new PDO($dsn, $this->user, $this->password, $this->pdoConnectionOptions);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
error_log($e->getMessage());
|
|
||||||
exit($this->databaseConnectionErrorMessage);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function newSession($userName, $password){
|
function newSession($userName, $password){
|
||||||
@ -40,7 +19,7 @@ class SessionApplication{
|
|||||||
return "yea";
|
return "yea";
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
"nah";
|
return "nay";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,34 @@ $container['logger'] = function ($c) {
|
|||||||
return $logger;
|
return $logger;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Mysql connecrion
|
||||||
|
$container['mysql'] = function ($c) {
|
||||||
|
$mysqlSettings = $c->get('settings')['mysql'];
|
||||||
|
|
||||||
|
// The database parameters
|
||||||
|
$host = $mysqlSettings['host'];
|
||||||
|
$database = $mysqlSettings['database'];
|
||||||
|
$user = $mysqlSettings['user'];
|
||||||
|
$password = $mysqlSettings['password'];
|
||||||
|
$charset = $mysqlSettings['charset'];
|
||||||
|
$pdoConnectionOptions = $mysqlSettings['pdoConnectionOptions'];
|
||||||
|
|
||||||
|
// Generic error messages
|
||||||
|
$databaseConnectionErrorMessage = $mysqlSettings['databaseConnectionErrorMessage'];
|
||||||
|
$databaseSelectQueryErrorMessage = $mysqlSettings['databaseSelectQueryErrorMessage'];
|
||||||
|
$databaseInsertQueryErrorMessage = $mysqlSettings['databaseInsertQueryErrorMessage'];
|
||||||
|
|
||||||
|
// Initiate the connection
|
||||||
|
$dsn = "mysql:host=$host;dbname=$database;charset=$charset";
|
||||||
|
try {
|
||||||
|
$pdo = new PDO($dsn, $user, $password, $pdoConnectionOptions);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
error_log($e->getMessage());
|
||||||
|
exit($databaseConnectionErrorMessage);
|
||||||
|
}
|
||||||
|
return $pdo;
|
||||||
|
};
|
||||||
|
|
||||||
// Cryto functions
|
// Cryto functions
|
||||||
$container['cryptographyService'] = function ($c) {
|
$container['cryptographyService'] = function ($c) {
|
||||||
$cryptographySettings = $c->get('settings')['cryptography'];
|
$cryptographySettings = $c->get('settings')['cryptography'];
|
||||||
@ -27,8 +55,7 @@ $container['cryptographyService'] = function ($c) {
|
|||||||
|
|
||||||
// The session application
|
// The session application
|
||||||
$container['sessionApplication'] = function ($c) {
|
$container['sessionApplication'] = function ($c) {
|
||||||
$mysqlSettings = $c->get('settings')['mysql'];
|
|
||||||
require dirname(__FILE__) . "/../src/application/SessionApplication.php";
|
require dirname(__FILE__) . "/../src/application/SessionApplication.php";
|
||||||
$sessionApplication = new SessionApplication($mysqlSettings, $c['cryptographyService']);
|
$sessionApplication = new SessionApplication($c['mysql'], $c['cryptographyService']);
|
||||||
return $sessionApplication;
|
return $sessionApplication;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user