Skip to content

Commit

Permalink
create: PrivateFile - same as PrivateJson
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbruce committed May 17, 2023
1 parent de8be0f commit 92eadb8
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/PlainText/PrivateFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
declare(strict_types=1);

namespace Eightfold\Amos\PlainText;

use Eightfold\Amos\FileSystem\Directories\Root;
use Eightfold\Amos\FileSystem\Files\PrivateFile;

use Eightfold\Amos\Php\Interfaces\Falsifiable;
use Eightfold\Amos\Php\Interfaces\Stringable;

final class PrivateFile
{
public static function inRoot(
Root $root,
string $filename,
string $at = ''
): self {
return new self(
PrivateFile::inRoot($root, $filename, $at)
);
}

final private function __construct(
private readonly PrivateFile $privateFile
) {
}

public function notFound(): bool
{
return $this->privateFile->notFound();
}

public function isFile(): bool
{
return $this->privateFile->isFile();
}

public function toBool(): bool
{
return $this->privateFile->toBool();
}

public function toString(): string
{
if ($this->notFound()) {
return '';
}

$content = file_get_contents($this->privateFile->toString());
if ($content === false) {
return '';
}
return $content;
}

public function __toString(): string
{
return $this->toString();
}
}

0 comments on commit 92eadb8

Please sign in to comment.