@@ -10,18 +10,18 @@ |
||
10 | 10 | /** |
11 | 11 | * @expectedException Exception |
12 | 12 | */ |
13 | - public function testInvalidDirectory() { |
|
13 | + public function testInvalidDirectory () { |
|
14 | 14 | new RecursiveFileListing(__DIR__ . "/not_existing_dir"); |
15 | 15 | } |
16 | 16 | |
17 | - public function testFindFiles() { |
|
17 | + public function testFindFiles () { |
|
18 | 18 | $finder = new RecursiveFileListing(__DIR__ . "/RecFileListTestDir"); |
19 | 19 | $files = $finder->scan(); |
20 | 20 | |
21 | 21 | $this->assertEquals(3, count($files)); |
22 | 22 | } |
23 | 23 | |
24 | - public function testFilterFiles() { |
|
24 | + public function testFilterFiles () { |
|
25 | 25 | $finder = new RecursiveFileListing(__DIR__ . "/RecFileListTestDir"); |
26 | 26 | $finder->addFilter('/.*\.txt$/i'); |
27 | 27 | $files = $finder->scan(); |
@@ -13,11 +13,11 @@ |
||
13 | 13 | |
14 | 14 | private $tempmrg; |
15 | 15 | |
16 | - public function __construct() { |
|
16 | + public function __construct () { |
|
17 | 17 | $this->tempmrg = new TempManager("csf_command_runner"); |
18 | 18 | } |
19 | 19 | |
20 | - public function run(int $type, string $dir, string $command, bool $sudo = false) : TempFile { |
|
20 | + public function run (int $type, string $dir, string $command, bool $sudo = false) : TempFile { |
|
21 | 21 | $tempfile = $this->tempmrg->createFile(); |
22 | 22 | $temp_path = $tempfile->getPath(); |
23 | 23 |
@@ -9,28 +9,28 @@ discard block |
||
9 | 9 | private $id; |
10 | 10 | private $full_path; |
11 | 11 | |
12 | - public function __construct(string $id, string $path) { |
|
12 | + public function __construct (string $id, string $path) { |
|
13 | 13 | $this->id = $id; |
14 | 14 | $this->full_path = $path; |
15 | 15 | } |
16 | 16 | |
17 | - public function getId() : string { |
|
17 | + public function getId () : string { |
|
18 | 18 | return $this->id; |
19 | 19 | } |
20 | 20 | |
21 | - public function getPath() : string { |
|
21 | + public function getPath () : string { |
|
22 | 22 | return $this->full_path; |
23 | 23 | } |
24 | 24 | |
25 | - public function __toString() : string { |
|
25 | + public function __toString () : string { |
|
26 | 26 | return $this->full_path; |
27 | 27 | } |
28 | 28 | |
29 | - public function getText() : string { |
|
29 | + public function getText () : string { |
|
30 | 30 | return file_get_contents($this->full_path); |
31 | 31 | } |
32 | 32 | |
33 | - public function getLastLines(int $lines = 10, $buffer = 4096) : string { |
|
33 | + public function getLastLines (int $lines = 10, $buffer = 4096) : string { |
|
34 | 34 | $f = fopen($this->full_path, "rb"); |
35 | 35 | if ($f === false) { |
36 | 36 | throw new Exception("Cant open file"); |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | return $output; |
59 | 59 | } |
60 | 60 | |
61 | - public function delete() { |
|
61 | + public function delete () { |
|
62 | 62 | unlink($this->full_path); |
63 | 63 | } |
64 | 64 |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | private $dir; |
13 | 13 | |
14 | - public function __construct(string $context) { |
|
14 | + public function __construct (string $context) { |
|
15 | 15 | if (!preg_match('/^[a-z0-9\_\-]+$/i', $context)) { |
16 | 16 | throw new Exception("The temp context must be an alphanumeric string"); |
17 | 17 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | } |
28 | 28 | } |
29 | 29 | |
30 | - private function IdToPath(string $id) : string { |
|
30 | + private function IdToPath (string $id) : string { |
|
31 | 31 | $path = $this->dir . "/" . $id; |
32 | 32 | if (!file_exists($path)) { |
33 | 33 | touch($path); |
@@ -35,12 +35,12 @@ discard block |
||
35 | 35 | return $path; |
36 | 36 | } |
37 | 37 | |
38 | - public function createFile() : TempFile { |
|
38 | + public function createFile () : TempFile { |
|
39 | 39 | $id = uniqid("", true); |
40 | 40 | return new TempFile($id, $this->IdToPath($id)); |
41 | 41 | } |
42 | 42 | |
43 | - public function getFile(string $id) : TempFile { |
|
43 | + public function getFile (string $id) : TempFile { |
|
44 | 44 | return new TempFile($id, $this->IdToPath($id)); |
45 | 45 | } |
46 | 46 |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | private $files; |
11 | 11 | private $filters = []; |
12 | 12 | |
13 | - public function __construct(string $dir) { |
|
13 | + public function __construct (string $dir) { |
|
14 | 14 | if (!is_dir($dir)) { |
15 | 15 | throw new Exception("Directory required"); |
16 | 16 | } |
@@ -18,22 +18,22 @@ discard block |
||
18 | 18 | $this->root_dir = $dir; |
19 | 19 | } |
20 | 20 | |
21 | - public function addFilter(string $regex) { |
|
21 | + public function addFilter (string $regex) { |
|
22 | 22 | $this->filters[] = $regex; |
23 | 23 | } |
24 | 24 | |
25 | - public function clearFilters() { |
|
25 | + public function clearFilters () { |
|
26 | 26 | $this->filters = []; |
27 | 27 | } |
28 | 28 | |
29 | - public function scan() : array { |
|
29 | + public function scan () : array { |
|
30 | 30 | $this->files = []; |
31 | 31 | $this->recursiveScan($this->root_dir); |
32 | 32 | sort($this->files); |
33 | 33 | return $this->files; |
34 | 34 | } |
35 | 35 | |
36 | - private function recursiveScan(string $dir) { |
|
36 | + private function recursiveScan (string $dir) { |
|
37 | 37 | $files = scandir($dir); |
38 | 38 | foreach ($files as $filename) { |
39 | 39 | if ($filename !== "." && $filename !== "..") { |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
52 | - private function isFileOk(string $path) : bool { |
|
52 | + private function isFileOk (string $path) : bool { |
|
53 | 53 | if (count($this->filters) == 0) { |
54 | 54 | return true; |
55 | 55 | } |