Completed
Push — master ( 689084...daf696 )
by Joao Gilberto
10s
created

BaseHandler::writeOutput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
3
namespace ByJG\RestServer\HandleOutput;
4
5
use ByJG\RestServer\ServiceAbstract;
6
7
abstract class BaseHandler implements HandleOutputInterface
8
{
9
    protected $options = [
10
        'header' => [],
11
        'build-null' => true,
12
        'only-string' => false
13
    ];
14
15
    public function option($option, $value)
16
    {
17
        $this->options[$option] = $value;
18
    }
19
20
    public function writeHeader()
21
    {
22
        foreach ($this->options['header'] as $header) {
23
            header($header);
24
        }
25
    }
26
27
    public function writeOutput(ServiceAbstract $instance)
28
    {
29
        $serialized = $instance
30
            ->getResponse()
31
            ->getResponseBag()
32
            ->process($this->options['build-null'], $this->options['only-string']);
33
34
        return $this->getFormatter()->process($serialized);
35
    }
36
}
37