1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace League\Flysystem\Adapter\Polyfill; |
4
|
|
|
|
5
|
|
|
use League\Flysystem\Config; |
6
|
|
|
use League\Flysystem\Util; |
7
|
|
|
|
8
|
|
|
trait StreamedWritingTrait |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Stream fallback delegator. |
12
|
|
|
* |
13
|
|
|
* @param string $path |
14
|
|
|
* @param resource $resource |
15
|
|
|
* @param Config $config |
16
|
|
|
* @param string $fallback |
17
|
|
|
* |
18
|
|
|
* @return mixed fallback result |
19
|
|
|
*/ |
20
|
|
View Code Duplication |
protected function stream($path, $resource, Config $config, $fallback) |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
Util::rewindStream($resource); |
23
|
|
|
$contents = stream_get_contents($resource); |
24
|
|
|
$fallbackCall = [$this, $fallback]; |
25
|
|
|
|
26
|
|
|
return call_user_func($fallbackCall, $path, $contents, $config); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Write using a stream. |
31
|
|
|
* |
32
|
|
|
* @param string $path |
33
|
|
|
* @param resource $resource |
34
|
|
|
* @param Config $config |
35
|
|
|
* |
36
|
|
|
* @return mixed false or file metadata |
37
|
|
|
*/ |
38
|
|
|
public function writeStream($path, $resource, Config $config) |
39
|
|
|
{ |
40
|
|
|
return $this->stream($path, $resource, $config, 'write'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Update a file using a stream. |
45
|
|
|
* |
46
|
|
|
* @param string $path |
47
|
|
|
* @param resource $resource |
48
|
|
|
* @param Config $config Config object or visibility setting |
49
|
|
|
* |
50
|
|
|
* @return mixed false of file metadata |
51
|
|
|
*/ |
52
|
|
|
public function updateStream($path, $resource, Config $config) |
53
|
|
|
{ |
54
|
|
|
return $this->stream($path, $resource, $config, 'update'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
// Required abstract methods |
58
|
|
|
abstract public function write($pash, $contents, Config $config); |
59
|
|
|
abstract public function update($pash, $contents, Config $config); |
60
|
|
|
} |
61
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.