public static function initialize()
 {
     // resolve details from host name
     // get site ID
     /*
     		if(empty(static::$ID))
     		{
     			if(!empty($_SERVER['SITE_ID']))
     				static::$ID = $_SERVER['SITE_ID'];
     			else
     				throw new Exception('No Site ID detected');
     		}
     */
     // get site root
     if (empty(static::$rootPath)) {
         if (!empty($_SERVER['SITE_ROOT'])) {
             static::$rootPath = $_SERVER['SITE_ROOT'];
         } else {
             throw new Exception('No Site root detected');
         }
     }
     // retrieve static configuration
     if (!(static::$_config = apc_fetch($_SERVER['HTTP_HOST'])) || $_GET['_recache'] == static::$controlKey) {
         static::$_config = static::_compileConfiguration();
         apc_store($_SERVER['HTTP_HOST'], static::$_config);
     }
     // get host-specific config
     if (!(static::$_hostConfig = static::$_config['hosts'][$_SERVER['HTTP_HOST']])) {
         throw new Exception('Current host is unknown');
     }
     if (static::$_hostConfig['ParentHostname']) {
         if (!(static::$_parentHostConfig = static::$_config['hosts'][static::$_hostConfig['ParentHostname']])) {
             throw new Exception('Parent host is unknown');
         }
     }
     // get request URI
     if (empty(static::$requestURI)) {
         static::$requestURI = parse_url($_SERVER['REQUEST_URI']);
     }
     // get path stack
     static::$pathStack = static::$requestPath = static::splitPath(static::$requestURI['path']);
     // register class loader
     spl_autoload_register('Site::loadClass');
     // set error handle
     set_error_handler('Site::handleError');
     // register exception handler
     set_exception_handler('Site::handleException');
     // check virtual system for site config
     static::loadConfig(__CLASS__);
     if (is_callable(static::$onInitialized)) {
         call_user_func(static::$onInitialized);
     }
 }
示例#2
0
 public static function initialize($rootPath, $hostname = null)
 {
     static::$initializeTime = microtime(true);
     // get site root
     if ($rootPath) {
         static::$rootPath = $rootPath;
     } elseif (!static::$rootPath) {
         throw new Exception('No site root detected');
     }
     // load config
     if (!(static::$_config = apc_fetch(static::$rootPath))) {
         if (is_readable(static::$rootPath . '/site.json')) {
             static::$_config = json_decode(file_get_contents(static::$rootPath . '/site.json'), true);
             apc_store(static::$rootPath, static::$_config);
         } elseif (is_readable(static::$rootPath . '/Site.config.php')) {
             include static::$rootPath . '/Site.config.php';
             apc_store(static::$rootPath, static::$_config);
         }
     }
     static::$config = static::$_config;
     // TODO: deprecate
     // get hostname
     if ($hostname) {
         static::$hostname = $hostname;
     } elseif (!static::$hostname) {
         if (!empty(static::$config['primary_hostname'])) {
             static::$hostname = static::$config['primary_hostname'];
         } else {
             throw new Exception('No hostname detected');
         }
     }
     // get path stack
     if (!empty($_SERVER['REQUEST_URI'])) {
         $path = $_SERVER['REQUEST_URI'];
         if (false !== ($qPos = strpos($path, '?'))) {
             $path = substr($path, 0, $qPos);
         }
         static::$pathStack = static::$requestPath = static::splitPath($path);
     }
     // set useful transaction name for newrelic
     if (extension_loaded('newrelic')) {
         newrelic_name_transaction(static::getConfig('handle') . '/' . implode('/', site::$requestPath));
     }
     // register class loader
     spl_autoload_register('Site::loadClass');
     // set error handle
     set_error_handler('Site::handleError');
     // register exception handler
     set_exception_handler('Site::handleException');
     // check virtual system for site config
     static::loadConfig(__CLASS__);
     // get site title
     if (!static::$title) {
         static::$title = static::getConfig('label');
     }
     // configure error display
     ini_set('display_errors', static::$debug);
     // check virtual system for proxy config
     if (class_exists('HttpProxy')) {
         static::loadConfig('HttpProxy');
     }
     if (is_callable(static::$onInitialized)) {
         call_user_func(static::$onInitialized);
     }
 }
示例#3
0
 /**
  * Reset the class variables to null.
  */
 public static function reset()
 {
     static::$query = null;
     static::$post = null;
     static::$properties = null;
     static::$server = null;
     static::$cookies = null;
     static::$files = null;
     static::$headers = null;
     static::$method = null;
     static::$pathInfo = null;
     static::$requestUri = null;
     static::$requestPath = null;
     static::$basePath = null;
     static::$baseUrl = null;
 }