-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVirtualFileSystem.php
More file actions
92 lines (77 loc) · 2.02 KB
/
VirtualFileSystem.php
File metadata and controls
92 lines (77 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
namespace org\jecat\framework\fs\vfs ;
class VirtualFileSystem
{
/**
* 挂载一个物理文件系统
*/
public function mount($sPath,IPhysicalFileSystem $aConcreteFileSystem)
{
$sMountPoint = trim($sPath,'/') ;
$this->arrConcreteFileSystem[$sMountPoint] = $aConcreteFileSystem ;
krsort($this->arrConcreteFileSystem) ;
}
/**
* 卸载一个物理文件系统
*/
public function unmount($sPath)
{
$sMountPoint = trim($sPath,'/') ;
unset($this->arrConcreteFileSystem[$sMountPoint]) ;
}
/**
* 通过确切的挂载点返回一个物理文件系统对像
*
* @param string $sMountPoint 是一个路径,左右两端不需要斜线
* @return IPhysicalFileSystem
*/
public function fileSystem($sMountPoint)
{
return isset($this->arrConcreteFileSystem[$sMountPoint])?
$this->arrConcreteFileSystem[$sMountPoint]: null ;
}
/**
* 找到给入的路径所属的物理文件系统
*
* @param string $sMountPoint 是一个路径,左右两端不需要斜线
* @return IPhysicalFileSystem
*/
public function findFileSystem($sPath)
{
$sPath = trim($sPath,'/').'/' ;
foreach($this->arrConcreteFileSystem as $sMountPoint=>$aConcreteFileSystem)
{
if( strpos( $sPath, $sMountPoint.'/' ) === 0 )
{
return $aConcreteFileSystem ;
}
}
return null ;
}
/**
* 返回给入的路径所属的物理文件系统 以及 在所属文件系统中的相对路径
*
* @param string $sMountPoint 是一个路径,左右两端不需要斜线
* @return array(IPhysicalFileSystem,string)
*/
public function localeFileSystemPath($sPath)
{
$sPath = trim($sPath,'/').'/' ;
foreach($this->arrConcreteFileSystem as $sMountPoint=>$aConcreteFileSystem)
{
if( strpos( $sPath, $sMountPoint.'/' ) === 0 )
{
return array(
$aConcreteFileSystem
, substr( $sPath, strlen($sMountPoint)+1, -1 )?: ''
) ;
}
}
return null ;
}
public function mountPoints()
{
return array_keys($this->arrConcreteFileSystem) ;
}
private $arrConcreteFileSystem ;
}