From 0f79ed1d56526c731624fe764a62926f8eb4eaa2 Mon Sep 17 00:00:00 2001 From: pookey Date: Sun, 14 Oct 2007 19:47:38 +0000 Subject: [PATCH] improvement to option handling, and added accessor generators --- lib/Doctrine/Import/Builder.php | 44 +++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/lib/Doctrine/Import/Builder.php b/lib/Doctrine/Import/Builder.php index 441e4d57b..f80997636 100644 --- a/lib/Doctrine/Import/Builder.php +++ b/lib/Doctrine/Import/Builder.php @@ -117,11 +117,29 @@ class Doctrine_Import_Builder { %s %s +%s } 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 * @@ -253,10 +271,9 @@ END; public function buildSetUp(array $options, array $columns, array $relations) { $ret = array(); - $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();"; $i++; } @@ -327,18 +344,27 @@ END; if ( ! isset($options['className'])) { 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']; $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, $className, $extends, $definition, - $setUp); + $setUp, + $accessors); return $content; } @@ -397,7 +423,6 @@ END; public function writeDefinition(array $options, array $columns, array $relations = array(), array $indexes = array()) { $content = $this->buildDefinition($options, $columns, $relations, $indexes); - $code = "