LoggerChain.php 769 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 SQLLogger[] */
11
    private $loggers = [];
Christophe Coevoet's avatar
Christophe Coevoet committed
12 13

    /**
Benjamin Morel's avatar
Benjamin Morel committed
14
     * Adds a logger in the chain.
Christophe Coevoet's avatar
Christophe Coevoet committed
15
     *
Benjamin Morel's avatar
Benjamin Morel committed
16
     * @return void
Christophe Coevoet's avatar
Christophe Coevoet committed
17 18 19 20 21 22 23 24 25
     */
    public function addLogger(SQLLogger $logger)
    {
        $this->loggers[] = $logger;
    }

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

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