improvement to option handling, and added accessor generators
This commit is contained in:
parent
6e020bef2a
commit
0f79ed1d56
@ -117,11 +117,29 @@ class Doctrine_Import_Builder
|
|||||||
{
|
{
|
||||||
%s
|
%s
|
||||||
%s
|
%s
|
||||||
|
%s
|
||||||
}
|
}
|
||||||
END;
|
END;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Build the accessors
|
||||||
|
*
|
||||||
|
* @param string $table
|
||||||
|
* @param array $tableColumns
|
||||||
|
*/
|
||||||
|
public function buildAccessors(array $options, array $columns)
|
||||||
|
{
|
||||||
|
$ret = '';
|
||||||
|
foreach ($columns as $name => $column) {
|
||||||
|
$ret .= "\tpublic function get{$name}() {\n";
|
||||||
|
$ret .= "\t\treturn \$this->{$name};\n";
|
||||||
|
$ret .= "\t}\n";
|
||||||
|
}
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Build the table definition of a Doctrine_Record object
|
* Build the table definition of a Doctrine_Record object
|
||||||
*
|
*
|
||||||
@ -253,10 +271,9 @@ END;
|
|||||||
public function buildSetUp(array $options, array $columns, array $relations)
|
public function buildSetUp(array $options, array $columns, array $relations)
|
||||||
{
|
{
|
||||||
$ret = array();
|
$ret = array();
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
if (isset($options['inheritance']['extends']) && !isset($options['override_parent'])) {
|
if (! (isset($options['override_parent']) && $options['override_parent'] == true)) {
|
||||||
$ret[$i] = "\t\t\t\tparent::setUp();";
|
$ret[$i] = "\t\t\t\tparent::setUp();";
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
@ -328,17 +345,26 @@ END;
|
|||||||
throw new Doctrine_Import_Builder_Exception('Missing class name.');
|
throw new Doctrine_Import_Builder_Exception('Missing class name.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$abstract = isset($options['abstract']) ? 'abstract ':null;
|
$abstract = isset($options['abstract']) && $options['abstract'] == true ? 'abstract ':null;
|
||||||
$className = $options['className'];
|
$className = $options['className'];
|
||||||
$extends = isset($options['inheritance']['extends']) ? $options['inheritance']['extends']:'Doctrine_Record';
|
$extends = isset($options['inheritance']['extends']) ? $options['inheritance']['extends']:'Doctrine_Record';
|
||||||
$definition = !isset($options['no_definition']) ? $this->buildTableDefinition($options, $columns, $relations, $indexes):null;
|
|
||||||
$setUp = !isset($options['no_definition']) ? $this->buildSetUp($options, $columns, $relations):null;
|
if (isset($options['no_definition']) && $options['no_definition'] == false) {
|
||||||
|
$definition = null;
|
||||||
|
$setUp = null;
|
||||||
|
} else {
|
||||||
|
$definition = $this->buildTableDefinition($options, $columns, $relations, $indexes);
|
||||||
|
$setUp = $this->buildSetUp($options, $columns, $relations);
|
||||||
|
}
|
||||||
|
|
||||||
|
$accessors = isset($options['generate_accessors']) && $options['generate_accessors'] == true ? $this->buildAccessors($options, $columns):null;
|
||||||
|
|
||||||
$content = sprintf(self::$tpl, $abstract,
|
$content = sprintf(self::$tpl, $abstract,
|
||||||
$className,
|
$className,
|
||||||
$extends,
|
$extends,
|
||||||
$definition,
|
$definition,
|
||||||
$setUp);
|
$setUp,
|
||||||
|
$accessors);
|
||||||
|
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
@ -397,7 +423,6 @@ END;
|
|||||||
public function writeDefinition(array $options, array $columns, array $relations = array(), array $indexes = array())
|
public function writeDefinition(array $options, array $columns, array $relations = array(), array $indexes = array())
|
||||||
{
|
{
|
||||||
$content = $this->buildDefinition($options, $columns, $relations, $indexes);
|
$content = $this->buildDefinition($options, $columns, $relations, $indexes);
|
||||||
|
|
||||||
$code = "<?php\n";
|
$code = "<?php\n";
|
||||||
|
|
||||||
if (isset($options['requires'])) {
|
if (isset($options['requires'])) {
|
||||||
@ -409,7 +434,6 @@ END;
|
|||||||
$code .= "require_once('".$require."');";
|
$code .= "require_once('".$require."');";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$code .= PHP_EOL . $content;
|
$code .= PHP_EOL . $content;
|
||||||
|
|
||||||
$bytes = file_put_contents($options['fileName'], $code);
|
$bytes = file_put_contents($options['fileName'], $code);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user