Skip to content

Commit

Permalink
feat: added File mode consts
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianKoehnen committed Nov 2, 2022
1 parent 5670633 commit bb4fe16
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

class File implements FileInterface
{
public const MODE_READ = 'r';
public const MODE_READ_PLUS = 'r+';
public const MODE_WRITE = 'w';
public const MODE_WRITE_PLUS = 'w+';
/**
* @var resource
*/
Expand All @@ -16,6 +20,9 @@ class File implements FileInterface
protected string $filePath;
protected string $mode;

/**
* @param self::MODE_* $mode
*/
public function __construct(string $filePath, string $mode)
{
$this->openStream($filePath, $mode);
Expand Down
6 changes: 4 additions & 2 deletions src/Remote/SftpFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Ambimax\File\File;
use phpseclib3\Net\SFTP;
use phpseclib3\Net\SFTP\Stream;
use RuntimeException;

class SftpFile extends File
{
Expand All @@ -16,6 +15,9 @@ class SftpFile extends File
protected string $password;
protected SFTP $sftp;

/**
* @param File::MODE_* $mode
*/
public function __construct(string $hostname, string $username, string $password, string $filePath, string $mode)
{
$this->hostname = $hostname;
Expand All @@ -38,7 +40,7 @@ protected function openStream(string $filePath, string $mode): void
$mode);

if (false === $tmpFileHandle) {
throw new RuntimeException(sprintf('Could not open file \'%s\'.', $filePath));
throw new \RuntimeException(sprintf('Could not open file \'%s\'.', $filePath));
}

$this->fileHandle = $tmpFileHandle;
Expand Down

0 comments on commit bb4fe16

Please sign in to comment.