|
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\Native; |
|
9
|
|
|
|
|
10
|
|
|
use Icewind\SMB\Exception\Exception; |
|
11
|
|
|
use Icewind\SMB\Exception\InvalidRequestException; |
|
12
|
|
|
use Icewind\Streams\File; |
|
13
|
|
|
|
|
14
|
|
|
class NativeStream implements File { |
|
15
|
|
|
/** |
|
16
|
|
|
* @var resource |
|
17
|
|
|
*/ |
|
18
|
|
|
public $context; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var NativeState |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $state; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var resource |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $handle; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var bool |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $eof = false; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $url; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Wrap a stream from libsmbclient-php into a regular php stream |
|
42
|
|
|
* |
|
43
|
|
|
* @param \Icewind\SMB\NativeState $state |
|
|
|
|
|
|
44
|
|
|
* @param resource $smbStream |
|
45
|
|
|
* @param string $mode |
|
46
|
|
|
* @param string $url |
|
47
|
|
|
* @return resource |
|
48
|
|
|
*/ |
|
49
|
|
|
public static function wrap($state, $smbStream, $mode, $url) { |
|
50
|
|
|
stream_wrapper_register('nativesmb', NativeStream::class); |
|
51
|
|
|
$context = stream_context_create([ |
|
52
|
|
|
'nativesmb' => [ |
|
53
|
|
|
'state' => $state, |
|
54
|
|
|
'handle' => $smbStream, |
|
55
|
|
|
'url' => $url |
|
56
|
|
|
] |
|
57
|
|
|
]); |
|
58
|
|
|
$fh = fopen('nativesmb://', $mode, false, $context); |
|
59
|
|
|
stream_wrapper_unregister('nativesmb'); |
|
60
|
|
|
return $fh; |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
78 |
|
public function stream_close() { |
|
64
|
|
|
try { |
|
65
|
78 |
|
return $this->state->close($this->handle); |
|
66
|
|
|
} catch (\Exception $e) { |
|
67
|
|
|
return false; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
38 |
|
public function stream_eof() { |
|
72
|
38 |
|
return $this->eof; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
38 |
|
public function stream_flush() { |
|
76
|
38 |
|
} |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
78 |
|
public function stream_open($path, $mode, $options, &$opened_path) { |
|
80
|
78 |
|
$context = stream_context_get_options($this->context); |
|
81
|
78 |
|
$this->state = $context['nativesmb']['state']; |
|
82
|
78 |
|
$this->handle = $context['nativesmb']['handle']; |
|
83
|
78 |
|
$this->url = $context['nativesmb']['url']; |
|
84
|
78 |
|
return true; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
38 |
|
public function stream_read($count) { |
|
88
|
38 |
|
$result = $this->state->read($this->handle, $count); |
|
89
|
38 |
|
if (strlen($result) < $count) { |
|
90
|
38 |
|
$this->eof = true; |
|
91
|
|
|
} |
|
92
|
38 |
|
return $result; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
4 |
|
public function stream_seek($offset, $whence = SEEK_SET) { |
|
96
|
4 |
|
$this->eof = false; |
|
97
|
|
|
try { |
|
98
|
4 |
|
return $this->state->lseek($this->handle, $offset, $whence) !== false; |
|
99
|
|
|
} catch (InvalidRequestException $e) { |
|
100
|
|
|
return false; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
36 |
|
public function stream_stat() { |
|
105
|
|
|
try { |
|
106
|
36 |
|
return $this->state->stat($this->url); |
|
107
|
|
|
} catch (Exception $e) { |
|
108
|
|
|
return false; |
|
|
|
|
|
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
4 |
|
public function stream_tell() { |
|
113
|
4 |
|
return $this->state->lseek($this->handle, 0, SEEK_CUR); |
|
|
|
|
|
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function stream_write($data) { |
|
117
|
|
|
return $this->state->write($this->handle, $data); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
2 |
|
public function stream_truncate($size) { |
|
121
|
2 |
|
return $this->state->ftruncate($this->handle, $size); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
2 |
|
public function stream_set_option($option, $arg1, $arg2) { |
|
125
|
2 |
|
return false; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
2 |
|
public function stream_lock($operation) { |
|
129
|
2 |
|
return false; |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths