Source for file Builder.php
Documentation is available at Builder.php
* $Id: Builder.php 2051 2007-07-23 20:28:46Z zYne $
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
* Doctrine_Import_Builder
* Import builder is responsible of building Doctrine ActiveRecord classes
* based on a database schema.
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version $Revision: 2051 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com>
* @author Nicolas Bérard-Nault <nicobn@php.net>
* @var string $path the path where imported files are being generated
* @param string path the path where imported files are being generated
* @return string the path where imported files are being generated
* This is a template that was previously in Builder/Record.tpl. Due to the fact
* that it was not bundled when compiling, it had to be moved here.
*
This class has been auto-
generated by the Doctrine ORM Framework
public function setTableDefinition()
* Build the table definition of a Doctrine_Record object
* @param array $tableColumns
foreach ($tableColumns as $name =>
$column) {
$columns[$i] =
' $this->hasColumn(\'' .
$name .
'\', \'' .
$column['type'] .
'\'';
$columns[$i] .=
', ' .
$column['length'];
$columns[$i] .=
', null';
if (isset
($column['default']) &&
$column['default']) {
$a[] =
'\'default\' => ' .
var_export($column['default'], true);
if (isset
($column['notnull']) &&
$column['notnull']) {
$a[] =
'\'notnull\' => true';
if (isset
($column['primary']) &&
$column['primary']) {
$a[] =
'\'primary\' => true';
if (isset
($column['autoinc']) &&
$column['autoinc']) {
$a[] =
'\'autoincrement\' => true';
if (isset
($column['unique']) &&
$column['unique']) {
$a[] =
'\'unique\' => true';
if (isset
($column['unsigned']) &&
$column['unsigned']) {
$a[] =
'\'unsigned\' => true';
if ($column['type'] ==
'enum' && isset
($column['values']) &&
$column['values']) {
$a[] =
'\'values\' => array(' .
implode(',', $column['values']) .
')';
$columns[$i] .=
', ' .
'array(';
$length =
strlen($columns[$i]);
if ($i <
(count($tableColumns) -
1)) {
return implode("\n", $columns);
foreach ($relations as $name =>
$relation) {
$alias =
(isset
($relation['alias']) &&
$relation['alias'] !==
$name) ?
' as ' .
$relation['alias'] :
'';
if ( ! isset
($relation['type'])) {
$ret[$i] =
' $this->hasOne(\'' .
$name .
$alias .
'\'';
$ret[$i] =
' $this->hasMany(\'' .
$name .
$alias .
'\'';
if (isset
($relation['deferred']) &&
$relation['deferred']) {
$a[] =
'\'default\' => ' .
var_export($relation['deferred'], true);
if (isset
($relation['local']) &&
$relation['local']) {
$a[] =
'\'local\' => ' .
var_export($relation['local'], true);
if (isset
($relation['foreign']) &&
$relation['foreign']) {
$a[] =
'\'foreign\' => ' .
var_export($relation['foreign'], true);
if (isset
($relation['onDelete']) &&
$relation['onDelete']) {
$a[] =
'\'onDelete\' => ' .
var_export($relation['onDelete'], true);
if (isset
($relation['onUpdate']) &&
$relation['onUpdate']) {
$a[] =
'\'onUpdate\' => ' .
var_export($relation['onUpdate'], true);
$ret[$i] .=
', ' .
'array(';
public function buildDefinition(array $options, array $columns, array $relations =
array())
if ( ! isset
($options['className'])) {
//$opt = array(0 => str_repeat(' ', 8) . '$this->setTableName(\''. $table .'\');');
$content =
sprintf(self::$tpl, $options['className'],
$this->buildColumnDefinition($columns),
public function buildRecord($options, $columns, $relations)
if ( ! isset
($options['className'])) {
if ( ! isset
($options['fileName'])) {
if (empty($this->path)) {
$errMsg =
'No build target directory set.';
$errMsg =
'Build target directory ' .
$this->path .
' is not writable.';
$options['fileName'] =
$this->path .
DIRECTORY_SEPARATOR .
$options['className'] .
$this->suffix;