From: Andrey Kutejko Date: Mon, 9 Sep 2013 16:13:43 +0000 (+0300) Subject: always autodiscover application models. Use explicit list for ordering only. X-Git-Tag: 0.5~44 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=cb612996ba04adbde32a25b172b8ad61e74a01f3;p=ipf.git always autodiscover application models. Use explicit list for ordering only. --- diff --git a/ipf/application.php b/ipf/application.php index 47006cb..c5e8ad5 100644 --- a/ipf/application.php +++ b/ipf/application.php @@ -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()