Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / dbal / lib / Doctrine / DBAL / Schema / Visitor / DropSchemaSqlCollector.php
1 <?php
2 /*
3  *  $Id$
4  *
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.
16  *
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>.
20  */
21
22 namespace Doctrine\DBAL\Schema\Visitor;
23
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;
33
34 /**
35  * Gather SQL statements that allow to completly drop the current schema.
36  *
37  * 
38  * @link    www.doctrine-project.org
39  * @since   2.0
40  * @author  Benjamin Eberlei <kontakt@beberlei.de>
41  */
42 class DropSchemaSqlCollector implements Visitor
43 {
44     /**
45      * @var \SplObjectStorage
46      */
47     private $constraints;
48
49     /**
50      * @var \SplObjectStorage
51      */
52     private $sequences;
53
54     /**
55      * @var \SplObjectStorage
56      */
57     private $tables;
58
59     /**
60      *
61      * @var \Doctrine\DBAL\Platforms\AbstractPlatform
62      */
63     private $platform;
64
65     /**
66      * @param AbstractPlatform $platform
67      */
68     public function __construct(AbstractPlatform $platform)
69     {
70         $this->platform = $platform;
71         $this->clearQueries();
72     }
73
74     /**
75      * @param Schema $schema
76      */
77     public function acceptSchema(Schema $schema)
78     {
79
80     }
81
82     /**
83      * @param Table $table
84      */
85     public function acceptTable(Table $table)
86     {
87         $this->tables->attach($table);
88     }
89
90     /**
91      * @param Column $column
92      */
93     public function acceptColumn(Table $table, Column $column)
94     {
95
96     }
97
98     /**
99      * @param Table $localTable
100      * @param ForeignKeyConstraint $fkConstraint
101      */
102     public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
103     {
104         if (strlen($fkConstraint->getName()) == 0) {
105             throw SchemaException::namedForeignKeyRequired($localTable, $fkConstraint);
106         }
107
108         $this->constraints->attach($fkConstraint);
109         $this->constraints[$fkConstraint] = $localTable;
110     }
111
112     /**
113      * @param Table $table
114      * @param Index $index
115      */
116     public function acceptIndex(Table $table, Index $index)
117     {
118
119     }
120
121     /**
122      * @param Sequence $sequence
123      */
124     public function acceptSequence(Sequence $sequence)
125     {
126         $this->sequences->attach($sequence);
127     }
128
129     /**
130      * @return void
131      */
132     public function clearQueries()
133     {
134         $this->constraints = new \SplObjectStorage();
135         $this->sequences = new \SplObjectStorage();
136         $this->tables = new \SplObjectStorage();
137     }
138
139     /**
140      * @return array
141      */
142     public function getQueries()
143     {
144         $sql = array();
145         foreach ($this->constraints as $fkConstraint) {
146             $localTable = $this->constraints[$fkConstraint];
147             $sql[] = $this->platform->getDropForeignKeySQL($fkConstraint, $localTable);
148         }
149
150         foreach ($this->sequences as $sequence) {
151             $sql[] = $this->platform->getDropSequenceSQL($sequence);
152         }
153
154         foreach ($this->tables as $table) {
155             $sql[] = $this->platform->getDropTableSQL($table);
156         }
157
158         return $sql;
159     }
160 }