1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* This file is part of phpDocumentor. |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @author Mike van Riel <[email protected]> |
11
|
|
|
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) |
12
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
13
|
|
|
* @link http://phpdoc.org |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace phpDocumentor\Parser; |
17
|
|
|
|
18
|
|
|
use League\Flysystem\FilesystemInterface; |
19
|
|
|
use phpDocumentor\Reflection\File; |
20
|
|
|
use Webmozart\Assert\Assert; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Wrapper for FlySystem's FilesystemInterface. |
24
|
|
|
*/ |
25
|
|
|
final class FlySystemFile implements File |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var FilesystemInterface |
29
|
|
|
*/ |
30
|
|
|
private $fileSystem; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private $fileName; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* FlySystemFile constructor. |
39
|
|
|
* |
40
|
|
|
* @param string $fileName |
41
|
|
|
*/ |
42
|
|
|
public function __construct(FilesystemInterface $fileSystem, $fileName) |
43
|
|
|
{ |
44
|
|
|
Assert::string($fileName); |
45
|
|
|
$this->fileSystem = $fileSystem; |
46
|
|
|
$this->fileName = $fileName; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Returns the content of the file as a string. |
51
|
|
|
*/ |
52
|
|
|
public function getContents(): string |
53
|
|
|
{ |
54
|
|
|
return $this->fileSystem->read($this->fileName); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Returns md5 hash of the file. |
59
|
|
|
*/ |
60
|
|
|
public function md5(): string |
61
|
|
|
{ |
62
|
|
|
return md5($this->getContents()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Returns an relative path to the file. |
67
|
|
|
*/ |
68
|
|
|
public function path(): string |
69
|
|
|
{ |
70
|
|
|
return $this->fileName; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|