Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / lib / Doctrine / ORM / Mapping / Builder / ManyToManyAssociationBuilder.php
1 <?php
2 /*
3  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14  *
15  * This software consists of voluntary contributions made by many individuals
16  * and is licensed under the MIT license. For more information, see
17  * <http://www.doctrine-project.org>.
18  */
19
20
21 namespace Doctrine\ORM\Mapping\Builder;
22
23 /**
24  * ManyToMany Association Builder
25  *
26  * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
27  * @link        www.doctrine-project.com
28  * @since       2.0
29  * @author      Benjamin Eberlei <kontakt@beberlei.de>
30  */
31 class ManyToManyAssociationBuilder extends OneToManyAssociationBuilder
32 {
33     private $joinTableName;
34
35     private $inverseJoinColumns = array();
36
37     public function setJoinTable($name)
38     {
39         $this->joinTableName = $name;
40         return $this;
41     }
42
43     /**
44      * Add Inverse Join Columns
45      *
46      * @param string $columnName
47      * @param string $referencedColumnName
48      * @param bool $nullable
49      * @param bool $unique
50      * @param string $onDelete
51      * @param string $columnDef
52      */
53     public function addInverseJoinColumn($columnName, $referencedColumnName, $nullable = true, $unique = false, $onDelete = null, $columnDef = null)
54     {
55         $this->inverseJoinColumns[] = array(
56             'name' => $columnName,
57             'referencedColumnName' => $referencedColumnName,
58             'nullable' => $nullable,
59             'unique' => $unique,
60             'onDelete' => $onDelete,
61             'columnDefinition' => $columnDef,
62         );
63         return $this;
64     }
65
66     /**
67      * @return ClassMetadataBuilder
68      */
69     public function build()
70     {
71         $mapping = $this->mapping;
72         $mapping['joinTable'] = array();
73         if ($this->joinColumns) {
74             $mapping['joinTable']['joinColumns'] = $this->joinColumns;
75         }
76         if ($this->inverseJoinColumns) {
77             $mapping['joinTable']['inverseJoinColumns'] = $this->inverseJoinColumns;
78         }
79         if ($this->joinTableName) {
80             $mapping['joinTable']['name'] = $this->joinTableName;
81         }
82         $cm = $this->builder->getClassMetadata();
83         $cm->mapManyToMany($mapping);
84         return $this->builder;
85     }
86 }