1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Explicit Architecture POC, |
7
|
|
|
* which is created on top of the Symfony Demo application. |
8
|
|
|
* |
9
|
|
|
* (c) Herberto Graça <[email protected]> |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
12
|
|
|
* file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Acme\App\Infrastructure\Auth\Authentication; |
16
|
|
|
|
17
|
|
|
use Acme\App\Core\Component\User\Domain\User\User; |
18
|
|
|
use Acme\App\Core\Port\Persistence\DQL\DqlQueryBuilderInterface; |
19
|
|
|
use Acme\App\Core\Port\Persistence\QueryServiceRouterInterface; |
20
|
|
|
|
21
|
|
|
final class SecurityUserQuery |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var DqlQueryBuilderInterface |
25
|
|
|
*/ |
26
|
|
|
private $dqlQueryBuilder; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var QueryServiceRouterInterface |
30
|
|
|
*/ |
31
|
|
|
private $queryService; |
32
|
|
|
|
33
|
|
|
public function __construct( |
34
|
|
|
DqlQueryBuilderInterface $dqlQueryBuilder, |
35
|
|
|
QueryServiceRouterInterface $queryService |
36
|
|
|
) { |
37
|
|
|
$this->dqlQueryBuilder = $dqlQueryBuilder; |
38
|
|
|
$this->queryService = $queryService; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function execute(string $username): SecurityUser |
42
|
|
|
{ |
43
|
|
|
$this->dqlQueryBuilder->create(User::class, 'User') |
44
|
|
|
->select( |
45
|
|
|
'User.id AS userId', |
46
|
|
|
'User.username AS username', |
47
|
|
|
'User.password AS password', |
48
|
|
|
'User.roles AS roles' |
49
|
|
|
) |
50
|
|
|
->where('User.username = :username') |
51
|
|
|
->setParameter('username', $username); |
52
|
|
|
|
53
|
|
|
return $this->queryService->query($this->dqlQueryBuilder->build())->hydrateSingleResultAs(SecurityUser::class); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|