config = $config; $this->dsn = $dsn; $this->user = $user; $this->password = $password; } public function getDatabaseDsn(): string { return $this->dsn; } public function getDbUser(): string { return $this->user; } public function getDbPassword(): string { return $this->password; } public function getLoginColumnName(): string { return $this->config[self::LOGIN_COLUMN_NAME]; } public function getPasswordColumnName(): string { return $this->config[self::PASSWORD_COLUMN_NAME]; } public function getSaltColumnName(): ?string { return $this->config[self::SALT_COLUMN_NAME]; } public function getTableName(): string { return $this->config[self::TABLE_NAME]; } public function getDataToFetch(): array { return $this->config[self::DATA_TO_FETCH]; } public function getRequestScope() { $scope = ''; foreach ($this->config[self::DATA_TO_FETCH] as $data) { $scope .= $data.','; } $scope = substr($scope, 0, -1); return 'SELECT '.$scope.' FROM '.$this->getTableName().' WHERE '.$this->getLoginColumnName().' = :'.$this->getLoginColumnName().';'; } /** * Construction de la string pour la requête préparée selon la configuration yaml * intègre la récupération du mot de passe hashé, du salt et de besoin d'upgrade de la méthode de hashage */ public function getRequestPassword() { $fields = $this->getPasswordColumnName(); if (!empty($this->getSaltColumnName())) { $fields .= ', '.$this->getSaltColumnName(); } return 'SELECT '.$fields.' FROM '.$this->getTableName().' WHERE '.$this->getLoginColumnName().' = :'.$this->getLoginColumnName().';'; } public function getRequestUpdatePassword() { $fieldsToUpdate = $this->getPasswordColumnName().'= :'.$this->getPasswordColumnName().','; if (!empty($this->getSaltColumnName())) { $fieldsToUpdate .= $this->getSaltColumnName().'= :'.$this->getSaltColumnName().','; } $fieldsToUpdate = substr($fieldsToUpdate, 0, -1); return 'UPDATE '.$this->getTableName().' SET '.$fieldsToUpdate.' WHERE '.$this->getLoginColumnName().' = :'.$this->getLoginColumnName().';'; } }