3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Error handler that overrides slim's one
10 * Copyright © 2017 The Galette Team
12 * This file is part of Galette (http://galette.tuxfamily.org).
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2017 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
33 * @link http://galette.tuxfamily.org
37 namespace Galette\Handlers
;
40 use Slim\Views\Smarty
;
41 use Psr\Http\Message\ServerRequestInterface
;
49 * @author Johan Cwiklinski <johan@x-tnd.be>
50 * @copyright 2017 The Galette Team
51 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
52 * @link http://galette.tuxfamily.org
62 * @param Smarty $view View instance
63 * @param bool $displayErrorDetails Set to true to display full details
65 public function __construct(Smarty
$view, $displayErrorDetails = false)
68 $this->displayErrorDetails
= (bool)$displayErrorDetails;
73 * Write to the error log whether displayErrorDetails is false or not
75 * @param \Exception|\Throwable $throwable Error
76 * @overrides \Slim\Handlers\AbstractError::writeToErrorLog()
80 protected function writeToErrorLog($throwable)
82 $message = 'Galette error:' . PHP_EOL
;
83 $message .= $this->renderThrowableAsText($throwable);
84 while ($throwable = $throwable->getPrevious()) {
85 $message .= PHP_EOL
. 'Previous error:' . PHP_EOL
;
86 $message .= $this->renderThrowableAsText($throwable);
89 $this->logError($message);
93 * Wraps the error_log function so that this can be easily tested
95 * @param string $message Error Message
99 protected function logError($message)
101 parent
::logError($message);
109 * Determine which content type we know about is wanted using Accept header
111 * Note: This method is a bare-bones implementation designed specifically for
112 * Slim's error handling requirements. Consider a fully-feature solution such
113 * as willdurand/negotiation for any other situation.
115 * @param ServerRequestInterface $request Request
118 protected function determineContentType(ServerRequestInterface
$request)
120 if ($request->isXhr()) {
121 //get error as JSON for XHR request; more lisible
122 return 'application/json';
124 return parent
::determineContentType($request);