processRequestSynchronously()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 1
nc 1
1
<?php
2
3
namespace Thruster\Component\ServerApplication;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Psr\Http\Message\ServerRequestInterface;
7
use Thruster\Component\Promise\ExtendedPromiseInterface;
8
use Thruster\Component\Promise\FulfilledPromise;
9
use Thruster\Component\Promise\RejectedPromise;
10
11
/**
12
 * Class SynchronousServerApplication
13
 *
14
 * @package Thruster\Component\ServerApplication
15
 * @author  Aurimas Niekis <[email protected]>
16
 */
17
abstract class SynchronousServerApplication implements ServerApplicationInterface
18
{
19
    /**
20
     * @param ServerRequestInterface $request
21
     *
22
     * @return ResponseInterface
23
     */
24
    abstract public function processRequestSynchronously(ServerRequestInterface $request) : ResponseInterface;
25
26
    /**
27
     * @inheritDoc
28
     */
29
    public function processRequest(ServerRequestInterface $request) : ExtendedPromiseInterface
30
    {
31
        try {
32
            $response = $this->processRequestSynchronously($request);
33
34
            return new FulfilledPromise($response);
35
        } catch (\Throwable $e) {
36
            return new RejectedPromise($e);
37
        }
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43
    public function processHead(array $headers, $httpMethod, $uri, $protocolVersion)
44
    {
45
    }
46
}
47