From 1c3b2278814c7b028000d9e74833b137d7ad3e71 Mon Sep 17 00:00:00 2001 From: avl Date: Fri, 29 Aug 2008 04:41:00 +0200 Subject: [PATCH] Import Scheme refactor --- ipf/orm/import/builder.php | 16 ++++++++-------- ipf/orm/import/schema.php | 13 ++++++++----- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/ipf/orm/import/builder.php b/ipf/orm/import/builder.php index 34d683f..2b996af 100644 --- a/ipf/orm/import/builder.php +++ b/ipf/orm/import/builder.php @@ -14,7 +14,6 @@ class IPF_ORM_Import_Builder extends IPF_ORM_Builder protected $_baseClassName = 'IPF_ORM_Record'; protected $_generateAccessors = false; protected static $_tpl; - public function __construct() { $this->loadTemplate(); @@ -66,6 +65,7 @@ class IPF_ORM_Import_Builder extends IPF_ORM_Builder if ($bool !== null) { $this->_generateAccessors = $bool; } + return $this->_generateAccessors; } @@ -127,7 +127,7 @@ class IPF_ORM_Import_Builder extends IPF_ORM_Builder } self::$_tpl = '/**' . PHP_EOL - . ' * This class has been auto-generated by the IPF ORM Framework' . PHP_EOL + . ' * This class has been auto-generated by the IPF_ORM Framework' . PHP_EOL . ' */' . PHP_EOL . '%sclass %s extends %s' . PHP_EOL . '{' @@ -289,6 +289,7 @@ class IPF_ORM_Import_Builder extends IPF_ORM_Builder if ($code) { return ' public function setUp()' . PHP_EOL . ' {' . PHP_EOL . ' ' . $code . PHP_EOL . ' }'; } + } public function buildColumns(array $columns) @@ -312,13 +313,13 @@ class IPF_ORM_Import_Builder extends IPF_ORM_Builder unset($options['ntype']); // Remove notnull => true if the column is primary - // Primary columns are implied to be notnull in IPF + // Primary columns are implied to be notnull in IPF_ORM if (isset($options['primary']) && $options['primary'] == true && (isset($options['notnull']) && $options['notnull'] == true)) { unset($options['notnull']); } // Remove default if the value is 0 and the column is a primary key - // IPF defaults to 0 if it is a primary key + // IPF_ORM defaults to 0 if it is a primary key if (isset($options['primary']) && $options['primary'] == true && (isset($options['default']) && $options['default'] == 0)) { unset($options['default']); } @@ -491,6 +492,7 @@ class IPF_ORM_Import_Builder extends IPF_ORM_Builder return PHP_EOL." ".'$this->addListener(new '.$listener.'());'; } + public function buildAttributes(array $attributes) { $build = PHP_EOL; @@ -582,12 +584,10 @@ class IPF_ORM_Import_Builder extends IPF_ORM_Builder public function buildRecord(array $definition) { - if ( ! isset($definition['className'])) { + if ( !isset($definition['className'])) { throw new IPF_ORM_Exception('Missing class name.'); } - $definition['topLevelClassName'] = $definition['className']; - if ($this->generateBaseClasses()) { $definition['is_package'] = (isset($definition['package']) && $definition['package']) ? true:false; @@ -702,7 +702,7 @@ class IPF_ORM_Import_Builder extends IPF_ORM_Builder $this->writeTableDefinition($definition['tableClassName'], $writePath, array('extends' => $definition['inheritance']['tableExtends'])); } } - // If it is the base class of the ipf record definition + // If it is the base class of the IPF_ORM record definition else if (isset($definition['is_base_class']) && $definition['is_base_class']) { // If it is a part of a package then we need to put it in a package subfolder if (isset($definition['is_package']) && $definition['is_package']) { diff --git a/ipf/orm/import/schema.php b/ipf/orm/import/schema.php index b8c64aa..e44ac1c 100644 --- a/ipf/orm/import/schema.php +++ b/ipf/orm/import/schema.php @@ -72,12 +72,12 @@ class IPF_ORM_Import_Schema 'keyValue')); protected $_validators = array(); + public function getValidators() { if (empty($this->_validators)) { $this->_validators = IPF_ORM_Utils::getValidators(); } - return $this->_validators; } @@ -142,12 +142,13 @@ class IPF_ORM_Import_Schema $builder->setOptions($this->getOptions()); $array = $this->buildSchema($schema, $format); - + foreach ($array as $name => $definition) { + if ( ! empty($models) && !in_array($definition['className'], $models)) { continue; } - print " $name\n"; + print " $name\n"; $builder->buildRecord($definition); } } @@ -338,6 +339,8 @@ class IPF_ORM_Import_Schema $moves = array('columns' => array()); foreach ($array as $className => $definition) { + if (!isset($definition['className'])) + continue; $parent = $this->_findBaseSuperClass($array, $definition['className']); // Move any definitions on the schema to the parent if (isset($definition['inheritance']['extends']) && isset($definition['inheritance']['type']) && ($definition['inheritance']['type'] == 'simple' || $definition['inheritance']['type'] == 'column_aggregation')) { @@ -401,7 +404,7 @@ class IPF_ORM_Import_Schema foreach ($relations as $alias => $relation) { $class = isset($relation['class']) ? $relation['class']:$alias; - if ( ! isset($array[$class])) { + if (!isset($array[$class])) { continue; } $relation['class'] = $class; @@ -444,6 +447,7 @@ class IPF_ORM_Import_Schema // Make sure we do not have any duplicate relations $this->_fixDuplicateRelations(); + //$array['relations']; // Set the full array of relationships for each class to the final array foreach ($this->_relations as $className => $relations) { $array[$className]['relations'] = $relations; @@ -531,7 +535,6 @@ class IPF_ORM_Import_Schema } $validation = array_flip($validation); - foreach ($element as $key => $value) { if ( ! isset($validation[$value])) { throw new IPF_ORM_Exception(sprintf('Invalid schema element named "' . $value . '" -- 2.49.0