Completed
Pull Request — master (#2)
by Tomáš
09:22
created

AuthenticatorQueryFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SixtyEightPublishers\User\Authentication\Query;
6
7
use Nette;
8
use Doctrine;
9
use SixtyEightPublishers;
10
11
final class AuthenticatorQueryFactory implements IAuthenticatorQueryFactory
12
{
13
	use Nette\SmartObject;
14
15
	/** @var \Doctrine\ORM\EntityManagerInterface  */
16
	private $em;
17
18
	/** @var \SixtyEightPublishers\User\Common\UserMapping  */
19
	private $userMapping;
20
21
	/**
22
	 * @param \Doctrine\ORM\EntityManagerInterface          $em
23
	 * @param \SixtyEightPublishers\User\Common\UserMapping $userMapping
24
	 */
25
	public function __construct(Doctrine\ORM\EntityManagerInterface $em, SixtyEightPublishers\User\Common\UserMapping $userMapping)
26
	{
27
		$this->em = $em;
28
		$this->userMapping = $userMapping;
29
	}
30
31
	/************* interface \Nette\Security\IAuthenticator *************/
32
33
	/**
34
	 * {@inheritdoc}
35
	 */
36
	public function create(string $login): Doctrine\ORM\Query
37
	{
38
		$builder = $this->em->createQueryBuilder();
39
40
		$condition = $builder->expr()->eq(
41
			'u.' . $this->userMapping[$this->userMapping::FIELD_LOGIN],
42
			':login'
43
		);
44
45
		return $builder
46
			->select('u')
47
			->from(SixtyEightPublishers\User\Authentication\DoctrineEntity\IUser::class, 'u')
48
			->where($condition)
49
			->setParameter('login', $login)
50
			->setMaxResults(1)
51
			->getQuery();
52
	}
53
}
54