public static function createClassesFromConfig() { $bdd = Bdd::getInstance(); $config = Config::getInstance(); if (!is_dir(BddPlugin::MODEL_DIR)) { @mkdir(BddPlugin::MODEL_DIR, 0744, true); } if (!is_dir(BddPlugin::BASE_MODEL_DIR)) { @mkdir(BddPlugin::BASE_MODEL_DIR, 0744, true); } foreach ($config->get("model", array()) as $table => $columns) { $baseClassName = "Base" . ucfirst($table) . "Model"; $filename = BddPlugin::BASE_MODEL_DIR . "/" . $baseClassName . ".class.php"; Cli::pinfo(" * {$baseClassName}"); $f = fopen($filename, "w"); fwrite($f, "<?php namespace " . __NAMESPACE__ . ";\n\nabstract class {$baseClassName} extends Model {\n\tconst TABLE = " . ArrayWriter::quote($bdd->updateTableName($table)) . ";\n"); $new_columns = array(); $new_names = array(); foreach ($columns as $name => $params) { if (substr($name, 0, 2) == "__" && substr($name, strlen($name) - 2) == "__") { continue; } list($_name, $params) = $bdd->updateModelField($name, $params); $new_columns[$_name] = $params; $new_names[$_name] = $name; } $colstr = ArrayWriter::toString($new_columns, 4); foreach ($new_columns as $name => $params) { fwrite($f, "\tconst " . strtoupper($new_names[$name]) . " = " . ArrayWriter::quote($name) . "; // " . (array_key_exists("type", $params) ? $params["type"] : ModelField::TYPE_AUTO) . "\n"); $colstr = str_replace(ArrayWriter::quote($name), "self::" . strtoupper($new_names[$name]), $colstr); } fwrite($f, "\n\n\tprotected function getTable() {\n"); fwrite($f, "\t\treturn array(\n"); fwrite($f, "\t\t\tself::TABLE,\n"); fwrite($f, "\t\t\t" . $colstr . ",\n"); fwrite($f, "\t\t);\n\t}\n"); fwrite($f, "\n}\n"); fclose($f); $className = ucfirst($table) . "Model"; $filename = BddPlugin::MODEL_DIR . "/" . $className . ".class.php"; if (file_exists($filename)) { continue; } if (array_key_exists("__baseClassName__", $columns)) { $baseClassName = $columns["__baseClassName__"]; } Cli::pinfo(" * {$className}"); $f = fopen($filename, "w"); fwrite($f, "<?php namespace " . __NAMESPACE__ . ";\n\nclass {$className} extends {$baseClassName} {\n\n}\n"); fclose($f); } }
public static function loadConfig() { $conf = Config::getInstance(); $memcache = new MemCache(); if (array_key_exists("JCONFIG_FILE", $memcache)) { $conf->setData($memcache["JCONFIG_FILE"]); Logger::debug("Config loaded from cache"); foreach ($conf->get("plugins", array()) as $plugin) { Plugins::add($plugin); } } else { $cache = Cache::Priv(self::config, ".php"); if ($cache->check()) { if (file_exists(ROOT_DIR . "/composer.json")) { $conf->append(ROOT_DIR . "/composer.json", false, "composer"); } if (file_exists(CONFIG_DIR . "/config.json")) { $conf->append(CONFIG_DIR . "/config.json"); } if (file_exists(CONFIG_DIR . "/config.local.json")) { $conf->append(CONFIG_DIR . "/config.local.json"); } foreach (glob(CONFIG_DIR . "/*.json") as $file) { $bn = basename($file); if (substr($bn, 0, 7) != "config.") { $conf->append($file, false, substr($bn, 0, strlen($bn) - 5)); } } if (DEBUG && file_exists(CONFIG_DIR . "/config.debug.json")) { $conf->append(CONFIG_DIR . "/config.debug.json"); } $confsave = $conf->getData(); foreach ($conf->get("plugins", array()) as $plugin) { Plugins::add($plugin); } foreach (array_reverse(Plugins::findAll(self::config)) as $dirname) { if (file_exists($dirname . "/config.json")) { $conf->append($dirname . "/config.json"); } foreach (glob($dirname . "/*.json") as $file) { $bn = basename($file); if (substr($bn, 0, 7) != "config.") { $conf->append($file, false, substr($bn, 0, strlen($bn) - 5)); } } } Plugins::dispatchAllReversed("config", $conf); $conf->merge($confsave); ArrayWriter::toFile($conf->getData(), $cache->getFilename()); } else { $conf->setData(ArrayWriter::fromFile($cache->getFilename())); foreach ($conf->get("plugins", array()) as $plugin) { Plugins::add($plugin); } } $memcache["JCONFIG_FILE"] = $conf->getData(); } }