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

[2.x] Discover authors when booting the kernel #1846

Closed
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public function boot(): void
$callback($this);
}

// Todo: Move to extension callback
$this->bootAuthors();

$this->booting = false;
$this->booted = true;
}
Expand Down
20 changes: 9 additions & 11 deletions packages/framework/src/Foundation/Concerns/HasKernelData.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,9 @@ trait HasKernelData
*/
public function authors(): Collection
{
if (isset($this->authors)) {
return $this->authors;
}
$this->needsToBeBooted();

$config = collect(Config::getArray('hyde.authors', []));

if ($config->isEmpty()) {
// Defer setting the authors property until the next try.
return $config;
}

return $this->authors = $this->parseConfigurationAuthors($config);
return $this->authors;
}

protected function parseConfigurationAuthors(Collection $authors): Collection
Expand All @@ -62,4 +53,11 @@ protected function parseConfigurationAuthors(Collection $authors): Collection
return [$username => PostAuthor::create($author)];
});
}

protected function bootAuthors(): void
{
$config = collect(Config::getArray('hyde.authors', []));

$this->authors = $this->parseConfigurationAuthors($config);
}
}
6 changes: 1 addition & 5 deletions packages/framework/tests/Feature/HydeKernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,14 +568,10 @@ public function testAuthorsReturnsEmptyCollectionWhenNoAuthorsDefined()
$this->assertEmpty($kernel->authors());
}

public function testAuthorsPropertyIsNotWrittenUntilThereAreAuthorsDefined()
public function testAuthorsPropertyWrittenWhenThereAreAuthorsDefined()
{
$kernel = new HydeKernel();

Config::set('hyde', []);

$this->assertEmpty($kernel->authors()->toArray());

Config::set('hyde.authors', ['foo' => Author::create('foo')]);

$this->assertNotEmpty($kernel->authors()->toArray());
Expand Down
Loading