LoggerChain.php 994 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 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 25
     * @deprecated Inject list of loggers via constructor instead
     *
Benjamin Morel's avatar
Benjamin Morel committed
26
     * @return void
Christophe Coevoet's avatar
Christophe Coevoet committed
27 28 29 30 31 32 33 34 35
     */
    public function addLogger(SQLLogger $logger)
    {
        $this->loggers[] = $logger;
    }

    /**
     * {@inheritdoc}
     */
36
    public function startQuery($sql, ?array $params = null, ?array $types = null)
Christophe Coevoet's avatar
Christophe Coevoet committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
    {
        foreach ($this->loggers as $logger) {
            $logger->startQuery($sql, $params, $types);
        }
    }

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