コード例 #1
0
 public static function run_command()
 {
     $command = static::$command;
     $method = static::$method;
     // Let's see if the command file exists.
     $path = SYS . 'cli/commands/' . $command . '.' . EXT;
     if (!File::exists($path, false)) {
         throw new CLIException('Unable to load file.');
     }
     // Let's include the file.
     require_once $path;
     // Let's check if the class exists.
     $_command = "CLI\\Command\\" . ucfirst($command);
     if (!class_exists($_command)) {
         throw new CLIException('Class ' . $_command . ' doesn\'t exists.');
     }
     // Let's create a new instance of the command object.
     $task = new $_command();
     // Let's check if the method is callable.
     if (!is_callable(array($task, $method))) {
         throw new CLIException('Unable to call ' . $method . ' in ' . $command);
     }
     // Let's call the method and by that finally run the command.
     $output = $task->{$method}(static::$arguments, static::$options);
     // If there was a returned value print it.
     if (!empty($output)) {
         echo $output . PHP_EOL;
     }
 }
コード例 #2
0
 public static function render()
 {
     static::$memory = new \stdClass();
     static::$memory->time = number_format((microtime(true) - START_TIME) * 1000, 2) . ' ms';
     static::$memory->usage = File::get_file_size(memory_get_usage(true));
     try {
         $output = File::get(COMPONENTS . 'profiler/profiler.html', true);
     } catch (Execption $e) {
         die($e->getMessage());
     }
     $_queries = '';
     $_checkpoints = '';
     if (static::$log_query) {
         // Log queries
         if (!empty(static::$queries)) {
             foreach (static::$queries as $query) {
                 $_queries .= '<section><aside><span>' . $query->time . ' ms.</span></aside><article>' . $query->query . '</article><div class="fluorine_profiler_clearfix"></div></section>';
             }
         } else {
             $_queries .= '<section class="fluorine_profiler_tab_none"><i>None</i></section>';
         }
     } else {
         $_queries .= '<section class="fluorine_profiler_tab_none"><i>Not logged</i></section>';
     }
     if (!empty(static::$checkpoints)) {
         foreach (static::$checkpoints as $cpoint) {
             $_checkpoints .= '<section><aside><span>' . $cpoint->type . '</span></aside><article>' . $cpoint->msg . '</article><div class="fluorine_profiler_clearfix"></div></section>';
         }
     } else {
         $_checkpoints .= '<section class="fluorine_profiler_tab_none"><i>None</i></section>';
     }
     $replacing = array('{queries}' => $_queries, '{checkpoints}' => $_checkpoints, '{memUsage}' => static::$memory->usage, '{totalTime}' => static::$memory->time);
     $output = strtr($output, $replacing);
     return $output;
 }
コード例 #3
0
 public static function init()
 {
     try {
         File::get(COMPONENTS . 'request/headers.' . EXT);
     } catch (Exception $e) {
         die($e->getMessage());
     }
     static::$header = Request\Header::newInstance();
 }
コード例 #4
0
 public static function load()
 {
     static::loadFromAppFile();
     foreach (static::$files as $path) {
         try {
             File::get($path);
         } catch (Exception $e) {
             die($e->getMessage());
         }
     }
 }
コード例 #5
0
 public static function error($code)
 {
     static::$header->set($code, '');
     $file = null;
     try {
         $file = File::get(APP . 'view/errors/' . $code . '.php', true);
     } catch (Exception $e) {
         die($e->getMessage());
     }
     echo $file;
     exit;
 }
コード例 #6
0
ファイル: load.php プロジェクト: fluorine-framework/framework
 public static function model($className)
 {
     // If class name of the requested model is empty, shout it for the programmer!
     if (empty($className)) {
         die("Failed to load model with no name!");
     }
     try {
         File::get(APP . 'model/' . strtolower($className) . '.php');
     } catch (Exception $e) {
         die('Error while trying to load ' . $className . ' model.<br />' . $e->getMessage());
     }
     $name = 'Model\\' . $className;
     return new $name();
 }
コード例 #7
0
 /**
  * Outputs the content by finding the correct template
  * and view file, if needed.
  */
 public function getContent()
 {
     $tplDir = $this->isView ? $this->view->tpl : Config::$template;
     $config = array('base_url' => null, 'tpl_dir' => array(APP . 'template/' . $tplDir . '/'), 'cache_dir' => APP . 'tmp/', 'debug' => true, 'php_enabled' => true, 'tpl_ext' => 'php');
     Tpl::configure($config);
     $tpl = new Tpl();
     $tpl->assign('isView', $this->isView);
     $tpl->assign('title', Config::$data->title);
     if ($this->isView) {
         $vars = $this->view->getVars();
         if (!empty($vars)) {
             foreach ($vars as $key => $value) {
                 $tpl->assign($key, $value);
             }
         }
         $sep = DIRECTORY_SEPARATOR;
         $view = '..' . $sep . '..' . $sep . APP . 'view/' . $this->view->path;
     } else {
         $view = $this->view;
         if ($this->isJson === true) {
             echo $view;
             exit;
         }
     }
     try {
         File::get(APP . 'template/' . $tplDir . '/template.php');
         if (class_exists('Template\\Model\\Template')) {
             $tpl_class = new Template\Model\Template();
             $tpl->assign('template', $tpl_class);
         }
     } catch (Exception $e) {
     }
     $tpl->assign('view', $view);
     $tpl->draw('index');
 }
コード例 #8
0
 /**
  * Gets the template file, modify it and put it in position.
  * @param 	$template 	The path to the template file.
  * @param 	$path 		The path to the final file.
  * @return 	void
  */
 private function makeFile($template, $path)
 {
     try {
         $file = File::get(SYS . 'cli/commands/' . $template, true);
     } catch (\Exception $e) {
         die('Unable to get template file.');
     }
     // Run replace sequence.
     $data = $this->replace($file);
     // If path contains slash, check if folder exists otherwise
     // create the needed folders.
     if (strpos($path, '/') !== false) {
         $folders = explode('/', $path);
         $count = count($folders);
         $_path = $folders[0];
         unset($folders[$count - 1]);
         for ($i = 0; $i <= $count; $i++) {
             if (!is_dir($_path)) {
                 mkdir($_path, 0777);
             }
             if (isset($folders[$i + 1])) {
                 $_path .= '/' . $folders[$i + 1];
             }
         }
     }
     file_put_contents($path, $data);
 }