1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2014 Robin Appelman <[email protected]> |
4
|
|
|
* This file is licensed under the Licensed under the MIT license: |
5
|
|
|
* http://opensource.org/licenses/MIT |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Icewind\SMB; |
9
|
|
|
|
10
|
|
|
class NativeFileInfo implements IFileInfo { |
11
|
|
|
const MODE_FILE = 0100000; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $path; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $name; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var \Icewind\SMB\NativeShare |
25
|
|
|
*/ |
26
|
|
|
protected $share; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var array|null |
30
|
|
|
*/ |
31
|
|
|
protected $statCache; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var int |
35
|
|
|
*/ |
36
|
|
|
protected $modeCache; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param \Icewind\SMB\NativeShare $share |
40
|
|
|
* @param string $path |
41
|
|
|
* @param string $name |
42
|
|
|
* @param array $stat |
43
|
|
|
*/ |
44
|
206 |
|
public function __construct($share, $path, $name, $stat = null) { |
45
|
206 |
|
$this->share = $share; |
46
|
206 |
|
$this->path = $path; |
47
|
206 |
|
$this->name = $name; |
48
|
206 |
|
$this->statCache = $stat; |
49
|
206 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
202 |
|
public function getPath() { |
55
|
202 |
|
return $this->path; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
98 |
|
public function getName() { |
62
|
98 |
|
return $this->name; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
202 |
|
protected function stat() { |
69
|
202 |
|
if (is_null($this->statCache)) { |
70
|
202 |
|
$this->statCache = $this->share->getStat($this->getPath()); |
71
|
202 |
|
} |
72
|
202 |
|
return $this->statCache; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return int |
77
|
|
|
*/ |
78
|
58 |
|
public function getSize() { |
79
|
58 |
|
$stat = $this->stat(); |
80
|
58 |
|
return $stat['size']; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return int |
85
|
|
|
*/ |
86
|
2 |
|
public function getMTime() { |
87
|
2 |
|
$stat = $this->stat(); |
88
|
2 |
|
return $stat['mtime']; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return bool |
93
|
|
|
*/ |
94
|
200 |
|
public function isDirectory() { |
95
|
200 |
|
$stat = $this->stat(); |
96
|
200 |
|
return !($stat['mode'] & self::MODE_FILE); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return int |
101
|
|
|
*/ |
102
|
28 |
|
protected function getMode() { |
103
|
28 |
|
if (!$this->modeCache) { |
104
|
28 |
|
$attribute = $this->share->getAttribute($this->path, 'system.dos_attr.mode'); |
105
|
|
|
// parse hex string |
106
|
28 |
|
$this->modeCache = (int)hexdec(substr($attribute, 2)); |
107
|
28 |
|
} |
108
|
28 |
|
return $this->modeCache; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return bool |
113
|
|
|
*/ |
114
|
18 |
|
public function isReadOnly() { |
115
|
18 |
|
$mode = $this->getMode(); |
116
|
18 |
|
return (bool)($mode & FileInfo::MODE_READONLY); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return bool |
121
|
|
|
*/ |
122
|
26 |
|
public function isHidden() { |
123
|
26 |
|
$mode = $this->getMode(); |
124
|
26 |
|
return (bool)($mode & FileInfo::MODE_HIDDEN); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @return bool |
129
|
|
|
*/ |
130
|
16 |
|
public function isSystem() { |
131
|
16 |
|
$mode = $this->getMode(); |
132
|
16 |
|
return (bool)($mode & FileInfo::MODE_SYSTEM); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return bool |
137
|
|
|
*/ |
138
|
16 |
|
public function isArchived() { |
139
|
16 |
|
$mode = $this->getMode(); |
140
|
16 |
|
return (bool)($mode & FileInfo::MODE_ARCHIVE); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|