Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
ToolBase64Logic
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 4
90
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 startup
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 validateImpl
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
 executeImpl
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\App\Models\Domain\Page\Tool;
6
7use Exception;
8use PeServer\App\Models\Domain\Page\PageLogicBase;
9use PeServer\Core\Mvc\LogicCallMode;
10use PeServer\Core\Mvc\LogicParameter;
11
12class ToolBase64Logic extends PageLogicBase
13{
14    public function __construct(LogicParameter $parameter)
15    {
16        parent::__construct($parameter);
17    }
18
19    #region PageLogicBase
20
21    protected function startup(LogicCallMode $callMode): void
22    {
23        $this->registerParameterKeys([
24            'tool_base64_input',
25            'tool_base64_kind',
26            'tool_base64_result',
27            'has_result',
28        ], true);
29
30        $this->setValue('has_result', false);
31    }
32
33    protected function validateImpl(LogicCallMode $callMode): void
34    {
35        if ($callMode === LogicCallMode::Initialize) {
36            return;
37        }
38
39        $this->validation('tool_base64_input', function (string $key, string $value) {
40            $this->validator->isNotEmpty($key, $value);
41        });
42
43        $this->validation('tool_base64_kind', function (string $key, string $value) {
44            $this->validator->isNotEmpty($key, $value);
45            $this->validator->isMatch($key, '/encode|decode/', $value);
46        });
47    }
48
49    protected function executeImpl(LogicCallMode $callMode): void
50    {
51        if ($callMode === LogicCallMode::Initialize) {
52            $this->setValue('tool_base64_kind', 'encode');
53            return;
54        }
55
56        $input = $this->getRequest('tool_base64_input');
57        $kind = $this->getRequest('tool_base64_kind');
58        $result = '';
59
60        switch ($kind) {
61            case 'encode':
62                $result = base64_encode($input);
63                break;
64
65            case 'decode':
66                $result = base64_decode($input);
67                break;
68
69            default:
70                throw new Exception('kind');
71        }
72
73        $this->setValue('has_result', true);
74        $this->setValue('tool_base64_result', $result);
75    }
76
77    #endregion
78}