Skip to content

Commit

Permalink
Merge pull request #30 from 8fold/rebuild
Browse files Browse the repository at this point in the history
fix: Site to use HTTP Root
  • Loading branch information
joshbruce authored May 22, 2023
2 parents ad2a9ed + c028406 commit 6794417
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
18 changes: 10 additions & 8 deletions src/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@

use Eightfold\Amos\SiteInterface;

use Eightfold\Amos\FileSystem\Directories\Root;
use Eightfold\Amos\FileSystem\Directories\Root as ContentRoot;
use Eightfold\Amos\FileSystem\Directories\PublicRoot;

use Eightfold\Amos\Http\Root as HttpRoot;

use Eightfold\Amos\ObjectsFromJson\PublicMeta;
use Eightfold\Amos\PlainText\PublicContent;
use Eightfold\Amos\PlainText\PublicFile;

class Site implements SiteInterface
{
private Root $file_system_root;
private ContentRoot $file_system_root;

private PublicRoot $file_system_public_root;

Expand All @@ -29,8 +31,8 @@ class Site implements SiteInterface
private array $publicContents = [];

public static function init(
Root $fileSystemRoot,
string $domain
ContentRoot $fileSystemRoot,
HttpRoot $domain
): self|false {
if ($fileSystemRoot->notFound()) {
return false;
Expand All @@ -39,17 +41,17 @@ public static function init(
}

final private function __construct(
private readonly Root $fileSystemRoot,
private readonly string $domain
private readonly ContentRoot $fileSystemRoot,
private readonly HttpRoot $domain
) {
}

public function domain(): string
public function domain(): HttpRoot
{
return $this->domain;
}

public function contentRoot(): Root
public function contentRoot(): ContentRoot
{
if (isset($this->file_system_root) === false) {
$this->file_system_root = $this->fileSystemRoot;
Expand Down
12 changes: 7 additions & 5 deletions src/SiteInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@

use Psr\Http\Message\RequestInterface;

use Eightfold\Amos\FileSystem\Directories\Root;
use Eightfold\Amos\FileSystem\Directories\Root as ContentRoot;
use Eightfold\Amos\FileSystem\Directories\PublicRoot;

use Eightfold\Amos\Http\Root as HttpRoot;

use Eightfold\Amos\ObjectsFromJson\PublicMeta;
use Eightfold\Amos\PlainText\PublicContent;

interface SiteInterface
{
public static function init(
Root $fileSystemRoot,
string $domain
ContentRoot $fileSystemRoot,
HttpRoot $domain
): self|false;

public function domain(): string;
public function domain(): HttpRoot;

public function contentRoot(): Root;
public function contentRoot(): ContentRoot;

public function publicRoot(): PublicRoot;

Expand Down
2 changes: 1 addition & 1 deletion tests/Http/RootTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function can_accept_valid_uri(): void
parent::request()
);

$expected = parent::domain();
$expected = parent::domain()->toString();

$this->assertSame(
$expected,
Expand Down
4 changes: 2 additions & 2 deletions tests/SiteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public function has_public_meta(): void
*/
public function has_expected_domain(): void
{
$expected = $this->domain();
$expected = $this->domain()->toString();

$result = $this->site()->domain();
$result = $this->site()->domain()->toString();

$this->assertSame(
$expected,
Expand Down
16 changes: 9 additions & 7 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

use Nyholm\Psr7\ServerRequest;

use Eightfold\Amos\FileSystem\Directories\Root;
use Eightfold\Amos\FileSystem\Directories\Root as ContentRoot;
use Eightfold\Amos\FileSystem\Directories\PublicRoot;

use Eightfold\Amos\Http\Root as HttpRoot;

class TestCase extends BaseTestCase
{
protected const BASE = __DIR__ . '/test-content';
Expand All @@ -22,14 +24,14 @@ class TestCase extends BaseTestCase

protected const PUBLIC_BASE = self::BASE . '/public';

protected function root(): Root
protected function root(): ContentRoot
{
return Root::fromString(self::BASE);
return ContentRoot::fromString(self::BASE);
}

protected function nonexistentRoot(): Root
protected function nonexistentRoot(): ContentRoot
{
return Root::fromString(self::NONEXISTENT_BASE);
return ContentRoot::fromString(self::NONEXISTENT_BASE);
}

protected function publicRoot(): PublicRoot
Expand All @@ -50,8 +52,8 @@ protected function request(string $path = '/'): ServerRequest
return new ServerRequest('get', $this->domain() . $path);
}

protected function domain(): string
protected function domain(): HttpRoot
{
return 'http://ex.ample';
return HttpRoot::fromString('http://ex.ample');
}
}

0 comments on commit 6794417

Please sign in to comment.