Advertisement
Neo-Craft

Application

Mar 9th, 2012
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.11 KB | None | 0 0
  1. <?php
  2. class Application {
  3.  
  4.     /** @var Database_Adapter **/
  5.     public $db = NULL;
  6.  
  7.     /** @var Cache **/
  8.     public static $cache = NULL;
  9.  
  10.     /** @var Request **/
  11.     public $request = NULL;
  12.  
  13.     /** @var array **/
  14.     public $params = array();
  15.  
  16.    public $begin_mem, $begin_time, $end_mem, $end_time;
  17.  
  18.     /**
  19.     * @return Cache
  20.     **/
  21.     public static function cache()
  22.     {
  23.         return self::$cache;
  24.     }
  25.  
  26.     /**
  27.      * Initier l'application.
  28.      * @throws Exception
  29.      * @param array $conf
  30.      * @return bool
  31.      */
  32.     public function init()
  33.     {
  34.         global $application;
  35.         $config = new Config();
  36.     $application->begin_time = $application->microtime_float();
  37.     $application->begin_mem = memory_get_usage();
  38.         $this->ConnectDatabase();
  39.         self::$cache = new Cache;
  40.         self::$cache->init();
  41.     //  User::init();
  42.     //  set_exception_handler(array('Error', 'handle'));
  43.         //self::$request = Request::instance();
  44.         return TRUE;
  45.     }
  46.  
  47.     private function ConnectDatabase(){
  48.         global $database;
  49.         $database->getPDO();
  50.     }
  51.  
  52.     /** @return null **/
  53.     public function run()
  54.     {
  55.         global $application;
  56.         Router::init();
  57.         //self::$request->init();
  58.         ob_start();
  59.         Router::dispatch();
  60.         $content = ob_get_clean();
  61.         $application->end_time = $application->microtime_float();
  62.         $application->end_mem = memory_get_usage();
  63.         include_once ROOT.'layouts/ocean.php';
  64.     }
  65.  
  66.     protected function convert($size)
  67.     {
  68.         $unit=array('B','Kb','Mb','Gb','Tb','Pb');
  69.         return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
  70.     }
  71.  
  72.     /** @return string **/
  73.  
  74.         function microtime_float() {
  75.             list($usec, $sec) = explode(" ", microtime());
  76.             return ((float)$usec + (float)$sec);
  77.         }
  78.  
  79.     public  function stats()
  80.     {
  81.             global $application;
  82.             $time = round($application->end_time - $application->begin_time, 4);
  83.             $mem = $application->convert($application->end_mem);
  84.         return "Page généré en $time s, $mem de mémoire utilisé.";
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement