Skip to content

Commit af51207

Browse files
committed
Fix Dependency Injection
1 parent 3ec940f commit af51207

File tree

5 files changed

+35
-17
lines changed

5 files changed

+35
-17
lines changed

Classes/Controller/SearchController.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,13 @@
4040
use TYPO3\CMS\Extbase\Http\ForwardResponse;
4141
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
4242
use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException;
43+
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
4344

4445
class SearchController extends ActionController
4546
{
4647
protected array $requestArguments = [];
4748

48-
protected ?ServiceProviderInterface $searchProvider = null;
49-
50-
public function __construct(private readonly AssetCollector $assetCollector, private readonly LoggerInterface $logger, private readonly PageTitleProviderInterface $pageTitleProvider) {}
49+
public function __construct(private readonly AssetCollector $assetCollector, private readonly ServiceProviderInterface $searchProvider, private readonly PageTitleProviderInterface $pageTitleProvider) {}
5150

5251
/**
5352
* @throws NoSuchArgumentException|\JsonException
@@ -155,14 +154,11 @@ protected function addStandardAssignments(): void
155154
protected function initializeConnection(string $activeConnection): void
156155
{
157156
$connectionConfiguration = $this->settings['connections'][$activeConnection];
158-
157+
$this->searchProvider->setConnectionName($activeConnection);
158+
$this->searchProvider->setSettings($this->settings);
159+
$this->searchProvider->setConnectionSettings($connectionConfiguration['provider']);
159160
/* @var ServiceProviderInterface $searchProvider */
160-
$this->searchProvider = GeneralUtility::makeInstance(
161-
$connectionConfiguration['provider'],
162-
$activeConnection,
163-
$this->settings,
164-
$this->logger,
165-
);
161+
166162
$this->searchProvider->connect();
167163
}
168164
}

Classes/Service/ServiceProviderInterface.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ interface ServiceProviderInterface
3434
{
3535
public function connect();
3636

37+
public function setConnectionName(string $name): void;
38+
public function setSettings(array $settings): void;
39+
public function setConnectionSettings(string $settings): void;
40+
3741
public function getConfiguration();
3842

3943
public function getDefaultQuery();

Classes/Service/SolrServiceProvider.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
use Subugoe\Find\Utility\SettingsUtility;
4040
use Subugoe\Find\Utility\UpgradeUtility;
4141
use Symfony\Component\EventDispatcher\EventDispatcher;
42+
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
4243
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
4344

4445
/**
@@ -58,7 +59,26 @@ class SolrServiceProvider implements ServiceProviderInterface
5859

5960
protected array $requestArguments = [];
6061

61-
public function __construct(protected string $connectionName, protected array $settings, protected LoggerInterface $logger) {}
62+
protected string $connectionName;
63+
64+
private array $settings;
65+
66+
private string $connectionSettings;
67+
68+
public function setConnectionName(string $name): void
69+
{
70+
$this->connectionName = $name;
71+
}
72+
73+
public function setSettings(array $settings): void
74+
{
75+
$this->settings = $settings;
76+
}
77+
78+
public function setConnectionSettings(string $settings): void
79+
{
80+
$this->connectionSettings = $settings;
81+
}
6282

6383
public function getRequestArguments(): array
6484
{

Classes/ViewHelpers/Data/NewArrayViewHelper.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function initializeArguments(): void
5757
$this->registerArgument('omitEmptyFields', 'boolean', 'omits empty fields', false, false);
5858
}
5959

60-
public function render(): array
60+
public function render()
6161
{
6262
$result = $this->arguments['array'] ?? [];
6363

@@ -69,11 +69,6 @@ public function render(): array
6969
$result[$key] = $value;
7070
}
7171
}
72-
} else {
73-
$result = 'newArray View Helper: Number of keys and values must be the same.' . PHP_EOL . print_r(
74-
$this->arguments,
75-
true
76-
);
7772
}
7873
} else {
7974
foreach ($this->arguments['values'] as $value) {

Configuration/Services.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ services:
66

77
Subugoe\Find\:
88
resource: '../Classes/*'
9+
10+
Subugoe\Find\Service\ServiceProviderInterface:
11+
class: Subugoe\Find\Service\SolrServiceProvider

0 commit comments

Comments
 (0)