AbstractSchemaSynchronizer.php 889 Bytes
Newer Older
1 2 3 4 5
<?php

namespace Doctrine\DBAL\Schema\Synchronizer;

use Doctrine\DBAL\Connection;
6
use Throwable;
7 8 9 10 11 12

/**
 * Abstract schema synchronizer with methods for executing batches of SQL.
 */
abstract class AbstractSchemaSynchronizer implements SchemaSynchronizer
{
13
    /** @var Connection */
14 15 16 17 18 19 20
    protected $conn;

    public function __construct(Connection $conn)
    {
        $this->conn = $conn;
    }

Benjamin Morel's avatar
Benjamin Morel committed
21
    /**
22
     * @param string[] $sql
23 24
     *
     * @return void
Benjamin Morel's avatar
Benjamin Morel committed
25
     */
26 27 28 29 30
    protected function processSqlSafely(array $sql)
    {
        foreach ($sql as $s) {
            try {
                $this->conn->exec($s);
31
            } catch (Throwable $e) {
32 33 34 35
            }
        }
    }

Benjamin Morel's avatar
Benjamin Morel committed
36
    /**
37
     * @param string[] $sql
38 39
     *
     * @return void
Benjamin Morel's avatar
Benjamin Morel committed
40
     */
41 42 43 44 45 46 47
    protected function processSql(array $sql)
    {
        foreach ($sql as $s) {
            $this->conn->exec($s);
        }
    }
}