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

Ensure $boltConfig is set for Controllers in extensions #1527

Merged
merged 2 commits into from
Jun 22, 2020
Merged
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
6 changes: 6 additions & 0 deletions src/Extension/ExtensionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@

namespace Bolt\Extension;

use Bolt\Configuration\Config;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class ExtensionController extends AbstractController
{
use ServicesTrait;
use ConfigTrait;

public function __construct(Config $config)
{
$this->boltConfig = $config;
}
}
9 changes: 8 additions & 1 deletion src/Extension/ServicesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ trait ServicesTrait
/** @var Query */
protected $query;

/** @var Config */
protected $boltConfig;

/**
* Injects commonly used objects into the extension, for use by the
* extension. Called from the listener.
Expand Down Expand Up @@ -103,7 +106,11 @@ public function getWidgets(): ?Widgets

public function getBoltConfig(): Config
{
return $this->getService(\Bolt\Configuration\Config::class);
if (! $this->boltConfig instanceof Config) {
$this->boltConfig = $this->getService(\Bolt\Configuration\Config::class);
}

return $this->boltConfig;
}

public function getTwig(): Environment
Expand Down