LoggerChain.php 995 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
final 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 14 15 16 17 18 19 20
    /**
     * @param SQLLogger[] $loggers
     */
    public function __construct(array $loggers = [])
    {
        $this->loggers = $loggers;
    }

Christophe Coevoet's avatar
Christophe Coevoet committed
21
    /**
Benjamin Morel's avatar
Benjamin Morel committed
22
     * Adds a logger in the chain.
Christophe Coevoet's avatar
Christophe Coevoet committed
23
     *
24
     * @deprecated Inject list of loggers via constructor instead
Christophe Coevoet's avatar
Christophe Coevoet committed
25
     */
26
    public function addLogger(SQLLogger $logger) : void
Christophe Coevoet's avatar
Christophe Coevoet committed
27 28 29 30 31 32 33
    {
        $this->loggers[] = $logger;
    }

    /**
     * {@inheritdoc}
     */
34
    public function startQuery(string $sql, array $params = [], array $types = []) : void
Christophe Coevoet's avatar
Christophe Coevoet committed
35 36 37 38 39 40 41 42 43
    {
        foreach ($this->loggers as $logger) {
            $logger->startQuery($sql, $params, $types);
        }
    }

    /**
     * {@inheritdoc}
     */
44
    public function stopQuery() : void
Christophe Coevoet's avatar
Christophe Coevoet committed
45 46 47 48 49 50
    {
        foreach ($this->loggers as $logger) {
            $logger->stopQuery();
        }
    }
}