mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-03-21 07:41:53 -04:00
* error page: true HTML page * error page: http500 erorr * error page: add CSP header * 'log.txt' replaced by LOG_FILENAME * use ADMIN_LOG * log.txt => LOG_FILENAME * error message: add <title> * Docs created * delete: documentation on error message page * line break added * added: new line at the end * typo fixed * Update lib/lib_rss.php Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr> * Update lib/lib_rss.php Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr> * Minz HTTP 500 Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
135 lines
3.5 KiB
PHP
135 lines
3.5 KiB
PHP
<?php
|
|
# ***** BEGIN LICENSE BLOCK *****
|
|
# MINZ - a free PHP Framework like Zend Framework
|
|
# Copyright (C) 2011 Marien Fressinaud
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
# ***** END LICENSE BLOCK *****
|
|
|
|
/**
|
|
* The Minz_FrontController class is the framework Dispatcher.
|
|
* It runs the application.
|
|
* It is generally invoqued by an index.php file at the root.
|
|
*/
|
|
class Minz_FrontController {
|
|
protected $dispatcher;
|
|
|
|
/**
|
|
* Constructeur
|
|
* Initialise le dispatcher, met à jour la Request
|
|
*/
|
|
public function __construct () {
|
|
try {
|
|
$this->setReporting();
|
|
|
|
Minz_Request::init();
|
|
|
|
$url = $this->buildUrl();
|
|
$url['params'] = array_merge (
|
|
$url['params'],
|
|
$_POST
|
|
);
|
|
Minz_Request::forward ($url);
|
|
} catch (Minz_Exception $e) {
|
|
Minz_Log::error($e->getMessage());
|
|
self::killApp($e->getMessage());
|
|
}
|
|
|
|
$this->dispatcher = Minz_Dispatcher::getInstance();
|
|
}
|
|
|
|
/**
|
|
* Returns an array representing the URL as passed in the address bar
|
|
* @return array URL representation
|
|
*/
|
|
private function buildUrl() {
|
|
$url = array();
|
|
|
|
$url['c'] = $_GET['c'] ?? Minz_Request::defaultControllerName();
|
|
$url['a'] = $_GET['a'] ?? Minz_Request::defaultActionName();
|
|
$url['params'] = $_GET;
|
|
|
|
// post-traitement
|
|
unset($url['params']['c']);
|
|
unset($url['params']['a']);
|
|
|
|
return $url;
|
|
}
|
|
|
|
/**
|
|
* Démarre l'application (lance le dispatcher et renvoie la réponse)
|
|
*/
|
|
public function run() {
|
|
try {
|
|
$this->dispatcher->run();
|
|
} catch (Minz_Exception $e) {
|
|
try {
|
|
Minz_Log::error($e->getMessage());
|
|
} catch (Minz_PermissionDeniedException $e) {
|
|
self::killApp($e->getMessage());
|
|
}
|
|
|
|
if ($e instanceof Minz_FileNotExistException ||
|
|
$e instanceof Minz_ControllerNotExistException ||
|
|
$e instanceof Minz_ControllerNotActionControllerException ||
|
|
$e instanceof Minz_ActionException) {
|
|
Minz_Error::error (
|
|
404,
|
|
array('error' => array ($e->getMessage ())),
|
|
true
|
|
);
|
|
} else {
|
|
self::killApp($e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Kills the programme
|
|
*/
|
|
public static function killApp($txt = '') {
|
|
header('HTTP 1.1 500 Internal Server Error', true, 500);
|
|
if (function_exists('errorMessageInfo')) {
|
|
//If the application has defined a custom error message function
|
|
die(errorMessageInfo('Application problem', $txt));
|
|
}
|
|
die('### Application problem ###<br />' . "\n" . $txt);
|
|
}
|
|
|
|
private function setReporting() {
|
|
$envType = getenv('FRESHRSS_ENV');
|
|
if ($envType == '') {
|
|
$conf = Minz_Configuration::get('system');
|
|
$envType = $conf->environment;
|
|
}
|
|
switch ($envType) {
|
|
case 'development':
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', 'On');
|
|
ini_set('log_errors', 'On');
|
|
break;
|
|
case 'silent':
|
|
error_reporting(0);
|
|
break;
|
|
case 'production':
|
|
default:
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', 'Off');
|
|
ini_set('log_errors', 'On');
|
|
break;
|
|
}
|
|
}
|
|
}
|