- Moved the record template inside the builder class, otherwise it is
not included in the bundle; removed Record.tpl - Changed manual newlines to PHP_EOL - Added a parameter to explicitly set the table name - Added a parameter to explicitly set the class file target
This commit is contained in:
parent
325f0cc46d
commit
215d06c544
@ -32,6 +32,7 @@
|
||||
* @version $Revision$
|
||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||
* @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com>
|
||||
* @author Nicolas Bérard-Nault <nicobn@php.net>
|
||||
*/
|
||||
class Doctrine_Import_Builder
|
||||
{
|
||||
@ -46,13 +47,7 @@ class Doctrine_Import_Builder
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if ( ! isset(self::$tpl)) {
|
||||
self::$tpl = file_get_contents(Doctrine::getPath()
|
||||
. DIRECTORY_SEPARATOR . 'Doctrine'
|
||||
. DIRECTORY_SEPARATOR . 'Import'
|
||||
. DIRECTORY_SEPARATOR . 'Builder'
|
||||
. DIRECTORY_SEPARATOR . 'Record.tpl');
|
||||
}
|
||||
$this->loadTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,26 +74,66 @@ class Doctrine_Import_Builder
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function loadTemplate()
|
||||
{
|
||||
if (isset(self::$tpl)) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::$tpl =<<<END
|
||||
<?php
|
||||
/**
|
||||
* This class has been auto-generated by the Doctrine ORM Framework
|
||||
* Created: %s
|
||||
*/
|
||||
class %s extends Doctrine_Record
|
||||
{
|
||||
public function setTableDefinition()
|
||||
{
|
||||
%s
|
||||
}
|
||||
public function setUp()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
END;
|
||||
|
||||
}
|
||||
|
||||
public function buildRecord($table, $tableColumns, $className='', $fileName='')
|
||||
{
|
||||
if (empty($this->path)) {
|
||||
throw new Doctrine_Import_Builder_Exception('No build target directory set.');
|
||||
}
|
||||
if (is_writable($this->path) === false) {
|
||||
throw new Doctrine_Import_Builder_Exception('Build target directory ' . $this->path . ' is not writable.');
|
||||
if (empty($fileName)) {
|
||||
if (empty($this->path)) {
|
||||
$errMsg = 'No build target directory set.';
|
||||
throw new Doctrine_Import_Builder_Exception($errMsg);
|
||||
}
|
||||
|
||||
|
||||
if (is_writable($this->path) === false) {
|
||||
$errMsg = 'Build target directory ' . $this->path . ' is not writable.';
|
||||
throw new Doctrine_Import_Builder_Exception($errMsg);
|
||||
}
|
||||
|
||||
$fileName = $this->path . DIRECTORY_SEPARATOR . $className . $this->suffix;
|
||||
}
|
||||
|
||||
$created = date('l dS \of F Y h:i:s A');
|
||||
|
||||
if (empty($className)) {
|
||||
$className = Doctrine::classify($table);
|
||||
}
|
||||
|
||||
if (empty($fileName)) {
|
||||
$fileName = $this->path . DIRECTORY_SEPARATOR . $className . $this->suffix;
|
||||
}
|
||||
|
||||
$columns = array();
|
||||
$i = 0;
|
||||
$columns = array(0 => str_repeat(' ', 8) . '$this->setTableName(\'$table\');');
|
||||
$i = 1;
|
||||
|
||||
foreach ($tableColumns as $name => $column) {
|
||||
$columns[$i] = ' $this->hasColumn(\'' . $name . '\', \'' . $column['ptype'][0] . '\'';
|
||||
@ -135,14 +170,12 @@ class Doctrine_Import_Builder
|
||||
if ( ! empty($a)) {
|
||||
$columns[$i] .= ', ' . 'array(';
|
||||
$length = strlen($columns[$i]);
|
||||
$columns[$i] .= implode(',
|
||||
' . str_repeat(' ', $length), $a) . ')';
|
||||
$columns[$i] .= implode(',' . PHP_EOL . str_repeat(' ', $length), $a) . ')';
|
||||
}
|
||||
$columns[$i] .= ');';
|
||||
|
||||
if ($i < (count($table) - 1)) {
|
||||
$columns[$i] .= '
|
||||
';
|
||||
$columns[$i] .= PHP_EOL;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* This class has been auto-generated by the Doctrine ORM Framework
|
||||
* Created: %s
|
||||
*/
|
||||
class %s extends Doctrine_Record
|
||||
{
|
||||
public function setTableDefinition()
|
||||
{
|
||||
%s
|
||||
}
|
||||
public function setUp()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user