|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* BEdita, API-first content management framework |
|
4
|
|
|
* Copyright 2018 ChannelWeb Srl, Chialab Srl |
|
5
|
|
|
* |
|
6
|
|
|
* This file is part of BEdita: you can redistribute it and/or modify |
|
7
|
|
|
* it under the terms of the GNU Lesser General Public License as published |
|
8
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
|
9
|
|
|
* (at your option) any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace App\Controller\Component; |
|
15
|
|
|
|
|
16
|
|
|
use BEdita\SDK\BEditaClientException; |
|
17
|
|
|
use Cake\Controller\Component\FlashComponent as CakeFlashComponent; |
|
18
|
|
|
use Cake\Core\Configure; |
|
19
|
|
|
use Cake\Utility\Hash; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Extends CakePHP FlashComponent setting exception attributes. |
|
23
|
|
|
*/ |
|
24
|
|
|
class FlashComponent extends CakeFlashComponent |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @inheritDoc |
|
28
|
|
|
*/ |
|
29
|
|
|
public function set($message, array $options = []): void |
|
30
|
|
|
{ |
|
31
|
|
|
$error = Hash::get($options, 'params'); |
|
32
|
|
|
if ($error && ($error instanceof \Exception)) { |
|
33
|
|
|
$options['params'] = [ |
|
34
|
|
|
'title' => $error->getMessage(), |
|
35
|
|
|
// exception error code is HTTP status as default |
|
36
|
|
|
'status' => $error->getCode(), |
|
37
|
|
|
// our error code may be different |
|
38
|
|
|
'code' => '', |
|
39
|
|
|
'detail' => '', |
|
40
|
|
|
'trace' => Configure::read('debug') ? $error->getTraceAsString() : '', |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
|
|
if ($error instanceof BEditaClientException) { |
|
44
|
|
|
$options['params'] = array_merge($options['params'], $error->getAttributes()); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
parent::set($message, $options); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|