1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* CMS Pico - Create websites using Pico CMS for Nextcloud. |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2019, Daniel Rudolf (<[email protected]>) |
6
|
|
|
* |
7
|
|
|
* @license GNU AGPL version 3 or any later version |
8
|
|
|
* |
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
12
|
|
|
* License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
declare(strict_types=1); |
24
|
|
|
|
25
|
|
|
namespace OCA\CMSPico\Exceptions; |
26
|
|
|
|
27
|
|
|
class TemplateNotCompatibleException extends \Exception |
28
|
|
|
{ |
29
|
|
|
/** @var string */ |
30
|
|
|
private $templateName; |
31
|
|
|
|
32
|
|
|
/** @var string */ |
33
|
|
|
private $reason; |
34
|
|
|
|
35
|
|
|
/** @var array */ |
36
|
|
|
private $reasonData; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* PluginNotCompatibleException constructor. |
40
|
|
|
* |
41
|
|
|
* @param string $templateName |
42
|
|
|
* @param string $reason |
43
|
|
|
* @param array $reasonData |
44
|
|
|
*/ |
45
|
|
|
public function __construct(string $templateName, string $reason = "", array $reasonData = []) |
46
|
|
|
{ |
47
|
|
|
$this->templateName = $templateName; |
48
|
|
|
$this->reason = $reason; |
49
|
|
|
$this->reasonData = $reasonData; |
50
|
|
|
|
51
|
|
|
parent::__construct($this->getReason()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
public function getTemplateName(): string |
58
|
|
|
{ |
59
|
|
|
return $this->templateName; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
|
|
public function getReason(): string |
66
|
|
|
{ |
67
|
|
|
if (!$this->reason) { |
68
|
|
|
return ''; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$reasonData = $this->reasonData; |
72
|
|
|
$replaceCallback = function (array $matches) use ($reasonData) { |
73
|
|
|
return $reasonData[$matches[1]] ?? ''; |
74
|
|
|
}; |
75
|
|
|
|
76
|
|
|
return preg_replace_callback('/{([^{}]*)}/', $replaceCallback, $this->reason) ?: ''; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
public function getRawReason(): string |
83
|
|
|
{ |
84
|
|
|
return $this->reason; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return array |
89
|
|
|
*/ |
90
|
|
|
public function getRawReasonData(): array |
91
|
|
|
{ |
92
|
|
|
return $this->reasonData; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|