Passed
Push — release/1.11.0 ( 94cc26 )
by Schlaefer
02:26
created

Server::emit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
nc 1
nop 1
dl 0
loc 3
c 0
b 0
f 0
cc 1
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * @author  PhileCMS
4
 * @link    https://philecms.github.io
5
 * @license http://opensource.org/licenses/MIT
6
 */
7
8
namespace Phile\Http;
9
10
use Phile\Phile;
11
use Psr\Http\Message\ResponseInterface;
12
use Psr\Http\Message\ServerRequestInterface;
13
use Zend\Diactoros\Response\SapiEmitter;
14
15
/**
16
 * Runs Phile as standalone application
17
 */
18
class Server
19
{
20
    /** @var Phile app to run */
21
    protected $app;
22
    
23 8
    public function __construct(Phile $app)
24
    {
25 8
        $this->app = $app;
26 8
    }
27
28 8
    public function run(ServerRequestInterface $request): ResponseInterface
29
    {
30 8
        $this->app->bootstrap();
31 8
        $middleware = $this->app->middleware(new MiddlewareQueue());
32 8
        $requestHandler = new RequestHandler($middleware, new ResponseFactory);
33 8
        return $requestHandler->handle($request);
34
    }
35
36
    public function emit(ResponseInterface $response)
37
    {
38
        (new SapiEmitter)->emit($response);
39
    }
40
}
41