Exemplo n.º 1
0
 /**
  * Creates a new site:
  *   starts the timing clock (if enabled)
  *   creates the SiteLayout if not set
  *   sets up config
  */
 private function __construct()
 {
     if (isset(self::$TheSite)) {
         throw new RuntimeException('Site already set to ' . get_class(self::$TheSite));
     }
     self::$TheSite = $this;
     set_error_handler(array($this, 'dispatchError'), E_ALL | E_RECOVERABLE_ERROR);
     set_exception_handler(array($this, 'dispatchException'));
     $start = array(microtime(true), 'start');
     $this->timePoint('start');
     if (!isset($this->url)) {
         $this->url = dirname($_SERVER['PHP_SELF']);
         if ($this->url == '/') {
             $this->url = '';
         }
     }
     $proto = 'http';
     $port = '';
     if (isset($_SERVER['SERVER_PORT'])) {
         if ($_SERVER['SERVER_PORT'] == 443) {
             $proto = 'https';
         } elseif ($_SERVER['SERVER_PORT'] != 80) {
             $port = ':' . $_SERVER['SERVER_PORT'];
         }
     }
     $this->serverUrl = "{$proto}://" . $_SERVER['SERVER_NAME'] . $port;
     try {
         if (!isset($this->layout)) {
             $this->layout = new SiteLayout($this);
         }
         // The log starts off in an unconfigured state where it accumulates
         // messages until configuration is done and it's told what to do with
         // them; however if something goes wrong early on, it dumps all logged
         // messages
         $this->log = new SiteLog($this);
         $this->config = new SiteConfig($this);
         $this->config->addFile(Loader::$FrameworkPath . '/config.ini');
         new SiteModuleLoader($this);
         $this->dispatchCallback('onConfig', $this);
         $this->config->addFile(Loader::$LocalPath . '/config.ini');
         $this->config->addFile(Loader::$Base . '/siteconfig.ini');
         $this->config->compile();
         $this->dispatchCallback('onPostConfig', $this);
     } catch (SiteConfigParseException $ex) {
         $this->printErrorPage('Error loading onfiguration', "<h1>Error loading configuration:</h1>\n" . "<pre>" . $ex->getMessage() . "</pre>\n");
         exit(1);
     }
     $this->timing = $this->isDebugMode();
     if ($this->timing) {
         array_push($this->timePoints, $start);
     }
 }