Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Added setUnixMode and getUnixMode to Filesystem #16560

Merged
merged 4 commits into from
Nov 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Illuminate/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ public function put($path, $contents, $lock = false)
return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);
}

/**
* Get or set UNIX mode of a file or directory.
*
* @param string $path
* @param int $mode
* @return mixed
*/
public function chmod($path, $mode = null)
{
if ($mode) {
return chmod($path, $mode);
}

return substr(sprintf('%o', fileperms($path)), -4);
}

/**
* Prepend to a file.
*
Expand Down
18 changes: 18 additions & 0 deletions tests/Filesystem/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ public function testPutStoresFiles()
$this->assertStringEqualsFile($this->tempDir.'/file.txt', 'Hello World');
}

public function testSetChmod()
{
file_put_contents($this->tempDir.'/file.txt', 'Hello World');
$files = new Filesystem();
$files->chmod($this->tempDir.'/file.txt', 0755);
$filePermisson = substr(sprintf('%o', fileperms($this->tempDir.'/file.txt')), -4);
$this->assertEquals('0755', $filePermisson);
}

public function testGetChmod()
{
file_put_contents($this->tempDir.'/file.txt', 'Hello World');
chmod($this->tempDir.'/file.txt', 0755);
$files = new Filesystem();
$filePermisson = $files->chmod($this->tempDir.'/file.txt');
$this->assertEquals('0755', $filePermisson);
}

public function testDeleteRemovesFiles()
{
file_put_contents($this->tempDir.'/file.txt', 'Hello World');
Expand Down