Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: initWithRequest #40

Merged
merged 2 commits into from
Jan 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions src/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Eightfold\Amos;

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\UriInterface;

use Eightfold\Amos\SiteInterface;
Expand All @@ -21,9 +22,9 @@

class Site implements SiteInterface
{
private ContentRoot $file_system_root;
private PublicRoot $fileSystemPublicRoot;

private PublicRoot $file_system_public_root;
private RequestInterface|false $request = false;

/**
* @var array<string, PublicMeta>
Expand All @@ -35,6 +36,18 @@ class Site implements SiteInterface
*/
private array $publicContents = [];

public static function initWithRequest(
ContentRoot $fileSystemRoot,
HttpRoot $domain,
RequestInterface $request
): self|false {
$self = self::init($fileSystemRoot, $domain);
if ($self === false) {
return false;
}
return $self->withRequest($request);
}

public static function init(
ContentRoot $fileSystemRoot,
HttpRoot $domain
Expand All @@ -58,20 +71,28 @@ public function domain(): HttpRoot

public function contentRoot(): ContentRoot
{
if (isset($this->file_system_root) === false) {
$this->file_system_root = $this->fileSystemRoot;
}
return $this->file_system_root;
return $this->fileSystemRoot;
}

public function publicRoot(): PublicRoot
{
if (isset($this->file_system_public_root) === false) {
$this->file_system_public_root = PublicRoot::inRoot(
if (isset($this->fileSystemPublicRoot) === false) {
$this->fileSystemPublicRoot = PublicRoot::inRoot(
$this->contentRoot()
);
}
return $this->file_system_public_root;
return $this->fileSystemPublicRoot;
}

public function request(): RequestInterface|false
{
return $this->request;
}

public function withRequest(RequestInterface $request): self
{
$this->request = $request;
return $this;
}

public function hasPublicMeta(Path $at): bool
Expand Down
Loading