-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocal.php
More file actions
89 lines (77 loc) · 2.04 KB
/
Local.php
File metadata and controls
89 lines (77 loc) · 2.04 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
<?php
namespace gud3\executor;
/**
* Class Client
* @package gud3\executor
*/
class Local extends ExecuteAbstract implements ExecuteInterface
{
/**
* @param $command
* @param bool $async
* @return int|string
*/
public function exec($command, $async = false)
{
if (is_array($command)) {
foreach ($command as $cmd) {
$this->exec($cmd, $async);
}
} else {
$flag = $this->getCommandFlag($command, $async);
switch ($this->checkOs()) {
case self::OS_WINDOWS:
$this->result[] = pclose(popen($command, $flag));
break;
case self::OS_LINUX:
$this->result[] = exec($command . $flag);
break;
}
}
if (count($this->result) <= 1) {
return end($this->result);
} else {
return $this->result;
}
}
/**
* @param $path
* @param $fileName
* @return array|string
*/
public function getFile($path, $fileName)
{
if (substr($path, -1) != DIRECTORY_SEPARATOR) {
$path .= DIRECTORY_SEPARATOR;
}
$file = @fopen("{$path}{$fileName}", 'r');
if (!$file) {
return [];
}
$filesize = filesize("{$path}{$fileName}");
$read = 0;
$string = '';
while ($read < $filesize && ($buffer = fread($file, $filesize - $read))) {
$read += strlen($buffer);
$string .= $buffer;
}
fclose($file);
return $this->result[] = $string;
}
/**
* @param $path
* @param $fileName
* @param $content
* @return int
*/
public function setFile($path, $fileName, $content)
{
if (substr($path, -1) != DIRECTORY_SEPARATOR) {
$path .= DIRECTORY_SEPARATOR;
}
$file = @fopen("{$path}{$fileName}", 'w+');
$write = fwrite($file, $content);
fclose($file);
return $write;
}
}