Completed
Push — develop ( a2b4be...d107a0 )
by Neomerx
03:39 queued 01:56
created

Responses::getSchemaContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php namespace Limoncello\Flute\Http;
2
3
/**
4
 * Copyright 2015-2017 [email protected]
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use Limoncello\Flute\Contracts\Encoder\EncoderInterface;
20
use Limoncello\Flute\Contracts\Models\PaginatedDataInterface;
21
use Neomerx\JsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface;
22
use Neomerx\JsonApi\Contracts\Http\Headers\MediaTypeInterface;
23
use Neomerx\JsonApi\Contracts\Http\Headers\SupportedExtensionsInterface;
24
use Neomerx\JsonApi\Contracts\Schema\ContainerInterface;
25
use Neomerx\JsonApi\Http\Responses as JsonApiResponses;
26
27
/**
28
 * @package Limoncello\Flute
29
 */
30
class Responses extends JsonApiResponses
31
{
32
    /**
33
     * @var EncodingParametersInterface|null
34
     */
35
    private $parameters;
36
37
    /**
38
     * @var EncoderInterface
39
     */
40
    private $encoder;
41
42
    /**
43
     * @var MediaTypeInterface
44
     */
45
    private $outputMediaType;
46
47
    /**
48
     * @var SupportedExtensionsInterface
49
     */
50
    private $extensions;
51
52
    /**
53
     * @var ContainerInterface
54
     */
55
    private $schemes;
56
57
    /**
58
     * @var null|string
59
     */
60
    private $urlPrefix;
61
62
    /**
63
     * @param MediaTypeInterface               $outputMediaType
64
     * @param SupportedExtensionsInterface     $extensions
65
     * @param EncoderInterface                 $encoder
66
     * @param ContainerInterface               $schemes
67
     * @param EncodingParametersInterface|null $parameters
68
     * @param string|null                      $urlPrefix
69
     */
70 22
    public function __construct(
71
        MediaTypeInterface $outputMediaType,
72
        SupportedExtensionsInterface $extensions,
73
        EncoderInterface $encoder,
74
        ContainerInterface $schemes,
75
        EncodingParametersInterface $parameters = null,
76
        string $urlPrefix = null
77
    ) {
78 22
        $this->extensions      = $extensions;
79 22
        $this->encoder         = $encoder;
80 22
        $this->outputMediaType = $outputMediaType;
81 22
        $this->schemes         = $schemes;
82 22
        $this->urlPrefix       = $urlPrefix;
83 22
        $this->parameters      = $parameters;
84
    }
85
86
    /**
87
     * @inheritdoc
88
     */
89 22
    protected function createResponse($content, $statusCode, array $headers)
90
    {
91 22
        return new JsonApiResponse($content, $statusCode, $headers);
92
    }
93
94
    /**
95
     * @inheritdoc
96
     */
97 18
    protected function getEncoder()
98
    {
99 18
        return $this->encoder;
100
    }
101
102
    /**
103
     * @inheritdoc
104
     */
105 1
    protected function getUrlPrefix()
106
    {
107 1
        return $this->urlPrefix;
108
    }
109
110
    /**
111
     * @inheritdoc
112
     */
113 18
    protected function getEncodingParameters()
114
    {
115 18
        return $this->parameters;
116
    }
117
118
    /**
119
     * @inheritdoc
120
     */
121 1
    protected function getSchemaContainer()
122
    {
123 1
        return $this->schemes;
124
    }
125
126
    /**
127
     * @inheritdoc
128
     */
129 18
    protected function getSupportedExtensions()
130
    {
131 18
        return $this->extensions;
132
    }
133
134
    /**
135
     * @inheritdoc
136
     */
137 18
    protected function getMediaType()
138
    {
139 18
        return $this->outputMediaType;
140
    }
141
142
    /**
143
     * @inheritdoc
144
     */
145 1
    protected function getResourceLocationUrl($resource)
146
    {
147 1
        return parent::getResourceLocationUrl(
148 1
            $resource instanceof PaginatedDataInterface ? $resource->getData() : $resource
149
        );
150
    }
151
}
152