Completed
Push — master ( 82f2f8...99d29b )
by Milroy
16s queued 10s
created

Sarala::resolve()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sarala;
6
7
use League\Fractal\Serializer\DataArraySerializer;
8
9
class Sarala
10
{
11
    private $handlers;
12
13
    private $handler;
14
15
    private $supportedMediaTypes;
16
17
    public function __construct()
18
    {
19
        $this->handlers = collect(config('sarala.handlers'));
20
21
        $this->handler = $this->handlers
22
            ->where('media_type', request()->header('Accept'))
23
            ->first();
24
25
        $this->supportedMediaTypes = $this->handlers
26
            ->pluck('media_type')
27
            ->all();
28
    }
29
30
    public function getSerializer()
31
    {
32
        $serializer = is_null($this->handler) ? DataArraySerializer::class : $this->handler['serializer'];
33
34
        return app()->make($serializer);
35
    }
36
37
    public function getSupportedMediaTypes()
38
    {
39
        return $this->supportedMediaTypes;
40
    }
41
}
42