Ejemplo n.º 1
0
 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);
             }
         }
     }
 }
Ejemplo n.º 2
0
 public function update()
 {
     if (Cli::getOption("a")) {
         $cf_dir = "\"" . realpath(CF_DIR) . "\"";
     } else {
         $cf_dir = "ROOT_DIR . \"/" . System::relativePath(System::absPath(ROOT_DIR), System::absPath(CF_DIR)) . "\"";
     }
     Cli::pinfo(" * Create paths.php");
     Logger::Debug("CF dir is {$cf_dir}");
     Logger::Debug("ROOT dir is " . ROOT_DIR);
     $content = "<?php // DO NOT MODIFY THIS FILE, IT IS GENERATED BY setup update SCRIPT\n\n";
     $content .= "@define(\"ROOT_DIR\", \"" . ROOT_DIR . "\");\n";
     $content .= "@define(\"CF_DIR\", {$cf_dir});\n";
     file_put_contents(CONFIG_DIR . "/paths.php", $content);
 }
Ejemplo n.º 3
0
 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);
     }
 }
Ejemplo n.º 4
0
 public static function runtests()
 {
     Cli::pinfo("Running tests");
     ErrorHandler::unregister();
     // Create Suite
     foreach (Plugins::get_plugins() as $name) {
         $result = new PHPUnit_Framework_TestResult();
         $listner = new self($name);
         $result->addListener($listner);
         $plugin = Plugins::get($name);
         $dir = $plugin->getDir() . DIRECTORY_SEPARATOR . self::TESTS_DIR;
         if (is_dir($dir)) {
             foreach (glob($dir . DIRECTORY_SEPARATOR . "*.test.php") as $file) {
                 require_once $file;
                 $testclassname = __NAMESPACE__ . "\\" . substr(basename($file), 0, -9) . "Test";
                 $suite = new PHPUnit_Framework_TestSuite(new ReflectionClass($testclassname));
                 $suite->run($result);
             }
         }
         if ($listner->dot) {
             Cli::pcolorln(Cli::ansiinfo, "]");
         }
     }
 }