File indexing completed on 2024-12-22 05:33:09
0001 <?php 0002 0003 /** 0004 * ocs-fileserver 0005 * 0006 * Copyright 2016 by pling GmbH. 0007 * 0008 * This file is part of ocs-fileserver. 0009 * 0010 * ocs-fileserver is free software: you can redistribute it and/or modify 0011 * it under the terms of the GNU Affero General Public License as published by 0012 * the Free Software Foundation, either version 3 of the License, or 0013 * (at your option) any later version. 0014 * 0015 * ocs-fileserver is distributed in the hope that it will be useful, 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 * GNU Affero General Public License for more details. 0019 * 0020 * You should have received a copy of the GNU Affero General Public License 0021 * along with Foobar. If not, see <http://www.gnu.org/licenses/>. 0022 **/ 0023 0024 class Bootstrap extends Flooer_Application_Bootstrap 0025 { 0026 0027 public function initAppConfig() 0028 { 0029 $this->getApplication()->setResource( 0030 'appConfig', 0031 (object) parse_ini_file('configs/application.ini', true) 0032 ); 0033 } 0034 0035 public function initDispatch() 0036 { 0037 parent::initDispatch(); 0038 require_once 'controllers/BaseController.php'; 0039 $dispatch = $this->getApplication()->getResource('dispatch'); 0040 $dispatch->setErrorController('ErrorController'); // Workaround for PHP7 0041 $dispatch->setLimitMethod(false); 0042 $dispatch->setRenderErrorPage(false); 0043 $dispatch->setViewFileSuffix('.xml'); 0044 } 0045 0046 public function initRequest() 0047 { 0048 parent::initRequest(); 0049 $request = $this->getApplication()->getResource('request'); 0050 $request->mapUri(); 0051 } 0052 0053 public function initResponse() 0054 { 0055 parent::initResponse(); 0056 $response = $this->getApplication()->getResource('response'); 0057 $appConfig = $this->getApplication()->getResource('appConfig'); 0058 $response->setHeader( 0059 'Access-Control-Allow-Origin', 0060 $appConfig->security['accessControlAllowOrigin'] 0061 ); 0062 $response->setHeader( 0063 'Access-Control-Allow-Credentials', 0064 $appConfig->security['accessControlAllowCredentials'] 0065 ); 0066 $response->setHeader( 0067 'Access-Control-Allow-Methods', 0068 $appConfig->security['accessControlAllowMethods'] 0069 ); 0070 $response->setHeader( 0071 'Access-Control-Allow-Headers', 0072 $appConfig->security['accessControlAllowHeaders'] 0073 ); 0074 $response->setHeader( 0075 'Access-Control-Max-Age', 0076 time() + 60 * 60 * 24 * $appConfig->security['accessControlMaxAge'] 0077 ); 0078 } 0079 0080 public function initCookie() 0081 { 0082 // Do not init 0083 } 0084 0085 public function initSession() 0086 { 0087 // Do not init 0088 } 0089 0090 public function initGettext() 0091 { 0092 // Do not init 0093 } 0094 0095 public function initLog() 0096 { 0097 parent::initLog(); 0098 $log = $this->getApplication()->getResource('log'); 0099 $appConfig = $this->getApplication()->getResource('appConfig'); 0100 $log->setFile($appConfig->log['file']); 0101 $log->setMail($appConfig->log['mail']); 0102 } 0103 0104 public function initDb() 0105 { 0106 try { 0107 $db = new Flooer_Db(parse_ini_file('configs/database.ini', true)); 0108 $this->getApplication()->setResource('db', $db); 0109 } 0110 catch (Exception $exception) { 0111 $response = $this->getApplication()->getResource('response'); 0112 $log = $this->getApplication()->getResource('log'); 0113 $log->log($exception->getMessage(), LOG_ALERT); 0114 $response->setStatus(500); 0115 $response->setHeader('Content-Type', 'text/plain'); 0116 $response->setBody('Internal server error'); 0117 $response->send(); 0118 exit; 0119 } 0120 } 0121 0122 public function initModels() 0123 { 0124 require_once 'models/BaseModel.php'; 0125 require_once 'models/ModelContainer.php'; 0126 /** @var Flooer_Db $db */ 0127 $db = $this->getApplication()->getResource('db'); 0128 $models = new ModelContainer($db, parse_ini_file('configs/models.ini', true)); 0129 $this->getApplication()->setResource('models', $models); 0130 0131 require_once 'models/OcsModel.php'; 0132 // $db2 = $this->getApplication()->getResource('db_ocs'); 0133 $dbConfig = parse_ini_file('configs/database.ini', true); 0134 $modelOcs = new OcsModel($db, $dbConfig); 0135 $this->getApplication()->setResource('modelOcs', $modelOcs); 0136 } 0137 0138 public function initRedisCache() 0139 { 0140 $appConfig = $this->getApplication()->getResource('appConfig'); 0141 $config = $appConfig->redis; 0142 $redisCache = null; 0143 if (boolval($config['enabled'])) { 0144 $redisCache = new RedisCache($config); 0145 } 0146 $this->getApplication()->setResource('redisCache', $redisCache); 0147 } 0148 0149 }