Skip to content

Commit

Permalink
Merge pull request #39 from 8fold/go-deeper-with-content
Browse files Browse the repository at this point in the history
BC: Require Path and Filename instances
  • Loading branch information
joshbruce authored Jan 20, 2024
2 parents 129a33b + 398a02a commit 85fa3b7
Show file tree
Hide file tree
Showing 33 changed files with 232 additions and 360 deletions.
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 3 additions & 9 deletions src/FileSystem/Directories/PrivateDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@ final class PrivateDirectory implements Findable, Stringable
{
private readonly SplFileInfo $fileInfo;

public static function inRoot(
Root $root,
string|Path $at = ''
): self {
if (is_string($at)) {
$at = Path::fromString($at);
}
public static function inRoot(Root $root, Path $at): self
{
return new self($root, $at);
}

// TODO: mark as final
private function __construct(
final private function __construct(
private readonly Root $root, // @phpstan-ignore-line
private readonly Path $at // @phpstan-ignore-line
) {
Expand Down
15 changes: 4 additions & 11 deletions src/FileSystem/Directories/PublicDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,13 @@ final class PublicDirectory implements Findable, Stringable
{
private readonly SplFileInfo $fileInfo;

public static function inRoot(
Root $root,
string|Path $at = ''
): self {
public static function inRoot(Root $root, Path $at): self
{
return self::inPublicRoot($root->publicRoot(), $at);
}

public static function inPublicRoot(
PublicRoot $root,
string|Path $at = ''
): self {
if (is_string($at)) {
$at = Path::fromString($at);
}
public static function inPublicRoot(PublicRoot $root, Path $at): self
{
return new self($root, $at);
}

Expand Down
17 changes: 4 additions & 13 deletions src/FileSystem/Files/PrivateFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,8 @@ final class PrivateFile implements Findable, Stringable
{
private readonly SplFileInfo $fileInfo;

public static function inRoot(
Root $root,
string|Filename $filename, // TODO: Create filename class
string|Path $at = ''
): self {
if (is_string($at)) {
$at = Path::fromString($at);
}
public static function inRoot(Root $root, Filename $filename, Path $at): self
{
return self::inPrivateDirectory(
PrivateDirectory::inRoot($root, $at),
$filename
Expand All @@ -34,15 +28,12 @@ public static function inRoot(

public static function inPrivateDirectory(
PrivateDirectory $directory,
string|Filename $filename
Filename $filename
): self {
if (is_string($filename)) {
$filename = Filename::fromString($filename);
}
return new self($directory, $filename);
}

private function __construct(
final private function __construct(
private readonly PrivateDirectory $directory, // @phpstan-ignore-line
private readonly Filename $filename // @phpstan-ignore-line
) {
Expand Down
22 changes: 8 additions & 14 deletions src/FileSystem/Files/PublicContentFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Eightfold\Amos\Php\Interfaces\Stringable;

use Eightfold\Amos\FileSystem\Path;
use Eightfold\Amos\FileSystem\Filename;

use Eightfold\Amos\FileSystem\Directories\Root;
use Eightfold\Amos\FileSystem\Directories\PublicRoot;
Expand All @@ -17,23 +18,16 @@ final class PublicContentFile implements Findable, Stringable
{
private const FILENAME = 'content.md';

public static function inRoot(
Root $root,
string|Path $at = ''
): self {
public static function inRoot(Root $root, Path $at): self
{
return self::inPublicRoot($root->publicRoot(), $at);
}

public static function inPublicRoot(
PublicRoot $root,
string|Path $at = ''
): self {
if (is_string($at)) {
$at = Path::fromString($at);
}
return new self(
PublicFile::inPublicRoot($root, self::FILENAME, $at)
);
public static function inPublicRoot(PublicRoot $root, Path $at): self
{
$filename = Filename::fromString(self::FILENAME);
$pFile = PublicFile::inPublicRoot($root, $filename, $at);
return new self($pFile);
}

private function __construct(
Expand Down
18 changes: 4 additions & 14 deletions src/FileSystem/Files/PublicFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,16 @@ final class PublicFile implements Findable, Stringable
{
private readonly SplFileInfo $fileInfo;

public static function inRoot(
Root $root,
string|Filename $filename,
string|Path $at = ''
): self {
public static function inRoot(Root $root, Filename $filename, Path $at): self
{
return self::inPublicRoot($root->publicRoot(), $filename, $at);
}

public static function inPublicRoot(
PublicRoot $root,
string|Filename $filename, // TODO: convert to class
string|Path $at = ''
Filename $filename,
Path $at
): self {
if (is_string($filename)) {
$filename = Filename::fromString($filename);
}

if (is_string($at)) {
$at = Path::fromString($at);
}
return new self($root, $filename, $at);
}

Expand Down
28 changes: 10 additions & 18 deletions src/FileSystem/Files/PublicMetaFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Eightfold\Amos\Php\Interfaces\Stringable;

use Eightfold\Amos\FileSystem\Path;
use Eightfold\Amos\FileSystem\Filename;

use Eightfold\Amos\FileSystem\Directories\Root;
use Eightfold\Amos\FileSystem\Directories\PublicRoot;
Expand All @@ -17,29 +18,20 @@ final class PublicMetaFile implements Findable, Stringable
{
private const FILENAME = 'meta.json';

public static function inRoot(
Root $root,
string|Path $at = ''
): self {
public static function inRoot(Root $root, Path $at): self
{
return self::inPublicRoot($root->publicRoot(), $at);
}

public static function inPublicRoot(
PublicRoot $root,
string|Path $at = ''
): self {
if (is_string($at)) {
$at = Path::fromString($at);
}

return new self(
PublicFile::inPublicRoot($root, self::FILENAME, $at)
);
public static function inPublicRoot(PublicRoot $root, Path $at): self
{
$filename = Filename::fromString(self::FILENAME);
$pFile = PublicFile::inPublicRoot($root, $filename, $at);
return new self($pFile);
}

private function __construct(
private readonly PublicFile $publicFile
) {
private function __construct(private readonly PublicFile $publicFile)
{
}

public function notFound(): bool
Expand Down
14 changes: 14 additions & 0 deletions src/FileSystem/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ public function parts(): array
);
}

public function toStringWithTrailingSlash(): string
{
$base = $this->toString();
if ($base === '/') {
return '/';
}

if (str_ends_with($base, '/')) {
return $base;
}

return $base . '/';
}

public function toString(): string
{
return $this->path;
Expand Down
11 changes: 3 additions & 8 deletions src/ObjectsFromJson/PrivateObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Eightfold\Amos\Php\Interfaces\Findable;

use Eightfold\Amos\FileSystem\Path;
use Eightfold\Amos\FileSystem\Filename;

use Eightfold\Amos\FileSystem\Directories\Root;
use Eightfold\Amos\PlainText\PrivateJson as PlainTextPrivateJson;
Expand All @@ -17,14 +18,8 @@ final class PrivateObject implements Findable
{
private StdClass $object;

public static function inRoot(
Root $root,
string $filename,
string|Path $at = ''
): self {
if (is_string($at)) {
$at = Path::fromString($at);
}
public static function inRoot(Root $root, Filename $filename, Path $at): self
{
return new self(
PlainTextPrivateJson::inRoot($root, $filename, $at)
);
Expand Down
9 changes: 2 additions & 7 deletions src/ObjectsFromJson/PublicMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@ final class PublicMeta implements Findable
{
private StdClass $object;

public static function inRoot(
Root $root,
string|Path $at = ''
): self {
if (is_string($at)) {
$at = Path::fromString($at);
}
public static function inRoot(Root $root, Path $at): self
{
return new self(
PlainTextPublicMeta::inRoot($root, $at)
);
Expand Down
11 changes: 3 additions & 8 deletions src/ObjectsFromJson/PublicObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Eightfold\Amos\Php\Interfaces\Findable;

use Eightfold\Amos\FileSystem\Path;
use Eightfold\Amos\FileSystem\Filename;

use Eightfold\Amos\FileSystem\Directories\Root;
use Eightfold\Amos\PlainText\PublicJson as PlainTextPublicJson;
Expand All @@ -17,14 +18,8 @@ final class PublicObject implements Findable
{
private StdClass $object;

public static function inRoot(
Root $root,
string $filename,
string|Path $at = ''
): self {
if (is_string($at)) {
$at = Path::fromString($at);
}
public static function inRoot(Root $root, Filename $filename, Path $at): self
{
return new self(
PlainTextPublicJson::inRoot($root, $filename, $at)
);
Expand Down
12 changes: 4 additions & 8 deletions src/PlainText/PrivateFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,19 @@
namespace Eightfold\Amos\PlainText;

use Eightfold\Amos\FileSystem\Path;
use Eightfold\Amos\FileSystem\Filename;

use Eightfold\Amos\FileSystem\Directories\Root;

use Eightfold\Amos\FileSystem\Files\PrivateFile as FileSystemPrivateFile;

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

final class PrivateFile implements Findable, Stringable
{
public static function inRoot(
Root $root,
string $filename,
string|Path $at = ''
): self {
if (is_string($at)) {
$at = Path::fromString($at);
}
public static function inRoot(Root $root, Filename $filename, Path $at): self
{
return new self(
FileSystemPrivateFile::inRoot($root, $filename, $at)
);
Expand Down
12 changes: 4 additions & 8 deletions src/PlainText/PrivateJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,19 @@
namespace Eightfold\Amos\PlainText;

use Eightfold\Amos\FileSystem\Path;
use Eightfold\Amos\FileSystem\Filename;

use Eightfold\Amos\FileSystem\Directories\Root;

use Eightfold\Amos\FileSystem\Files\PrivateFile;

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

final class PrivateJson implements Findable, Stringable
{
public static function inRoot(
Root $root,
string $filename,
string|Path $at = ''
): self {
if (is_string($at)) {
$at = Path::fromString($at);
}
public static function inRoot(Root $root, Filename $filename, Path $at): self
{
return new self(
PrivateFile::inRoot($root, $filename, $at)
);
Expand Down
Loading

0 comments on commit 85fa3b7

Please sign in to comment.