]> git.andy128k.dev Git - ipf-legacy-orm.git/commitdiff
Import Scheme refactor
authoravl <alex.litovchenko@gmail.com>
Fri, 29 Aug 2008 02:41:00 +0000 (04:41 +0200)
committeravl <alex.litovchenko@gmail.com>
Fri, 29 Aug 2008 02:41:00 +0000 (04:41 +0200)
ipf/orm/import/builder.php
ipf/orm/import/schema.php

index 34d683faeab5fb535b50c6c038a26d9efb724692..2b996afdcd035ecf32ffe5b6a6306e9fc5a0f69f 100644 (file)
@@ -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']) {
index b8c64aaf88ad2250bfb4e895bbe22255bd453870..e44ac1c3a3df9da2bb0c35f356b52497b2caa3fb 100644 (file)
@@ -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 . '"