-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathFile.php
61 lines (53 loc) · 1.2 KB
/
File.php
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
<?php
namespace Laravel\Nova\LogViewer;
use Symfony\Component\Process\Process;
class File
{
/**
* The path to the log file.
*
* @var string
*/
public $file;
/**
* Create a new File instance.
*
* @param string $file
*/
public function __construct($file)
{
$this->file = $file;
}
/**
* Return the number of lines for the given file.
*
* @return int
*/
public function numberOfLines()
{
return (int) $this->executeCommand('awk', 'END {print NR}', $this->file);
}
/**
* Return the content after the given line number.
*
* @param int $lineNumber
* @return string
*/
public function contentAfterLine($lineNumber)
{
return $this->executeCommand('awk', "NR > {$lineNumber}", $this->file);
}
/**
* Execute the given command and arguments in a process.
*
* @param string $command
* @param array ...$args
* @return string
*/
public function executeCommand($command, ...$args)
{
$process = new Process(array_merge([$command], $args));
$process->run();
return $process->getOutput();
}
}