diff --git a/lib/Doctrine/Import/Builder.php b/lib/Doctrine/Import/Builder.php index defc1dc9a..bc87d5d7a 100644 --- a/lib/Doctrine/Import/Builder.php +++ b/lib/Doctrine/Import/Builder.php @@ -32,6 +32,7 @@ * @version $Revision$ * @author Konsta Vesterinen * @author Jukka Hassinen + * @author Nicolas BĂ©rard-Nault */ 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; + + } + 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++; } diff --git a/lib/Doctrine/Import/Builder/Record.tpl b/lib/Doctrine/Import/Builder/Record.tpl deleted file mode 100644 index 1cd9b1abd..000000000 --- a/lib/Doctrine/Import/Builder/Record.tpl +++ /dev/null @@ -1,16 +0,0 @@ -