- 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$
|
* @version $Revision$
|
||||||
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
||||||
* @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com>
|
* @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com>
|
||||||
|
* @author Nicolas Bérard-Nault <nicobn@php.net>
|
||||||
*/
|
*/
|
||||||
class Doctrine_Import_Builder
|
class Doctrine_Import_Builder
|
||||||
{
|
{
|
||||||
@ -46,13 +47,7 @@ class Doctrine_Import_Builder
|
|||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
if ( ! isset(self::$tpl)) {
|
$this->loadTemplate();
|
||||||
self::$tpl = file_get_contents(Doctrine::getPath()
|
|
||||||
. DIRECTORY_SEPARATOR . 'Doctrine'
|
|
||||||
. DIRECTORY_SEPARATOR . 'Import'
|
|
||||||
. DIRECTORY_SEPARATOR . 'Builder'
|
|
||||||
. DIRECTORY_SEPARATOR . 'Record.tpl');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,26 +74,66 @@ class Doctrine_Import_Builder
|
|||||||
return $this->path;
|
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='')
|
public function buildRecord($table, $tableColumns, $className='', $fileName='')
|
||||||
{
|
{
|
||||||
if (empty($this->path)) {
|
if (empty($fileName)) {
|
||||||
throw new Doctrine_Import_Builder_Exception('No build target directory set.');
|
if (empty($this->path)) {
|
||||||
}
|
$errMsg = 'No build target directory set.';
|
||||||
if (is_writable($this->path) === false) {
|
throw new Doctrine_Import_Builder_Exception($errMsg);
|
||||||
throw new Doctrine_Import_Builder_Exception('Build target directory ' . $this->path . ' is not writable.');
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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');
|
$created = date('l dS \of F Y h:i:s A');
|
||||||
|
|
||||||
if (empty($className)) {
|
if (empty($className)) {
|
||||||
$className = Doctrine::classify($table);
|
$className = Doctrine::classify($table);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($fileName)) {
|
$columns = array(0 => str_repeat(' ', 8) . '$this->setTableName(\'$table\');');
|
||||||
$fileName = $this->path . DIRECTORY_SEPARATOR . $className . $this->suffix;
|
$i = 1;
|
||||||
}
|
|
||||||
|
|
||||||
$columns = array();
|
|
||||||
$i = 0;
|
|
||||||
|
|
||||||
foreach ($tableColumns as $name => $column) {
|
foreach ($tableColumns as $name => $column) {
|
||||||
$columns[$i] = ' $this->hasColumn(\'' . $name . '\', \'' . $column['ptype'][0] . '\'';
|
$columns[$i] = ' $this->hasColumn(\'' . $name . '\', \'' . $column['ptype'][0] . '\'';
|
||||||
@ -135,14 +170,12 @@ class Doctrine_Import_Builder
|
|||||||
if ( ! empty($a)) {
|
if ( ! empty($a)) {
|
||||||
$columns[$i] .= ', ' . 'array(';
|
$columns[$i] .= ', ' . 'array(';
|
||||||
$length = strlen($columns[$i]);
|
$length = strlen($columns[$i]);
|
||||||
$columns[$i] .= implode(',
|
$columns[$i] .= implode(',' . PHP_EOL . str_repeat(' ', $length), $a) . ')';
|
||||||
' . str_repeat(' ', $length), $a) . ')';
|
|
||||||
}
|
}
|
||||||
$columns[$i] .= ');';
|
$columns[$i] .= ');';
|
||||||
|
|
||||||
if ($i < (count($table) - 1)) {
|
if ($i < (count($table) - 1)) {
|
||||||
$columns[$i] .= '
|
$columns[$i] .= PHP_EOL;
|
||||||
';
|
|
||||||
}
|
}
|
||||||
$i++;
|
$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