Skip to content

Commit

Permalink
Merge pull request #40 from 8fold/initialize-site-with-request
Browse files Browse the repository at this point in the history
add: initWithRequest
  • Loading branch information
joshbruce authored Jan 21, 2024
2 parents 85fa3b7 + 7776382 commit a6d5549
Showing 1 changed file with 30 additions and 9 deletions.
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

0 comments on commit a6d5549

Please sign in to comment.