コード例 #1
0
ファイル: web.php プロジェクト: map-framework/map
 /**
  * initialize application and load configs
  */
 public function __construct()
 {
     include_once self::AUTOLOAD;
     if (strtolower(ini_get('display_errors')) === 'off') {
         define('ENVIRONMENT', 'LIVE');
     } else {
         define('ENVIRONMENT', 'DEV');
     }
     if (!session_start()) {
         Logger::error('failed to start session');
         exit;
     }
     # load public & private config
     $this->config = (new Bucket())->applyIni(new File(self::CONFIG_PUBLIC))->applyIni(new File(self::CONFIG_PRIVATE));
     # load MAPUrl
     if (stripos($_SERVER['SERVER_PROTOCOL'], 'HTTPS') !== false) {
         $scheme = 'https';
     } else {
         $scheme = 'http';
     }
     $this->request = new MAPUrl($scheme . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], $this->config);
     Logger::debug('REQUEST (' . 'mode: `' . $this->request->getMode() . '` ' . 'area: `' . $this->request->getArea() . '` ' . 'page: `' . $this->request->getPage() . '`');
     # load area & page config
     $configPathList = array('private/src/area/' . $this->request->getArea() . '/config/area.ini', 'private/src/area/' . $this->request->getArea() . '/config/page/' . $this->request->getPage() . '.ini');
     foreach ($configPathList as $configPath) {
         $configFile = new File($configPath);
         if (!$configFile->isFile()) {
             if (constant('ENVIRONMENT') === 'DEV') {
                 Logger::info('config-file `' . $configFile . '` not found');
             }
             continue;
         }
         $this->config->applyIni($configFile);
     }
     # load session config
     if (!isset($_SESSION['config'])) {
         $_SESSION['config'] = array();
     }
     $this->config->applyArray($_SESSION['config']);
 }