for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Hyde\Framework\Actions\Constructors;
use Hyde\Framework\Models\Author;
use Hyde\Framework\Models\Pages\MarkdownPost;
/**
* @internal
*/
class FindsAuthorForPost
{
public static function run(MarkdownPost $page): Author|null
return (new static($page))->findAuthorForPost();
}
protected function __construct(protected MarkdownPost $page)
protected function findAuthorForPost(): Author|null
if ($this->page->matter('author') !== null) {
if (is_string($this->page->matter('author'))) {
// If the author is a string, we assume it's a username,
// so we'll try to find the author in the config
return Author::get($this->page->matter('author'));
if (is_array($this->page->matter('author'))) {
// If the author is an array, we'll assume it's a user
// with one-off custom data, so we create a new author.
// In the future we may want to merge config data with custom data
return new Author($this->getUsername(), $this->page->matter('author'));
return null;
protected function getUsername(): string
return $this->page->matter('author')['username'] ?? $this->page->matter('author')['name'] ?? 'Guest';