]> git.andy128k.dev Git - ipf-legacy-orm.git/commitdiff
cleanup
authorAndrey Kutejko <andy128k@gmail.com>
Sun, 14 Jul 2013 09:37:21 +0000 (12:37 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Sun, 14 Jul 2013 09:37:21 +0000 (12:37 +0300)
ipf/orm.php
ipf/orm/export.php
ipf/orm/import/builder.php
ipf/orm/table.php

index bb5854ddb18e6f74b6f40dce804ff613cf16c939..78cc0cec98c3779e4d82c3989e8172c1ffdf8622 100644 (file)
@@ -177,8 +177,6 @@ final class IPF_ORM
     
     const BASE_CLASSES_DIRECTORY    = '_generated';
 
-    private static $_loadedModelFiles = array();
-
     private function __construct() {}
 
     public static function getTable($componentName)
@@ -207,80 +205,20 @@ final class IPF_ORM
         return $models;
     }
 
-    public static function createTablesFromModels($directory)
+    public static function createTablesFromModels($app)
     {
-        return IPF_ORM_Manager::connection()->export->exportSchema($directory);
+        IPF_ORM_Manager::connection()->export->exportClasses($app->modelList());
     }
-    
-    public static function generateSqlFromModels($directory = null)
+
+    public static function generateSqlFromModels($app)
     {
-        $sql = IPF_ORM_Manager::connection()->export->exportSql($directory);
+        $sql = IPF_ORM_Manager::connection()->export->exportSortedClassesSql($app->modelList(), false);
+
         $build = '';
         foreach ($sql as $query) {
             $build .= $query.";\n\n";
         }
         return $build;
-    }    
-    
-    public static function loadModel($className, $path = null)
-    {
-        self::$_loadedModelFiles[$className] = $path;
-    }
-
-    public static function filterInvalidModels($classes)
-    {
-        $validModels = array();
-        foreach ((array) $classes as $name) {
-            if (self::isValidModelClass($name) && ! in_array($name, $validModels)) {
-                $validModels[] = $name;
-            }
-        }
-
-        return $validModels;
-    }
-
-    public static function loadModels($directory, $modelLoading = null)
-    {
-        $loadedModels = array();
-        try{
-            $it = new DirectoryIterator($directory.DIRECTORY_SEPARATOR.IPF_ORM::BASE_CLASSES_DIRECTORY);
-        }catch(RuntimeException $e){
-            return $loadedModels;
-        }
-        foreach ($it as $file) {
-            $e = explode('.', $file->getFileName());
-            if (end($e) === 'php') {
-               $className = $e[0];
-               require_once($file->getPathName());
-            }
-        }
-        $it = new DirectoryIterator($directory);
-        foreach ($it as $file) {
-            $e = explode('.', $file->getFileName());
-            if (end($e) === 'php') {
-               $className = $e[0];
-               require_once($file->getPathName());
-               $loadedModels[$className] = $className;
-            }
-        }
-        return $loadedModels;
-    }
-
-
-    public static function isValidModelClass($class)
-    {
-        if ($class instanceof IPF_ORM_Record) {
-            $class = get_class($class);
-        }
-        if (is_string($class) && class_exists($class)) {
-            $class = new ReflectionClass($class);
-        }
-        if ($class instanceof ReflectionClass) {
-            if ( ! $class->isAbstract() && $class->isSubClassOf('IPF_ORM_Record')) {
-                return true;
-            }
-        }
-        return false;
     }
 
     public static function dump($var, $output = true, $indent = "")
@@ -311,3 +249,4 @@ final class IPF_ORM
         return implode("\n", $ret);
     }
 }
+
index 10db5f321d1f1453ad627421cccc8aa15b120c93..43b76ed947ff94d701bb586ad5c2ba2a552d5379 100644 (file)
@@ -128,15 +128,6 @@ class IPF_ORM_Export extends IPF_ORM_Connection_Module
         return $sql;
     }
 
-    public function createTable($name, array $fields, array $options = array())
-    {
-        $sql = (array) $this->createTableSql($name, $fields, $options);
-
-        foreach ($sql as $query) {
-            $this->conn->execute($query);
-        }
-    }
-
     public function createSequence($seqName, $start = 1, array $options = array())
     {
         return $this->conn->execute($this->createSequenceSql($seqName, $start = 1, $options));
@@ -443,16 +434,6 @@ class IPF_ORM_Export extends IPF_ORM_Connection_Module
         return '';
     }
 
-    public function exportSchema($directory = null)
-    {
-        if ($directory !== null) {
-            $models = IPF_ORM::filterInvalidModels(IPF_ORM::loadModels($directory));
-        } else {
-            $models = IPF_ORM::getLoadedModels();
-        }
-        $this->exportClasses($models);
-    }
-
     public function exportSortedClassesSql($classes, $groupByConnection = true)
     {
          $connections = array();
@@ -548,10 +529,8 @@ class IPF_ORM_Export extends IPF_ORM_Connection_Module
          }
      }
 
-    public function exportClassesSql(array $classes)
+    public function exportClassesSql(array $models)
     {
-        $models = IPF_ORM::filterInvalidModels($classes);
-        
         $sql = array();
         
         foreach ($models as $name) {
@@ -630,29 +609,5 @@ class IPF_ORM_Export extends IPF_ORM_Connection_Module
 
         return $sql;
     }
+}
 
-    public function exportSql($directory = null)
-    {
-        if ($directory !== null) {
-            $models = IPF_ORM::filterInvalidModels(IPF_ORM::loadModels($directory));
-        } else {
-            $models = IPF_ORM::getLoadedModels();
-        }
-        
-        return $this->exportSortedClassesSql($models, false);
-    }
-
-    public function exportTable(IPF_ORM_Table $table)
-    {
-        try {
-            $data = $table->getExportableFormat();
-
-            $this->conn->export->createTable($data['tableName'], $data['columns'], $data['options']);
-        } catch(IPF_ORM_Exception $e) {
-            // we only want to silence table already exists errors
-            if ($e->getPortableCode() !== IPF_ORM::ERR_ALREADY_EXISTS) {
-                throw $e;
-            }
-        }
-    }
-}
\ No newline at end of file
index 09330d2bf47e9c8994fc3ffe98a40f6d03885e74..dd9dfc32498d628758ae0aeb91ad809b3eaf5317 100644 (file)
@@ -452,8 +452,6 @@ class IPF_ORM_Import_Builder
         IPF_Utils::makeDirectories($targetPath);
         if (file_put_contents($writePath, implode(PHP_EOL, $code)) === false)
             throw new IPF_ORM_Exception("Couldn't write file " . $writePath);
-
-        IPF_ORM::loadModel($className, $writePath);
     }
 }
 
index d4e566e92958a99ab963d84f587073af66a47722..af399f6b49c3c73679087fed9032c0a655cd34c0 100644 (file)
@@ -326,11 +326,7 @@ class IPF_ORM_Table extends IPF_ORM_Configurable implements Countable
     public function getTemplates()
     {
         return $this->_templates;
-    }
 
-    public function export()
-    {
-        $this->_conn->export->exportTable($this);
     }
 
     public function getExportableFormat($parseForeignKeys = true)