[add] Injecting dependency

This commit is contained in:
Jose Pabl Domingo Aramburo Sanchez 2018-08-05 04:30:50 -06:00
parent 2920fdd89b
commit 09f11ebe49
3 changed files with 10 additions and 5 deletions

View File

@ -3,6 +3,7 @@
class SessionApplication{ class SessionApplication{
// The to be connection // The to be connection
private $pdo = ''; private $pdo = '';
private $cryptographyService;
function __construct($mysqlSettings, $cryptographyService){ function __construct($mysqlSettings, $cryptographyService){
// Services // Services
@ -33,9 +34,13 @@ class SessionApplication{
function newSession($userName, $password){ function newSession($userName, $password){
$real = 'slothness'; $real = 'slothness';
$password = "$2y$12$51mfESaLEGXDT4u9Bd9kiOHEpaJ1Bx4SEcVwsU5K6jVPMNkrnpJAa";
if($this->cryptographyService->decryptPassword($real, $password)){ if($this->cryptographyService->decryptPassword($real, $password)){
return "yea";
}
else{
"nah";
} }
} }
} }

View File

@ -27,11 +27,8 @@ $container['cryptographyService'] = function ($c) {
// The session application // The session application
$container['sessionApplication'] = function ($c) { $container['sessionApplication'] = function ($c) {
$cryptographySettings = $c->get('settings')['cryptography'];
$cryptographyService = new App\Service\CryptographyService($cryptographySettings);
$mysqlSettings = $c->get('settings')['mysql']; $mysqlSettings = $c->get('settings')['mysql'];
require dirname(__FILE__) . "/../src/application/SessionApplication.php"; require dirname(__FILE__) . "/../src/application/SessionApplication.php";
$sessionApplication = new SessionApplication($mysqlSettings, $cryptographyService); $sessionApplication = new SessionApplication($mysqlSettings, $c['cryptographyService']);
return $sessionApplication; return $sessionApplication;
}; };

View File

@ -42,4 +42,7 @@ $app->get('/api/decrypt/password/{string}', function (Request $request, Response
if ($cosa){ if ($cosa){
return "yea"; return "yea";
} }
else{
"nah";
}
}); });