Skip to content

Commit 9de0c28

Browse files
committed
fix: initialize view composers through container to allow DI
1 parent e528afa commit 9de0c28

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/classes/Common/View/ViewComposerRepository.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace DoWStarterTheme\Common\View;
66

77
use DoWStarterTheme\Common\Config\Config;
8+
use DoWStarterTheme\Deps\DI\Container;
89

910
/**
1011
* View Composer Repository class
@@ -28,10 +29,12 @@ class ViewComposerRepository
2829
/**
2930
* Class constructor.
3031
*
31-
* @param Config $config Config instance.
32+
* @param Config $config Config instance.
33+
* @param Container $container Container instance.
3234
*/
3335
public function __construct(
3436
private Config $config,
37+
private Container $container,
3538
) {
3639
$this->registerComposers();
3740
}
@@ -83,8 +86,7 @@ private function mapComposerToViews(string $composer): void
8386
private function getComposer(string $composer): ViewComposer
8487
{
8588
if (! isset($this->composers[$composer])) {
86-
// phpcs:ignore NeutronStandard.Functions.VariableFunctions.VariableFunction
87-
$this->composers[$composer] = new $composer();
89+
$this->composers[$composer] = $this->container->get($composer);
8890
}
8991

9092
return $this->composers[$composer];

0 commit comments

Comments
 (0)