Menu

[2d8935]: / project.micro / webroot / index.php  Maximize  Restore  History

Download this file

64 lines (49 with data), 1.7 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/** @noinspection PhpUnhandledExceptionInspection */
use GI\Autoloader\Autoloader;
use GI\Application\Application\Micro\Web\Application,
GI\Application\Call\Web\Call as WebCall,
GI\Application\Call\Web\CallInterface as WebCallInterface;
use GI\REST\Route\Path\Advanced\GET as GETRoute;
use View\View;
require_once dirname(dirname(__DIR__)) . '/GI/Autoloader/resources.php';
(new Autoloader())->addBaseNamespace('View', dirname(__DIR__) . '/View');
$homeCall = new WebCall(
new GETRoute('/'),
function (WebCallInterface $call)
{
$call->setResponseToSimple(new View());
return true;
}
);
$cryptCall = new WebCall(
new GETRoute('/crypt'),
function (WebCallInterface $call)
{
try {
$word = $call->getRequest()->getQuery()->getOptional('word');
$encoding = $call->getRequest()->getQuery()->getOptional('encoding');
if (empty($word)) {
throw new Exception('word for encoding should not be empty');
}
if (empty($encoding)) {
throw new Exception('encoding should not be empty');
}
switch (strtolower($encoding)) {
case 'sha1':
$word = sha1($word);
break;
case 'md5':
$word = md5($word);
break;
default:
throw new Exception('encoding not found');
}
$call->setResponseToSimple($word);
} catch (Exception $e) {
$call->setResponseToStatus500($e->getMessage());
}
return true;
}
);
(new Application())->add($homeCall)->add($cryptCall)->run();
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.