Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
12 / 12 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
AjaxMarkdownLogic | |
100.00% |
12 / 12 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
validateImpl | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
executeImpl | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Models\Domain\Page\Ajax; |
6 | |
7 | use PeServer\Core\Collection\Arr; |
8 | use PeServer\Core\Text; |
9 | use PeServer\Core\Mvc\Markdown; |
10 | use PeServer\Core\TypeUtility; |
11 | use PeServer\Core\Mvc\LogicCallMode; |
12 | use PeServer\App\Models\ResponseJson; |
13 | use PeServer\Core\Mvc\LogicParameter; |
14 | use PeServer\App\Models\SessionKey; |
15 | use PeServer\App\Models\Domain\UserLevel; |
16 | use PeServer\App\Models\Domain\Page\PageLogicBase; |
17 | |
18 | class AjaxMarkdownLogic extends PageLogicBase |
19 | { |
20 | public function __construct(LogicParameter $parameter) |
21 | { |
22 | parent::__construct($parameter); |
23 | } |
24 | |
25 | #region PageLogicBase |
26 | |
27 | protected function validateImpl(LogicCallMode $callMode): void |
28 | { |
29 | //NOP |
30 | } |
31 | |
32 | protected function executeImpl(LogicCallMode $callMode): void |
33 | { |
34 | $account = $this->requireSession(SessionKey::ACCOUNT); |
35 | |
36 | $json = $this->getRequestJson(); |
37 | |
38 | $isSafeMode = TypeUtility::parseBoolean($json['safe_mode'] ?? true); |
39 | /** @var string */ |
40 | $source = $json['source'] ?? Text::EMPTY; |
41 | if ($account->level !== UserLevel::ADMINISTRATOR) { |
42 | $isSafeMode = true; |
43 | } |
44 | |
45 | $markdown = new Markdown(); |
46 | $markdown->setSafeMode($isSafeMode); |
47 | $result = $markdown->build($source); |
48 | |
49 | $this->setResponseJson(ResponseJson::success(['markdown' => $result])); |
50 | } |
51 | |
52 | #endregion |
53 | } |