LoggerChain.php 808 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
 *
Benjamin Morel's avatar
Benjamin Morel committed
8
 * @link   www.doctrine-project.org
Christophe Coevoet's avatar
Christophe Coevoet committed
9
 */
10
class LoggerChain implements SQLLogger
Christophe Coevoet's avatar
Christophe Coevoet committed
11
{
12
    /** @var SQLLogger[] */
13
    private $loggers = [];
Christophe Coevoet's avatar
Christophe Coevoet committed
14 15

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

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

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