Fixes up the getters/setters that are generated in Builder.
This commit is contained in:
parent
38331335ab
commit
33c209db7a
@ -37,18 +37,55 @@
|
|||||||
class Doctrine_Import_Builder
|
class Doctrine_Import_Builder
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string $path the path where imported files are being generated
|
* Path
|
||||||
|
*
|
||||||
|
* the path where imported files are being generated
|
||||||
|
*
|
||||||
|
* @var string $path
|
||||||
*/
|
*/
|
||||||
private $path = '';
|
private $path = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* suffix
|
||||||
|
*
|
||||||
|
* File suffix to use when writing class definitions
|
||||||
|
*
|
||||||
|
* @var string $suffix
|
||||||
|
*/
|
||||||
private $suffix = '.class.php';
|
private $suffix = '.class.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* generateBaseClasses
|
||||||
|
*
|
||||||
|
* Bool true/false for whether or not to generate base classes
|
||||||
|
*
|
||||||
|
* @var string $suffix
|
||||||
|
*/
|
||||||
private $generateBaseClasses = false;
|
private $generateBaseClasses = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* baseClassesDirectory
|
||||||
|
*
|
||||||
|
* Directory to put the generate base classes in
|
||||||
|
*
|
||||||
|
* @var string $suffix
|
||||||
|
*/
|
||||||
private $baseClassesDirectory = 'generated';
|
private $baseClassesDirectory = 'generated';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tpl
|
||||||
|
*
|
||||||
|
* Class template used for writing classes
|
||||||
|
*
|
||||||
|
* @var $tpl
|
||||||
|
*/
|
||||||
private static $tpl;
|
private static $tpl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* __construct
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->loadTemplate();
|
$this->loadTemplate();
|
||||||
@ -98,8 +135,9 @@ class Doctrine_Import_Builder
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a template that was previously in Builder/Record.tpl. Due to the fact
|
* loadTemplate
|
||||||
* that it was not bundled when compiling, it had to be moved here.
|
*
|
||||||
|
* Loads the class template used for generating classes
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@ -127,16 +165,25 @@ END;
|
|||||||
* Build the accessors
|
* Build the accessors
|
||||||
*
|
*
|
||||||
* @param string $table
|
* @param string $table
|
||||||
* @param array $tableColumns
|
* @param array $columns
|
||||||
*/
|
*/
|
||||||
public function buildAccessors(array $options, array $columns)
|
public function buildAccessors(array $options, array $columns)
|
||||||
{
|
{
|
||||||
$ret = '';
|
$ret = '';
|
||||||
foreach ($columns as $name => $column) {
|
foreach ($columns as $name => $column) {
|
||||||
$ret .= "\tpublic function get{$name}() {\n";
|
// getters
|
||||||
$ret .= "\t\treturn \$this->{$name};\n";
|
$ret .= "\n\tpublic function get".Doctrine::classify($name)."()\n";
|
||||||
|
$ret .= "\t{\n";
|
||||||
|
$ret .= "\t\treturn \$this->get('{$name}');\n";
|
||||||
|
$ret .= "\t}\n";
|
||||||
|
|
||||||
|
// setters
|
||||||
|
$ret .= "\n\tpublic function set".Doctrine::classify($name)."()\n";
|
||||||
|
$ret .= "\t{\n";
|
||||||
|
$ret .= "\t\treturn \$this->set('{$name}');\n";
|
||||||
$ret .= "\t}\n";
|
$ret .= "\t}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,7 +321,7 @@ END;
|
|||||||
$ret = array();
|
$ret = array();
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
if (! (isset($options['override_parent']) && $options['override_parent'] == true)) {
|
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++;
|
||||||
}
|
}
|
||||||
@ -346,11 +393,11 @@ END;
|
|||||||
throw new Doctrine_Import_Builder_Exception('Missing class name.');
|
throw new Doctrine_Import_Builder_Exception('Missing class name.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$abstract = isset($options['abstract']) && $options['abstract'] == true ? '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';
|
||||||
|
|
||||||
if (isset($options['no_definition']) && $options['no_definition'] == false) {
|
if (isset($options['no_definition']) && $options['no_definition'] === false) {
|
||||||
$definition = null;
|
$definition = null;
|
||||||
$setUp = null;
|
$setUp = null;
|
||||||
} else {
|
} else {
|
||||||
@ -358,7 +405,7 @@ END;
|
|||||||
$setUp = $this->buildSetUp($options, $columns, $relations);
|
$setUp = $this->buildSetUp($options, $columns, $relations);
|
||||||
}
|
}
|
||||||
|
|
||||||
$accessors = isset($options['generate_accessors']) && $options['generate_accessors'] == true ? $this->buildAccessors($options, $columns):null;
|
$accessors = true === true ? $this->buildAccessors($options, $columns):null;
|
||||||
|
|
||||||
$content = sprintf(self::$tpl, $abstract,
|
$content = sprintf(self::$tpl, $abstract,
|
||||||
$className,
|
$className,
|
||||||
@ -433,7 +480,7 @@ END;
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($options['requires'] as $require) {
|
foreach ($options['requires'] as $require) {
|
||||||
$code .= "require_once('".$require."');";
|
$code .= "require_once('".$require."');\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user