Skip to content

Commit

Permalink
Added setUnixMode and getUnixMode to Filesystem.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bert-Jan Verwer committed Nov 26, 2016
1 parent bd3eb57 commit 7a79f07
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Illuminate/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
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 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');
Expand Down

0 comments on commit 7a79f07

Please sign in to comment.