Various updates
This commit is contained in:
25
api/common/Middleware/Attachments.php
Normal file
25
api/common/Middleware/Attachments.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace ProVM\Common\Middleware;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use ProVM\Common\Exception\Database\BlankResult;
|
||||
use ProVM\Common\Service;
|
||||
|
||||
class Attachments
|
||||
{
|
||||
public function __construct(protected Service\Attachments $service, protected LoggerInterface $logger) {}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$this->service->checkDownloaded();
|
||||
$this->service->checkEncryption();
|
||||
} catch (BlankResult $e) {
|
||||
$this->logger->notice($e);
|
||||
}
|
||||
return $handler->handle($request);
|
||||
}
|
||||
}
|
20
api/common/Middleware/Install.php
Normal file
20
api/common/Middleware/Install.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace ProVM\Common\Middleware;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use ProVM\Common\Service\Install as Service;
|
||||
|
||||
class Install
|
||||
{
|
||||
public function __construct(protected Service $service) {}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
if (!$this->service->check()) {
|
||||
$this->service->install();
|
||||
}
|
||||
return $handler->handle($request);
|
||||
}
|
||||
}
|
@ -5,34 +5,21 @@ use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use function Safe\json_encode;
|
||||
|
||||
class Logging
|
||||
{
|
||||
public function __construct(LoggerInterface $logger) {
|
||||
$this->setLogger($logger);
|
||||
}
|
||||
|
||||
protected LoggerInterface $logger;
|
||||
|
||||
public function getLogger(): LoggerInterface
|
||||
{
|
||||
return $this->logger;
|
||||
}
|
||||
|
||||
public function setLogger(LoggerInterface $logger): Logging
|
||||
{
|
||||
$this->logger = $logger;
|
||||
return $this;
|
||||
}
|
||||
public function __construct(protected LoggerInterface $logger) {}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
$response = $handler->handle($request);
|
||||
$output = [
|
||||
'uri' => var_export($request->getUri(), true),
|
||||
'body' => $request->getBody()->getContents()
|
||||
'body' => $request->getBody()->getContents(),
|
||||
'response' => (clone $response)->getBody()->getContents()
|
||||
];
|
||||
$this->getLogger()->info(\Safe\json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
|
||||
$this->logger->info(json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
24
api/common/Middleware/Mailboxes.php
Normal file
24
api/common/Middleware/Mailboxes.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace ProVM\Common\Middleware;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use ProVM\Common\Exception\Database\BlankResult;
|
||||
use ProVM\Common\Service;
|
||||
|
||||
class Mailboxes
|
||||
{
|
||||
public function __construct(protected Service\Messages $service, protected LoggerInterface $logger) {}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$this->service->checkUpdate();
|
||||
} catch (BlankResult $e) {
|
||||
$this->logger->notice($e);
|
||||
}
|
||||
return $handler->handle($request);
|
||||
}
|
||||
}
|
24
api/common/Middleware/Messages.php
Normal file
24
api/common/Middleware/Messages.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace ProVM\Common\Middleware;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use ProVM\Common\Exception\Database\BlankResult;
|
||||
use ProVM\Common\Service;
|
||||
|
||||
class Messages
|
||||
{
|
||||
public function __construct(protected Service\Messages $service, protected LoggerInterface $logger) {}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
try {
|
||||
$this->service->checkSchedule();
|
||||
} catch (BlankResult $e) {
|
||||
$this->logger->notice($e);
|
||||
}
|
||||
return $handler->handle($request);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user