]> git.andy128k.dev Git - ipf.git/commitdiff
always autodiscover application models. Use explicit list for ordering only.
authorAndrey Kutejko <andy128k@gmail.com>
Mon, 9 Sep 2013 16:13:43 +0000 (19:13 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Mon, 9 Sep 2013 16:13:43 +0000 (19:13 +0300)
ipf/application.php

index 47006cbf62018c3a4623da791594dee1c20043dc..c5e8ad5c2f3d44f3e4e9d74aa501ba0ade412d8f 100644 (file)
@@ -12,25 +12,29 @@ abstract class IPF_Application
         $root = (strpos($this->name,'IPF_') === 0) ? IPF::get('ipf_path') : IPF::get('project_path');
         $this->path = $root.DIRECTORY_SEPARATOR.strtolower(str_replace('_',DIRECTORY_SEPARATOR,$this->name)).DIRECTORY_SEPARATOR;
 
-        if (array_key_exists('models',$data)) {
-            foreach ($data['models'] as &$modelname) {
-                if (!IPF_Utils::isValidName($modelname))
-                    throw new IPF_Exception_Panic("Model name \"$modelname\" is incorrect");
-                $this->models[] = $modelname;
-            }
-        } else {
-            try {
-                $it = new DirectoryIterator($this->path.DIRECTORY_SEPARATOR.'models');
-                foreach ($it as $file) {
-                    $e = explode('.', $file->getFileName(), 2);
-                    if (count($e) == 2 && $e[1] === 'php') {
-                        $this->models[] = $e[0];
-                    }
+        $models = array();
+        try {
+            $it = new DirectoryIterator($this->path.DIRECTORY_SEPARATOR.'models');
+            foreach ($it as $file) {
+                $e = explode('.', $file->getFileName(), 2);
+                if (count($e) == 2 && $e[1] === 'php') {
+                    $models[] = $e[0];
                 }
-            } catch(RuntimeException $e) {
-                // nothing to do
             }
+        } catch (RuntimeException $e) {
+            // nothing to do
         }
+
+        // reorder models according to a given parameter
+        if (array_key_exists('models', $data)) {
+            foreach ($data['models'] as $modelname) {
+                if (!in_array($modelname, $models))
+                    throw new IPF_Exception_Panic("Model \"$modelname\" does not exist.");
+            }
+            $models = array_merge($data['models'], array_diff($models, $data['models']));
+        }
+
+        $this->models = $models;
     }
 
     public function modelList()