LoggerChain.php 764 Bytes
Newer Older
Christophe Coevoet's avatar
Christophe Coevoet committed
1 2 3 4 5
<?php

namespace Doctrine\DBAL\Logging;

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

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

Christophe Coevoet's avatar
Christophe Coevoet committed
21 22 23
    /**
     * {@inheritdoc}
     */
24
    public function startQuery($sql, ?array $params = null, ?array $types = null)
Christophe Coevoet's avatar
Christophe Coevoet committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
    {
        foreach ($this->loggers as $logger) {
            $logger->startQuery($sql, $params, $types);
        }
    }

    /**
     * {@inheritdoc}
     */
    public function stopQuery()
    {
        foreach ($this->loggers as $logger) {
            $logger->stopQuery();
        }
    }
}