LoggerChain.php 811 Bytes
Newer Older
Christophe Coevoet's avatar
Christophe Coevoet committed
1 2
<?php

Michael Moravec's avatar
Michael Moravec committed
3 4
declare(strict_types=1);

Christophe Coevoet's avatar
Christophe Coevoet committed
5 6 7
namespace Doctrine\DBAL\Logging;

/**
Benjamin Morel's avatar
Benjamin Morel committed
8
 * Chains multiple SQLLogger.
Christophe Coevoet's avatar
Christophe Coevoet committed
9
 */
10
final class LoggerChain implements SQLLogger
Christophe Coevoet's avatar
Christophe Coevoet committed
11
{
12
    /** @var iterable<SQLLogger> */
13
    private $loggers = [];
Christophe Coevoet's avatar
Christophe Coevoet committed
14

15
    /**
16
     * @param iterable<SQLLogger> $loggers
17
     */
18
    public function __construct(iterable $loggers = [])
19 20 21 22
    {
        $this->loggers = $loggers;
    }

Christophe Coevoet's avatar
Christophe Coevoet committed
23 24 25
    /**
     * {@inheritdoc}
     */
26
    public function startQuery(string $sql, array $params = [], array $types = []) : void
Christophe Coevoet's avatar
Christophe Coevoet committed
27 28 29 30 31 32 33 34 35
    {
        foreach ($this->loggers as $logger) {
            $logger->startQuery($sql, $params, $types);
        }
    }

    /**
     * {@inheritdoc}
     */
36
    public function stopQuery() : void
Christophe Coevoet's avatar
Christophe Coevoet committed
37 38 39 40 41 42
    {
        foreach ($this->loggers as $logger) {
            $logger->stopQuery();
        }
    }
}