示例#1
0
文件: Cli.class.php 项目: davbfr/cf
 public static function jconfig()
 {
     self::enableHelp();
     $conf = Config::getInstance();
     $data = $conf->getData();
     $p = 0;
     if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
         $p = JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
     }
     self::pln(json_encode($data, $p));
 }
示例#2
0
文件: Model.class.php 项目: davbfr/cf
 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);
     }
 }
示例#3
0
文件: Crud.class.php 项目: davbfr/cf
 public static function create()
 {
     $create_tpt = Cli::addSwitch("t", "Create templates");
     $models = Cli::getInputs("models", "Model names to create");
     Cli::enableHelp();
     $config = Config::getInstance();
     $rest = Plugins::get(Plugins::APP_NAME)->getDir() . DIRECTORY_SEPARATOR . self::REQUEST_DIR;
     System::ensureDir($rest);
     $ctrl = WWW_DIR . "/app/crud";
     System::ensureDir($ctrl);
     foreach ($models as $model) {
         $className = ucfirst($model) . "Rest";
         $modelClass = ucfirst($model) . "Model";
         Cli::pinfo(" * " . $className);
         $filename = $rest . "/" . $className . ".class.php";
         $tpt = new Template(array("className" => $className, "model" => $model, "umodel" => ucfirst($model), "modelClass" => $modelClass));
         if (!file_exists($filename)) {
             $f = fopen($filename, "w");
             fwrite($f, $tpt->parse("crud-rest-skel.php"));
             fclose($f);
         }
         $filename = $ctrl . "/" . $className . ".js";
         if (!file_exists($filename)) {
             $f = fopen($filename, "w");
             fwrite($f, $tpt->parse("crud-app-skel.php"));
             fclose($f);
         }
         if ($create_tpt) {
             $templates = Plugins::get(Plugins::APP_NAME)->getDir() . DIRECTORY_SEPARATOR . Template::TEMPLATES_DIR;
             System::ensureDir($templates);
             $afields = $config->get("model." . $model);
             $fields = array();
             foreach ($afields as $name => $prop) {
                 $fields[$name] = new ModelField($model, $name, $prop);
             }
             $options = self::defaultOptions();
             $tpt = new Template(array_merge($options, array("model" => $fields)));
             $filename = $templates . "/" . $model . "-crud-list.php";
             if (!file_exists($filename)) {
                 $f = fopen($filename, "w");
                 fwrite($f, $tpt->parse($options["list_partial"]));
                 fclose($f);
             }
             $filename = $templates . "/" . $model . "-crud-detail.php";
             if (!file_exists($filename)) {
                 $f = fopen($filename, "w");
                 fwrite($f, $tpt->parse($options["detail_partial"]));
                 fclose($f);
             }
         }
     }
 }
示例#4
0
文件: Core.plugin.php 项目: davbfr/cf
 public static function bootstrap()
 {
     ErrorHandler::Init(__NAMESPACE__ . "\\ErrorHandler");
     self::loadConfig();
     if (array_key_exists("PATH_INFO", $_SERVER) && $_SERVER["PATH_INFO"]) {
         Rest::handle();
     }
     $conf = Config::getInstance();
     $tpt = new TemplateRes(array("title" => $conf->get("title", "CF " . CF_VERSION), "description" => $conf->get("description", null), "favicon" => $conf->get("favicon", null)));
     foreach (Plugins::dispatchAll("index", $tpt) as $index) {
         if ($index !== null) {
             $tpt->output($index);
         }
     }
     return $tpt;
 }