1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of phpDocumentor. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @copyright 2010-2016 Mike van Riel<[email protected]> |
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
10
|
|
|
* @link http://phpdoc.org |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace phpDocumentor\Infrastructure\Renderer; |
14
|
|
|
|
15
|
|
|
use League\Flysystem\Filesystem; |
16
|
|
|
use League\Flysystem\MountManager; |
17
|
|
|
use phpDocumentor\DomainModel\Path; |
18
|
|
|
use phpDocumentor\DomainModel\Renderer\Asset; |
19
|
|
|
use phpDocumentor\DomainModel\Renderer\AssetNotFoundException; |
20
|
|
|
use phpDocumentor\DomainModel\Renderer\Assets; |
21
|
|
|
use phpDocumentor\DomainModel\Renderer\Template; |
22
|
|
|
|
23
|
|
|
final class FlySystemAssets implements Assets |
24
|
|
|
{ |
25
|
|
|
/** @var Filesystem|MountManager */ |
26
|
|
|
private $filesystem; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param Filesystem|MountManager $filesystem |
30
|
|
|
*/ |
31
|
|
|
public function __construct($filesystem) |
32
|
|
|
{ |
33
|
|
|
$this->filesystem = $filesystem; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @inheritDoc |
38
|
|
|
*/ |
39
|
|
|
public function get(Path $location) |
40
|
|
|
{ |
41
|
|
|
if (! $this->has($location)) { |
42
|
|
|
throw new AssetNotFoundException(sprintf('Asset at "%s" could not found', $location)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return new Asset($this->filesystem->get((string)$location)); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @inheritDoc |
50
|
|
|
*/ |
51
|
|
|
public function has(Path $location) |
52
|
|
|
{ |
53
|
|
|
return $this->filesystem->has((string)$location); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Returns a new instance of this collection with the assets for the given template included. |
58
|
|
|
* |
59
|
|
|
* @param Template $template |
60
|
|
|
* |
61
|
|
|
* @return Assets |
62
|
|
|
*/ |
63
|
|
|
public function includeTemplateAssets(Template $template) |
64
|
|
|
{ |
65
|
|
|
$assets = clone $this; |
66
|
|
|
if ($assets->filesystem instanceof Filesystem) { |
67
|
|
|
$assets->filesystem = new MountManager([$assets->filesystem]); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
// TODO: Add template location to the mount manager |
71
|
|
|
// $assets->filesystem->mountFilesystem('', $template->) |
72
|
|
|
|
73
|
|
|
return $assets; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|