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.
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>.
21 namespace Doctrine\ORM\Mapping\Builder;
26 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
27 * @link www.doctrine-project.com
29 * @author Benjamin Eberlei <kontakt@beberlei.de>
34 * @var ClassMetadataBuilder
49 private $generatedValue;
58 * @param ClassMetadataBuilder $builder
59 * @param array $mapping
61 public function __construct(ClassMetadataBuilder $builder, array $mapping)
63 $this->builder = $builder;
64 $this->mapping = $mapping;
71 * @return FieldBuilder
73 public function length($length)
75 $this->mapping['length'] = $length;
83 * @return FieldBuilder
85 public function nullable($flag = true)
87 $this->mapping['nullable'] = (bool)$flag;
95 * @return FieldBuilder
97 public function unique($flag = true)
99 $this->mapping['unique'] = (bool)$flag;
106 * @param string $name
107 * @return FieldBuilder
109 public function columnName($name)
111 $this->mapping['columnName'] = $name;
119 * @return FieldBuilder
121 public function precision($p)
123 $this->mapping['precision'] = $p;
131 * @return FieldBuilder
133 public function scale($s)
135 $this->mapping['scale'] = $s;
140 * Set field as primary key.
142 * @return FieldBuilder
144 public function isPrimaryKey()
146 $this->mapping['id'] = true;
151 * @param int $strategy
152 * @return FieldBuilder
154 public function generatedValue($strategy = 'AUTO')
156 $this->generatedValue = $strategy;
161 * Set field versioned
163 * @return FieldBuilder
165 public function isVersionField()
167 $this->version = true;
172 * Set Sequence Generator
174 * @param string $sequenceName
175 * @param int $allocationSize
176 * @param int $initialValue
177 * @return FieldBuilder
179 public function setSequenceGenerator($sequenceName, $allocationSize = 1, $initialValue = 1)
181 $this->sequenceDef = array(
182 'sequenceName' => $sequenceName,
183 'allocationSize' => $allocationSize,
184 'initialValue' => $initialValue,
190 * Set column definition.
193 * @return FieldBuilder
195 public function columnDefinition($def)
197 $this->mapping['columnDefinition'] = $def;
202 * Finalize this field and attach it to the ClassMetadata.
204 * Without this call a FieldBuilder has no effect on the ClassMetadata.
206 * @return ClassMetadataBuilder
208 public function build()
210 $cm = $this->builder->getClassMetadata();
211 if ($this->generatedValue) {
212 $cm->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_' . $this->generatedValue));
214 if ($this->version) {
215 $cm->setVersionMapping($this->mapping);
217 $cm->mapField($this->mapping);
218 if ($this->sequenceDef) {
219 $cm->setSequenceGeneratorDefinition($this->sequenceDef);
221 return $this->builder;