Completed
Pull Request — master (#345)
by
unknown
05:39
created

DBALWebsiteLookupService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
namespace CultuurNet\UDB3\Organizer;
4
5
use CultuurNet\UDB3\EventSourcing\DBAL\UniqueDBALEventStoreDecorator;
6
use Doctrine\DBAL\Connection;
7
use ValueObjects\Web\Url;
8
9
class DBALWebsiteLookupService implements WebsiteLookupServiceInterface
10
{
11
    /**
12
     * @var Connection
13
     */
14
    private $connection;
15
16
    /**
17
     * @var string
18
     */
19
    private $tableName;
20
21
    /**
22
     * @param Connection $connection
23
     * @param string $tableName
24
     */
25
    public function __construct(
26
        Connection $connection,
27
        $tableName
28
    ) {
29
        $this->connection = $connection;
30
        $this->tableName = (string) $tableName;
31
    }
32
33
    /**
34
     * @inheritdoc
35
     */
36
    public function lookup(Url $url)
37
    {
38
        $expr = $this->connection->getExpressionBuilder();
39
40
        $results = $this->connection->createQueryBuilder()
41
            ->select(UniqueDBALEventStoreDecorator::UUID_COLUMN)
42
            ->from($this->tableName)
43
            ->where($expr->eq(UniqueDBALEventStoreDecorator::UNIQUE_COLUMN, ':url'))
44
            ->setParameter(':url', (string) $url)
45
            ->execute();
46
47
        $uuid = $results->fetchColumn();
48
        return $uuid ? $uuid : null;
49
    }
50
}
51