5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17 * This software consists of voluntary contributions made by many individuals
18 * and is licensed under the MIT license. For more information, see
19 * <http://www.doctrine-project.org>.
22 namespace Doctrine\DBAL\Schema\Visitor;
24 use Doctrine\DBAL\Platforms\AbstractPlatform,
25 Doctrine\DBAL\Schema\Table,
26 Doctrine\DBAL\Schema\Schema,
27 Doctrine\DBAL\Schema\Column,
28 Doctrine\DBAL\Schema\ForeignKeyConstraint,
29 Doctrine\DBAL\Schema\Constraint,
30 Doctrine\DBAL\Schema\Sequence,
31 Doctrine\DBAL\Schema\SchemaException,
32 Doctrine\DBAL\Schema\Index;
35 * Gather SQL statements that allow to completly drop the current schema.
38 * @link www.doctrine-project.org
40 * @author Benjamin Eberlei <kontakt@beberlei.de>
42 class DropSchemaSqlCollector implements Visitor
45 * @var \SplObjectStorage
50 * @var \SplObjectStorage
55 * @var \SplObjectStorage
61 * @var \Doctrine\DBAL\Platforms\AbstractPlatform
66 * @param AbstractPlatform $platform
68 public function __construct(AbstractPlatform $platform)
70 $this->platform = $platform;
71 $this->clearQueries();
75 * @param Schema $schema
77 public function acceptSchema(Schema $schema)
85 public function acceptTable(Table $table)
87 $this->tables->attach($table);
91 * @param Column $column
93 public function acceptColumn(Table $table, Column $column)
99 * @param Table $localTable
100 * @param ForeignKeyConstraint $fkConstraint
102 public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
104 if (strlen($fkConstraint->getName()) == 0) {
105 throw SchemaException::namedForeignKeyRequired($localTable, $fkConstraint);
108 $this->constraints->attach($fkConstraint);
109 $this->constraints[$fkConstraint] = $localTable;
113 * @param Table $table
114 * @param Index $index
116 public function acceptIndex(Table $table, Index $index)
122 * @param Sequence $sequence
124 public function acceptSequence(Sequence $sequence)
126 $this->sequences->attach($sequence);
132 public function clearQueries()
134 $this->constraints = new \SplObjectStorage();
135 $this->sequences = new \SplObjectStorage();
136 $this->tables = new \SplObjectStorage();
142 public function getQueries()
145 foreach ($this->constraints as $fkConstraint) {
146 $localTable = $this->constraints[$fkConstraint];
147 $sql[] = $this->platform->getDropForeignKeySQL($fkConstraint, $localTable);
150 foreach ($this->sequences as $sequence) {
151 $sql[] = $this->platform->getDropSequenceSQL($sequence);
154 foreach ($this->tables as $table) {
155 $sql[] = $this->platform->getDropTableSQL($table);