From 3e39fcf30c24e1cb23463b50f50c6edd7de0c67d Mon Sep 17 00:00:00 2001 From: phuson Date: Wed, 17 Oct 2007 09:18:59 +0000 Subject: [PATCH] Implemented generation for loadTemplate() from Schema file. --- lib/Doctrine/Import/Builder.php | 20 ++++++++++++++++++++ lib/Doctrine/Import/Schema.php | 2 ++ 2 files changed, 22 insertions(+) diff --git a/lib/Doctrine/Import/Builder.php b/lib/Doctrine/Import/Builder.php index f0e962b02..c54a4391f 100644 --- a/lib/Doctrine/Import/Builder.php +++ b/lib/Doctrine/Import/Builder.php @@ -210,6 +210,26 @@ END; $i++; } + if (isset($options['templates']) && !empty($options['templates'])) { + $ret[$i] = PHP_EOL .str_repeat(' ', 8) . '// Load Class Template(s)'; + $i++; + + if (!is_array($options['templates'])) { + // explode to extract each template separated by commas + $templatesArray = explode(',', $options['templates']); + } else { + // set the existing array to templatesArray to be traversed through + $templatesArray = $options['templates']; + } + + foreach ($templatesArray as $templateName) { + $ret[$i] = str_repeat(' ', 8) . '$this->loadTemplate(\''. trim($templateName) .'\');'; + $i++; + } + $ret[$i] = ''; + $i++; + } + foreach ($columns as $name => $column) { $ret[$i] = ' $this->hasColumn(\'' . $name . '\', \'' . $column['type'] . '\''; diff --git a/lib/Doctrine/Import/Schema.php b/lib/Doctrine/Import/Schema.php index 69fda7119..2cf371f3d 100644 --- a/lib/Doctrine/Import/Schema.php +++ b/lib/Doctrine/Import/Schema.php @@ -139,6 +139,7 @@ class Doctrine_Import_Schema $options['className'] = $properties['className']; $options['fileName'] = $directory.DIRECTORY_SEPARATOR.$properties['className'].'.class.php'; $options['tableName'] = isset($properties['tableName']) ? $properties['tableName']:null; + $options['templates'] = isset($properties['templates']) ? $properties['templates']:null; if (isset($properties['inheritance'])) { $options['inheritance'] = $properties['inheritance']; @@ -239,6 +240,7 @@ class Doctrine_Import_Schema $build[$className]['tableName'] = $tableName; $build[$className]['columns'] = $columns; + $build[$className]['templates'] = isset($table['templates']) ? $table['templates']:array(); $build[$className]['relations'] = isset($table['relations']) ? $table['relations']:array(); $build[$className]['indexes'] = isset($table['indexes']) ? $table['indexes']:array(); $build[$className]['attributes'] = isset($table['attributes']) ? $table['attributes']:array();