From 7a79f07ab319e8fdb8c950f94a4342d0e7dcaf57 Mon Sep 17 00:00:00 2001 From: Bert-Jan Verwer Date: Sat, 26 Nov 2016 19:37:53 +0100 Subject: [PATCH 1/4] Added setUnixMode and getUnixMode to Filesystem. --- src/Illuminate/Filesystem/Filesystem.php | 23 +++++++++++++++++++++++ tests/Filesystem/FilesystemTest.php | 18 ++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/Illuminate/Filesystem/Filesystem.php b/src/Illuminate/Filesystem/Filesystem.php index 8bc7b09fb0f9..d3850de09444 100644 --- a/src/Illuminate/Filesystem/Filesystem.php +++ b/src/Illuminate/Filesystem/Filesystem.php @@ -111,6 +111,29 @@ public function put($path, $contents, $lock = false) return file_put_contents($path, $contents, $lock ? LOCK_EX : 0); } + /** + * Set UNIX mode of a file or directory. + * + * @param string $path + * @param bool $mode + * @return int + */ + public function setUnixMode($path, $mode) + { + return chmod($path, $mode); + } + + /** + * Get UNIX mode of a file or directory. + * + * @param string $path + * @return string + */ + public function getUnixMode($path) + { + return substr(sprintf('%o', fileperms($path)), -4); + } + /** * Prepend to a file. * diff --git a/tests/Filesystem/FilesystemTest.php b/tests/Filesystem/FilesystemTest.php index 731bde976e43..b12ccdf70558 100755 --- a/tests/Filesystem/FilesystemTest.php +++ b/tests/Filesystem/FilesystemTest.php @@ -32,6 +32,24 @@ public function testPutStoresFiles() $this->assertStringEqualsFile($this->tempDir.'/file.txt', 'Hello World'); } + public function testSetUnixMode() + { + file_put_contents($this->tempDir.'/file.txt', 'Hello World'); + $files = new Filesystem(); + $files->setUnixMode($this->tempDir.'/file.txt', 0755); + $filePermisson = substr(sprintf('%o', fileperms($this->tempDir.'/file.txt')), - 4); + $this->assertEquals('0755', $filePermisson); + } + + public function testGetUnixMode() + { + file_put_contents($this->tempDir.'/file.txt', 'Hello World'); + chmod($this->tempDir.'/file.txt', 0755); + $files = new Filesystem(); + $filePermisson = $files->getUnixMode($this->tempDir.'/file.txt'); + $this->assertEquals('0755', $filePermisson); + } + public function testDeleteRemovesFiles() { file_put_contents($this->tempDir.'/file.txt', 'Hello World'); From 11c2e60316578725d4a522938e3f2a2d4e18185f Mon Sep 17 00:00:00 2001 From: Bert-Jan Verwer Date: Sat, 26 Nov 2016 19:44:21 +0100 Subject: [PATCH 2/4] Fixed StyleCI issues. --- src/Illuminate/Filesystem/Filesystem.php | 4 ++-- tests/Filesystem/FilesystemTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Filesystem/Filesystem.php b/src/Illuminate/Filesystem/Filesystem.php index d3850de09444..c1007e8ea3ba 100644 --- a/src/Illuminate/Filesystem/Filesystem.php +++ b/src/Illuminate/Filesystem/Filesystem.php @@ -117,7 +117,7 @@ public function put($path, $contents, $lock = false) * @param string $path * @param bool $mode * @return int - */ + */ public function setUnixMode($path, $mode) { return chmod($path, $mode); @@ -128,7 +128,7 @@ public function setUnixMode($path, $mode) * * @param string $path * @return string - */ + */ public function getUnixMode($path) { return substr(sprintf('%o', fileperms($path)), -4); diff --git a/tests/Filesystem/FilesystemTest.php b/tests/Filesystem/FilesystemTest.php index b12ccdf70558..d6e135ed3a93 100755 --- a/tests/Filesystem/FilesystemTest.php +++ b/tests/Filesystem/FilesystemTest.php @@ -37,7 +37,7 @@ public function testSetUnixMode() file_put_contents($this->tempDir.'/file.txt', 'Hello World'); $files = new Filesystem(); $files->setUnixMode($this->tempDir.'/file.txt', 0755); - $filePermisson = substr(sprintf('%o', fileperms($this->tempDir.'/file.txt')), - 4); + $filePermisson = substr(sprintf('%o', fileperms($this->tempDir.'/file.txt')), -4); $this->assertEquals('0755', $filePermisson); } From c3f05abda6b19851aa58d63fdc9273c4d3def695 Mon Sep 17 00:00:00 2001 From: Bert-Jan Verwer Date: Mon, 28 Nov 2016 19:32:05 +0100 Subject: [PATCH 3/4] Merged into one method and renamed to chmod. --- src/Illuminate/Filesystem/Filesystem.php | 21 +++++++-------------- tests/Filesystem/FilesystemTest.php | 8 ++++---- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/Illuminate/Filesystem/Filesystem.php b/src/Illuminate/Filesystem/Filesystem.php index c1007e8ea3ba..3f6b6cf6331a 100644 --- a/src/Illuminate/Filesystem/Filesystem.php +++ b/src/Illuminate/Filesystem/Filesystem.php @@ -112,25 +112,18 @@ public function put($path, $contents, $lock = false) } /** - * Set UNIX mode of a file or directory. + * Get or set UNIX mode of a file or directory. * * @param string $path - * @param bool $mode - * @return int + * @param int $mode + * @return mixed */ - public function setUnixMode($path, $mode) + public function chmod($path, $mode = null) { - return chmod($path, $mode); - } + if($mode) { + return chmod($path, $mode); + } - /** - * Get UNIX mode of a file or directory. - * - * @param string $path - * @return string - */ - public function getUnixMode($path) - { return substr(sprintf('%o', fileperms($path)), -4); } diff --git a/tests/Filesystem/FilesystemTest.php b/tests/Filesystem/FilesystemTest.php index d6e135ed3a93..f63b22bed10a 100755 --- a/tests/Filesystem/FilesystemTest.php +++ b/tests/Filesystem/FilesystemTest.php @@ -32,21 +32,21 @@ public function testPutStoresFiles() $this->assertStringEqualsFile($this->tempDir.'/file.txt', 'Hello World'); } - public function testSetUnixMode() + public function testSetChmod() { file_put_contents($this->tempDir.'/file.txt', 'Hello World'); $files = new Filesystem(); - $files->setUnixMode($this->tempDir.'/file.txt', 0755); + $files->chmod($this->tempDir.'/file.txt', 0755); $filePermisson = substr(sprintf('%o', fileperms($this->tempDir.'/file.txt')), -4); $this->assertEquals('0755', $filePermisson); } - public function testGetUnixMode() + public function testGetChmod() { file_put_contents($this->tempDir.'/file.txt', 'Hello World'); chmod($this->tempDir.'/file.txt', 0755); $files = new Filesystem(); - $filePermisson = $files->getUnixMode($this->tempDir.'/file.txt'); + $filePermisson = $files->chmod($this->tempDir.'/file.txt'); $this->assertEquals('0755', $filePermisson); } From 77ac02a1921189a5e4b47f4d9f58b46a328c68c4 Mon Sep 17 00:00:00 2001 From: Bert-Jan Verwer Date: Mon, 28 Nov 2016 19:33:07 +0100 Subject: [PATCH 4/4] Solved StyleCI issue. --- src/Illuminate/Filesystem/Filesystem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Filesystem/Filesystem.php b/src/Illuminate/Filesystem/Filesystem.php index 3f6b6cf6331a..bc11ebf5ab29 100644 --- a/src/Illuminate/Filesystem/Filesystem.php +++ b/src/Illuminate/Filesystem/Filesystem.php @@ -120,7 +120,7 @@ public function put($path, $contents, $lock = false) */ public function chmod($path, $mode = null) { - if($mode) { + if ($mode) { return chmod($path, $mode); }