1 | <?php |
||
12 | class NativeFileInfo implements IFileInfo { |
||
13 | const MODE_FILE = 0100000; |
||
14 | |||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $path; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $name; |
||
24 | |||
25 | /** |
||
26 | * @var NativeShare |
||
27 | */ |
||
28 | protected $share; |
||
29 | |||
30 | /** |
||
31 | * @var array|null |
||
32 | */ |
||
33 | protected $statCache = null; |
||
34 | |||
35 | /** @var callable|null */ |
||
36 | protected $statCallback = null; |
||
37 | |||
38 | /** |
||
39 | * @var int |
||
40 | */ |
||
41 | protected $modeCache; |
||
42 | |||
43 | /** |
||
44 | * @param NativeShare $share |
||
45 | * @param string $path |
||
46 | * @param string $name |
||
47 | * @param array|callable $stat |
||
48 | */ |
||
49 | 104 | public function __construct($share, $path, $name, $stat) { |
|
50 | 104 | $this->share = $share; |
|
51 | 104 | $this->path = $path; |
|
52 | 104 | $this->name = $name; |
|
53 | |||
54 | 104 | if (is_array($stat)) { |
|
55 | 23 | $this->statCache = $stat; |
|
56 | 102 | } elseif (is_callable($stat)) { |
|
57 | 102 | $this->statCallback = $stat; |
|
58 | } else { |
||
59 | throw new \InvalidArgumentException('$stat needs to be an array or callback'); |
||
60 | } |
||
61 | 104 | } |
|
62 | |||
63 | /** |
||
64 | * @return string |
||
65 | */ |
||
66 | 101 | public function getPath() { |
|
69 | |||
70 | /** |
||
71 | * @return string |
||
72 | */ |
||
73 | 49 | public function getName() { |
|
76 | |||
77 | /** |
||
78 | * @return array |
||
79 | */ |
||
80 | 102 | protected function stat() { |
|
81 | 102 | if (is_null($this->statCache)) { |
|
82 | 102 | $this->statCache = call_user_func($this->statCallback); |
|
83 | } |
||
84 | 102 | return $this->statCache; |
|
85 | } |
||
86 | |||
87 | /** |
||
88 | * @return int |
||
89 | */ |
||
90 | 29 | public function getSize() { |
|
94 | |||
95 | /** |
||
96 | * @return int |
||
97 | */ |
||
98 | 1 | public function getMTime() { |
|
102 | |||
103 | /** |
||
104 | * @return bool |
||
105 | */ |
||
106 | 101 | public function isDirectory() { |
|
110 | |||
111 | /** |
||
112 | * @return int |
||
113 | */ |
||
114 | 14 | protected function getMode() { |
|
115 | 14 | if (!$this->modeCache) { |
|
116 | 14 | $attribute = $this->share->getAttribute($this->path, 'system.dos_attr.mode'); |
|
117 | // parse hex string |
||
118 | 14 | $this->modeCache = (int)hexdec(substr($attribute, 2)); |
|
119 | } |
||
120 | 14 | return $this->modeCache; |
|
121 | } |
||
122 | |||
123 | /** |
||
124 | * @return bool |
||
125 | */ |
||
126 | 9 | public function isReadOnly() { |
|
130 | |||
131 | /** |
||
132 | * @return bool |
||
133 | */ |
||
134 | 13 | public function isHidden() { |
|
138 | |||
139 | /** |
||
140 | * @return bool |
||
141 | */ |
||
142 | 8 | public function isSystem() { |
|
146 | |||
147 | /** |
||
148 | * @return bool |
||
149 | */ |
||
150 | 8 | public function isArchived() { |
|
154 | } |
||
155 |