@@ -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 | } |
@@ -10,18 +10,18 @@ discard block |
||
| 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(); |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | $this->assertEquals(2, count($files)); |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - public function testFilterRemoval() { |
|
| 32 | + public function testFilterRemoval () { |
|
| 33 | 33 | $finder = new RecursiveFileListing(__DIR__ . "/RecFileListTestDir"); |
| 34 | 34 | $finder->addFilter('/.*\.txt$/i'); |
| 35 | 35 | $finder->clearFilters(); |
@@ -7,7 +7,7 @@ |
||
| 7 | 7 | |
| 8 | 8 | final class CommandRunnerTest extends TestCase { |
| 9 | 9 | |
| 10 | - public function testRunningCommand() { |
|
| 10 | + public function testRunningCommand () { |
|
| 11 | 11 | $runner = new CommandRunner(); |
| 12 | 12 | $file = $runner->run(CommandRunner::COMMAND_SYNC, __DIR__ . "/RecFileListTestDir", "ls"); |
| 13 | 13 | $file_lists = $file->getText(); |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | private $exec; |
| 16 | 16 | |
| 17 | - public function __construct(string $container, string $connection_string) { |
|
| 17 | + public function __construct (string $container, string $connection_string) { |
|
| 18 | 18 | $this->exec = new CommandRunner(); |
| 19 | 19 | |
| 20 | 20 | $this->connection_string = $connection_string; |
@@ -31,22 +31,22 @@ discard block |
||
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - protected function run($cmd) : string { |
|
| 34 | + protected function run ($cmd) : string { |
|
| 35 | 35 | $logfile = $this->exec->run(CommandRunner::COMMAND_SYNC, __DIR__, $cmd, true); |
| 36 | 36 | $log = $logfile->getText(); |
| 37 | 37 | $logfile->delete(); |
| 38 | 38 | return $log; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - public function getContainer() : string { |
|
| 41 | + public function getContainer () : string { |
|
| 42 | 42 | return $this->container; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - public function getAccountName() : string { |
|
| 45 | + public function getAccountName () : string { |
|
| 46 | 46 | $this->account_name; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - public function uploadToBlob(string $file, string $name, string $content_type = null) { |
|
| 49 | + public function uploadToBlob (string $file, string $name, string $content_type = null) { |
|
| 50 | 50 | if (!file_exists($file) || !is_file($file)) { |
| 51 | 51 | throw new Exception("Invalid file"); |
| 52 | 52 | } |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | return $log; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - public function GenerateBlobSas(string $name, int $expire = 5 * 60 * 60, string $ip = null) : string { |
|
| 73 | + public function GenerateBlobSas (string $name, int $expire = 5 * 60 * 60, string $ip = null) : string { |
|
| 74 | 74 | $signedPermissions = "r"; |
| 75 | 75 | //$signedStart = gmdate("Y-m-d\TH:i\Z", time()); |
| 76 | 76 | $signedExpiry = gmdate("Y-m-d\TH:i\Z", time() + $expire); |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | return $sas; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - public function getBlobUrl(string $name) { |
|
| 124 | + public function getBlobUrl (string $name) { |
|
| 125 | 125 | $url = "https://" . $this->account_name . ".blob.core.windows.net/" . $this->container . "/" . $name; |
| 126 | 126 | return $url; |
| 127 | 127 | } |