109 lines
3.0 KiB
PHP
109 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\SQLLogin;
|
|
|
|
use App\SQLLogin\Exception\NullDataToFetchException;
|
|
|
|
class SQLLoginRequest
|
|
{
|
|
public const DATA_TO_FETCH = 'data_to_fetch';
|
|
public const LOGIN_COLUMN_NAME = 'login_column_name';
|
|
public const SALT_COLUMN_NAME = 'salt_column_name';
|
|
public const PASSWORD_COLUMN_NAME = 'password_column_name';
|
|
public const PASSWORD_NEED_UPGRADE = 'password_need_upgrade';
|
|
public const TABLE_NAME = 'table_name';
|
|
public const SUBJECT_REWRITE_EXPRESSION = 'subject_rewrite_expression';
|
|
|
|
private array $config;
|
|
private string $dsn;
|
|
private string $user;
|
|
private string $password;
|
|
|
|
public function __construct(string $dsn, string $user, string $password, array $config = [])
|
|
{
|
|
$this->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 getSubjectRewriteExpression(): ?string
|
|
{
|
|
return $this->config[self::SUBJECT_REWRITE_EXPRESSION];
|
|
}
|
|
|
|
private function getDataFields(): array
|
|
{
|
|
if (!$this->config[self::DATA_TO_FETCH]) {
|
|
throw new NullDataToFetchException();
|
|
}
|
|
|
|
return $this->config[self::DATA_TO_FETCH];
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
*/
|
|
private function getPasswordFields(): array
|
|
{
|
|
$fields[] = $this->getPasswordColumnName();
|
|
if (!empty($this->getSaltColumnName())) {
|
|
$fields[] = $this->getSaltColumnName();
|
|
}
|
|
|
|
return $fields;
|
|
}
|
|
|
|
/**
|
|
* 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 getDatasRequest(): string
|
|
{
|
|
$fields = join(',', array_merge($this->getPasswordFields(), $this->getDataFields()));
|
|
|
|
return 'SELECT '.$fields.' FROM '.$this->getTableName().' WHERE LOWER('.$this->getLoginColumnName().') = LOWER(:'.$this->getLoginColumnName().');';
|
|
}
|
|
}
|