Passed
Push — develop ( df587f...f7c208 )
by Schlaefer
34s
created

Server::emit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * @author  PhileCMS
4
 * @link    https://philecms.com
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 4
    public function __construct(Phile $app)
24
    {
25 4
        $this->app = $app;
26 4
    }
27
28 4
    public function run(ServerRequestInterface $request): ResponseInterface
29
    {
30 4
        $this->app->bootstrap();
31 4
        $middleware = $this->app->middleware(new MiddlewareQueue());
32 4
        $requestHandler = new RequestHandler($middleware, new ResponseFactory);
33 4
        return $requestHandler->handle($request);
34
    }
35
36
    public function emit(ResponseInterface $response)
37
    {
38
        (new SapiEmitter)->emit($response);
39
    }
40
}
41