Exemplo n.º 1
0
 protected function formatErrorBody($code, $message, $body, $backtrace = array(), $log = array())
 {
     $baseline = CorePlugin::getBaseline();
     if ($message === null) {
         if (isset(self::$messagecode[$code])) {
             $message = self::$messagecode[$code];
         } else {
             $message = "Error #{$code}";
         }
     }
     if (!DEBUG) {
         $body = "";
         $backtrace = array();
     }
     if (Template::findTemplate(ERROR_TEMPLATE) && !IS_CLI) {
         $tpt = new TemplateRes(array("code" => $code, "message" => $message, "body" => $body, "backtrace" => $backtrace, "baseline" => $baseline, "log" => $log));
         header("Content-type: text/html");
         $tpt->output(ERROR_TEMPLATE);
     }
     header("Content-type: text/plain");
     $body = "{$message} ({$code})\n{$body}";
     if (is_array($backtrace) && count($backtrace) > 0) {
         $body .= "\n\nBacktrace:\n";
         foreach ($backtrace as $n => $bt) {
             $body .= "#{$n}" . " {$bt[0]} ({$bt[1]}):\n" . (isset($bt[2]) ? $bt[2] . '->' : '') . (isset($bt[3]) ? $bt[3] . '(' . implode(', ', $bt[4]) . ')' : '') . "\n";
         }
     }
     $body .= "\n---\n" . $baseline . "\n";
     echo $body;
     Output::finish($code);
 }
Exemplo n.º 2
0
 public function testParsing()
 {
     $tpt = new Template(array("myvar" => "456"));
     $data = $tpt->parse("test.php");
     $this->assertEquals(trim($data), 'test 123 456');
 }
Exemplo n.º 3
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);
             }
         }
     }
 }