forked from fabarea/messenger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageDisplayController.php
More file actions
70 lines (61 loc) · 2.02 KB
/
Copy pathMessageDisplayController.php
File metadata and controls
70 lines (61 loc) · 2.02 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
65
66
67
68
69
70
<?php
namespace Fab\Messenger\Controller;
/*
* This file is part of the Fab/Messenger project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use Doctrine\DBAL\Driver\Exception;
use Fab\Messenger\Domain\Repository\QueueRepository;
use Fab\Messenger\Domain\Repository\SentMessageRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
/**
* Class MessageDisplayController
*/
class MessageDisplayController extends ActionController
{
/**
* @throws Exception
*/
public function showAction(): \Psr\Http\Message\ResponseInterface
{
$result = 'Nothing to show!';
$uuid = $this->request->getParsedBody()['uuid'] ?? $this->request->getQueryParams()['uuid'] ?? null;
if ($this->isUuidValid($uuid)) {
$source = (string)$this->request->getParsedBody()['source'] ?? $this->request->getQueryParams()['source'] ?? null;
$message =
$source === 'queue'
? $this->getQueueRepository()->findByUuid($uuid)
: $this->getSentMessageRepository()->findByUuid($uuid);
if (!empty($message)) {
$result = $message['body'];
}
}
return $this->htmlResponse($result);
}
/**
* @param $uuid
* @return bool
*/
public function isUuidValid($uuid): bool
{
$expression = '/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/';
return preg_match($expression, (string)$uuid) === 1;
}
/**
* @return QueueRepository
*/
public function getQueueRepository(): QueueRepository
{
return GeneralUtility::makeInstance(QueueRepository::class);
}
/**
* @return SentMessageRepository
*/
public function getSentMessageRepository(): SentMessageRepository
{
return GeneralUtility::makeInstance(SentMessageRepository::class);
}
}