SchemaCreateTableEventArgs.php 1.85 KB
Newer Older
1 2 3 4
<?php

namespace Doctrine\DBAL\Event;

Benjamin Morel's avatar
Benjamin Morel committed
5
use Doctrine\DBAL\Platforms\AbstractPlatform;
6
use Doctrine\DBAL\Schema\Column;
Benjamin Morel's avatar
Benjamin Morel committed
7
use Doctrine\DBAL\Schema\Table;
8 9
use function array_merge;
use function is_array;
10 11 12 13 14 15

/**
 * Event Arguments used when SQL queries for creating tables are generated inside Doctrine\DBAL\Platform\AbstractPlatform.
 */
class SchemaCreateTableEventArgs extends SchemaEventArgs
{
16
    /** @var Table */
17
    private $table;
18

19
    /** @var Column[] */
20
    private $columns;
21

22
    /** @var mixed[] */
23
    private $options;
24

25
    /** @var AbstractPlatform */
26
    private $platform;
27

28
    /** @var string[] */
29
    private $sql = [];
30

jsor's avatar
jsor committed
31
    /**
32 33
     * @param Column[] $columns
     * @param mixed[]  $options
jsor's avatar
jsor committed
34
     */
35
    public function __construct(Table $table, array $columns, array $options, AbstractPlatform $platform)
36
    {
37 38 39 40
        $this->table    = $table;
        $this->columns  = $columns;
        $this->options  = $options;
        $this->platform = $platform;
41 42 43
    }

    /**
44
     * @return Table
45 46 47
     */
    public function getTable()
    {
48
        return $this->table;
49 50
    }

51
    /**
52
     * @return Column[]
53 54 55
     */
    public function getColumns()
    {
56
        return $this->columns;
57 58 59
    }

    /**
60
     * @return mixed[]
61 62 63
     */
    public function getOptions()
    {
64
        return $this->options;
65 66
    }

67
    /**
68
     * @return AbstractPlatform
69 70 71
     */
    public function getPlatform()
    {
72
        return $this->platform;
73
    }
jsor's avatar
jsor committed
74 75

    /**
76
     * @param string|string[] $sql
Benjamin Morel's avatar
Benjamin Morel committed
77
     *
78
     * @return \Doctrine\DBAL\Event\SchemaCreateTableEventArgs
jsor's avatar
jsor committed
79 80 81 82
     */
    public function addSql($sql)
    {
        if (is_array($sql)) {
83
            $this->sql = array_merge($this->sql, $sql);
jsor's avatar
jsor committed
84
        } else {
85
            $this->sql[] = $sql;
jsor's avatar
jsor committed
86 87 88 89 90 91
        }

        return $this;
    }

    /**
92
     * @return string[]
jsor's avatar
jsor committed
93 94 95
     */
    public function getSql()
    {
96
        return $this->sql;
jsor's avatar
jsor committed
97
    }
98
}