|
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 Flyfinder\Finder; |
|
19
|
|
|
use League\Flysystem\Adapter\Local; |
|
20
|
|
|
use League\Flysystem\Filesystem; |
|
21
|
|
|
use League\Flysystem\FilesystemInterface; |
|
22
|
|
|
use League\Flysystem\MountManager; |
|
23
|
|
|
use LogicException; |
|
24
|
|
|
use phpDocumentor\Dsn; |
|
25
|
|
|
use phpDocumentor\Parser\FileSystemFactory; |
|
26
|
|
|
|
|
27
|
|
|
final class FlySystemFactory implements FileSystemFactory |
|
28
|
|
|
{ |
|
29
|
|
|
/** @var MountManager */ |
|
30
|
|
|
private $mountManager; |
|
31
|
|
|
|
|
32
|
4 |
|
public function __construct(MountManager $mountManager) |
|
33
|
|
|
{ |
|
34
|
4 |
|
$this->mountManager = $mountManager; |
|
35
|
4 |
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Returns a Filesystem instance based on the scheme of the provided Dsn |
|
39
|
|
|
*/ |
|
40
|
4 |
|
public function create(Dsn $dsn): FilesystemInterface |
|
41
|
|
|
{ |
|
42
|
4 |
|
$dsnId = hash('md5', (string) $dsn); |
|
43
|
|
|
|
|
44
|
|
|
try { |
|
45
|
4 |
|
$filesystem = $this->mountManager->getFilesystem($dsnId); |
|
46
|
3 |
|
} catch (LogicException $e) { |
|
47
|
3 |
|
if ($dsn->getScheme() === 'file') { |
|
48
|
2 |
|
$path = $dsn->getPath(); |
|
49
|
2 |
|
$filesystem = new Filesystem(new Local($path, LOCK_EX, Local::SKIP_LINKS)); |
|
50
|
|
|
} else { |
|
51
|
|
|
//This will be implemented as soon as the CloneRemoteGitToLocal adapter is finished |
|
52
|
1 |
|
throw new \InvalidArgumentException('http and https are not supported yet'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
2 |
|
$this->mountManager->mountFilesystem($dsnId, $filesystem); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
3 |
|
$filesystem->addPlugin(new Finder()); |
|
59
|
|
|
|
|
60
|
3 |
|
return $filesystem; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|