FileGetContents::retrieve()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace Realshadow\RequestDeserializer\JsonSchema\Uri\Retrievers;
4
5
use JsonSchema\Uri\Retrievers\FileGetContents as OriginalFileGetContents;
6
use JsonSchema\Uri\Retrievers\UriRetrieverInterface;
7
8
9
/**
10
 * Override of the originle retriever so we can look for nested and/or inherited schemas on disk in specified base path
11
 *
12
 * @package Realshadow\RequestDeserializer\JsonSchema\Uri\Retrievers
13
 * @author Lukáš Homza <[email protected]>
14
 */
15
class FileGetContents extends OriginalFileGetContents implements UriRetrieverInterface
16
{
17
18
    /**
19
     * @var string $basePath
20
     */
21
    private $basePath;
22
23
    /**
24
     * @param string $basePath
25
     */
26
    public function setBasePath($basePath)
27
    {
28
        $this->basePath = $basePath;
29
    }
30
31
    /**
32
     * {@inheritDoc}
33
     * @see \JsonSchema\Uri\Retrievers\UriRetrieverInterface::retrieve()
34
     */
35
    public function retrieve($uri)
36
    {
37
        $scheme = parse_url($uri)['scheme'] . '://';
38
39
        $uri = str_replace($scheme, $scheme . $this->basePath, $uri);
40
41
        return parent::retrieve($uri);
42
    }
43
44
}
45