generated from 8fold/github-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create: PrivateFile - same as PrivateJson
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |