SHARE
TWEET

Untitled

a guest Jun 10th, 2011 157 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. define('SEDIR', dirname(__FILE__));
  4.  
  5. class SE {
  6.     public static $config=null, $app=null;
  7.    
  8.     public static $service, $output;
  9.    
  10.     private static $stime;
  11.    
  12.     public static function startApp () {
  13.         if(self::$config == null) throw new SEException('Application config must be specified.');
  14.        
  15.         self::preload();
  16.        
  17.         self::$stime  = microtime(true);
  18.         self::$output = '';
  19.         self::resolveUrl();
  20.        
  21.         self::$app = new SE::$service['id'];
  22.         self::$app->execute();
  23.     }
  24.    
  25.     private static function preload () {
  26.         if(!is_dir(APP_DIR.'/preload')) return false;
  27.        
  28.         foreach(glob(APP_DIR.'/preload/*.php') as $file) {
  29.             require_once $file;
  30.         }
  31.     }
  32.    
  33.     public static function resolveUrl () {
  34.         $http = $_SERVER['HTTPS']? 'https://': 'http://';
  35.         $host = $_SERVER['HTTP_HOST'];
  36.         $request = $http.$host.$_SERVER['REQUEST_URI'];
  37.         $conf = self::$config['app']['baseUrl'].(strstr($request, self::$config['app']['scriptName'])? self::$config['app']['scriptName']: '');
  38.         $request = trim(str_replace($conf, '', $request), '/');
  39.        
  40.         $p = explode('?', $request);
  41.         $tservice = $p[0];
  42.         $params  = isset($p[1])? $p[1]: null;
  43.        
  44.         if($params !== null) {
  45.             parse_str($params, $_GET);
  46.             foreach($_GET as $k=>$v) $_GET['__rev'][] = $k;
  47.         }
  48.        
  49.         $service = strstr($tservice, '.', true)?
  50.                    strstr($tservice, '.', true):
  51.                    $tservice;
  52.         $action = strstr($tservice, '.')?
  53.                   str_replace('.', '', strstr($tservice, '.')):
  54.                   'main';
  55.         $action = $action==''?'main':$action;
  56.        
  57.         self::$service = empty($request)?
  58.                          array('id'=>'mainService','action'=>'mainAction'):
  59.                          array('id'=>$service.'Service','action'=>$action.'Action');
  60.     }
  61.    
  62.     public static function addToResponse ($str, $before=false) {
  63.         self::$output = $before? $str.self::$output: self::$output.$str;
  64.     }
  65.    
  66.     public static function addHeader ($str) {
  67.         header($str);
  68.     }
  69.    
  70.     public static function autoload ($class) {
  71.         if(strstr($class, 'Service')) $path = '/services';
  72.         elseif(strstr($class, 'Module')) $path = '/modules';
  73.         elseif(strstr($class, 'Component')) $path = '/components';
  74.         elseif(strstr($class, 'Resource')) $path = '/resources';
  75.         elseif(strstr($class, 'Model')) $path = '/models';
  76.         else $path = '/modules';
  77.        
  78.         if(is_file(APP_DIR.$path.'/'.$class.'.php')) require APP_DIR.$path.'/'.$class.'.php';
  79.         elseif(is_file(SEDIR.$path.'/'.$class.'.php')) require SEDIR.$path.'/'.$class.'.php';
  80.         else throw new SEException('Class "'.$class.'" not found.');
  81.     }
  82.    
  83.     public static function getExecTime () {
  84.         return microtime(true) - self::$stime;
  85.     }
  86. }
  87.  
  88. class SEException extends Exception {}
  89.  
  90. spl_autoload_register('SE::autoload');
  91.  
  92. interface iResource {
  93.     public function configure ();
  94. }
  95.  
  96. require_once 'service.php';
  97. require_once 'component.php';
  98. require_once 'resource.php';
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top