Skip to content

Commit c9711fe

Browse files
committed
OXDEV-8947 Segregate the ModuleSettingsInterface into more concrete settings
Signed-off-by: Anton Fedurtsya <anton@fedurtsya.com>
1 parent 0e16e75 commit c9711fe

21 files changed

Lines changed: 314 additions & 233 deletions

services.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ imports:
66
- { resource: src/Greeting/services.yaml }
77
- { resource: src/Logging/services.yaml }
88
- { resource: src/ProductVote/services.yaml }
9-
- { resource: src/Settings/services.yaml }
109
- { resource: src/Tracker/services.yaml }
1110

1211
services:

src/Extension/Controller/StartController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
use OxidEsales\Eshop\Application\Model\User as EshopModelUser;
1313
use OxidEsales\ExamplesModule\Greeting\Service\GreetingMessageServiceInterface;
14-
use OxidEsales\ExamplesModule\Settings\Service\ModuleSettingsServiceInterface;
14+
use OxidEsales\ExamplesModule\Greeting\Settings\GreetingSettingsInterface;
1515

1616
/**
1717
* @eshopExtension
@@ -55,9 +55,9 @@ public function getOeemGreeting(): string
5555

5656
public function canUpdateOeemGreeting(): bool
5757
{
58-
$moduleSettings = $this->getService(ModuleSettingsServiceInterface::class);
58+
$greetingSettings = $this->getService(GreetingSettingsInterface::class);
5959

6060
/** @phpstan-ignore-next-line */
61-
return is_a($this->getUser(), EshopModelUser::class) && $moduleSettings->isPersonalGreetingMode();
61+
return is_a($this->getUser(), EshopModelUser::class) && $greetingSettings->isPersonalGreetingMode();
6262
}
6363
}

src/Greeting/Controller/GreetingController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use OxidEsales\ExamplesModule\Extension\Model\User as ExamplesModelUser;
1616
use OxidEsales\ExamplesModule\Extension\Model\UserInterface;
1717
use OxidEsales\ExamplesModule\Greeting\Service\GreetingMessageServiceInterface;
18-
use OxidEsales\ExamplesModule\Settings\Service\ModuleSettingsServiceInterface;
18+
use OxidEsales\ExamplesModule\Greeting\Settings\GreetingSettingsInterface;
1919
use OxidEsales\ExamplesModule\Tracker\Infrastructure\Repository\TrackerRepositoryInterface;
2020

2121
use function PHPUnit\Framework\isInstanceOf;
@@ -37,7 +37,7 @@ class GreetingController extends FrontendController
3737
protected $_sThisTemplate = '@oe_examples_module/templates/greetingtemplate';
3838

3939
public function __construct(
40-
private readonly ModuleSettingsServiceInterface $moduleSettings,
40+
private readonly GreetingSettingsInterface $greetingSettings,
4141
private readonly TrackerRepositoryInterface $trackerRepository,
4242
private readonly GreetingMessageServiceInterface $greetingService,
4343
) {
@@ -58,7 +58,7 @@ public function render()
5858
if (
5959
$user instanceof UserInterface
6060
&& !empty($user->getId())
61-
&& $this->moduleSettings->isPersonalGreetingMode()
61+
&& $this->greetingSettings->isPersonalGreetingMode()
6262
) {
6363
$greeting = $user->getPersonalGreeting();
6464
$tracker = $this->trackerRepository->getTrackerByUserId($user->getId());
@@ -83,7 +83,7 @@ public function updateGreeting(): void
8383
$user = $this->getUser();
8484

8585
/** @phpstan-ignore-next-line */
86-
if (is_a($user, EshopModelUser::class) && $this->moduleSettings->isPersonalGreetingMode()) {
86+
if (is_a($user, EshopModelUser::class) && $this->greetingSettings->isPersonalGreetingMode()) {
8787
$this->greetingService->saveGreeting($user);
8888
}
8989
}

src/Greeting/Service/GreetingMessageService.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
use OxidEsales\Eshop\Core\Request as EshopRequest;
1515
use OxidEsales\ExamplesModule\Core\Module as ModuleCore;
1616
use OxidEsales\ExamplesModule\Extension\Model\User as ExamplesModelUser;
17-
use OxidEsales\ExamplesModule\Settings\Service\ModuleSettingsServiceInterface;
17+
use OxidEsales\ExamplesModule\Greeting\Settings\GreetingSettingsInterface;
1818

1919
readonly class GreetingMessageService implements GreetingMessageServiceInterface
2020
{
2121
public function __construct(
22-
private ModuleSettingsServiceInterface $moduleSettings,
22+
private GreetingSettingsInterface $greetingSettings,
2323
private EshopRequest $shopRequest,
2424
private EshopLanguage $shopLanguage,
2525
private ?string $shopName,
@@ -35,7 +35,7 @@ public function getGreeting(?EshopModelUser $user = null): string
3535
{
3636
$result = ModuleCore::DEFAULT_PERSONAL_GREETING_LANGUAGE_CONST;
3737

38-
if (ModuleSettingsServiceInterface::GREETING_MODE_PERSONAL == $this->moduleSettings->getGreetingMode()) {
38+
if (GreetingSettingsInterface::GREETING_MODE_PERSONAL == $this->greetingSettings->getGreetingMode()) {
3939
$result = $this->getUserGreeting($user);
4040
}
4141

src/Settings/Service/ModuleSettingsService.php renamed to src/Greeting/Settings/GreetingSettings.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
declare(strict_types=1);
99

10-
namespace OxidEsales\ExamplesModule\Settings\Service;
10+
namespace OxidEsales\ExamplesModule\Greeting\Settings;
1111

1212
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
1313
use OxidEsales\ExamplesModule\Core\Module;
1414

1515
/**
1616
* @extendable-class
1717
*/
18-
readonly class ModuleSettingsService implements ModuleSettingsServiceInterface
18+
readonly class GreetingSettings implements GreetingSettingsInterface
1919
{
2020
public const GREETING_MODE_VALUES = [
2121
self::GREETING_MODE_GENERIC,
@@ -43,9 +43,4 @@ public function saveGreetingMode(string $value): void
4343
{
4444
$this->moduleSettingService->saveString(self::GREETING_MODE, $value, Module::MODULE_ID);
4545
}
46-
47-
public function isLoggingEnabled(): bool
48-
{
49-
return $this->moduleSettingService->getBoolean(self::LOGGER_STATUS, Module::MODULE_ID);
50-
}
5146
}

src/Settings/Service/ModuleSettingsServiceInterface.php renamed to src/Greeting/Settings/GreetingSettingsInterface.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,19 @@
77

88
declare(strict_types=1);
99

10-
namespace OxidEsales\ExamplesModule\Settings\Service;
10+
namespace OxidEsales\ExamplesModule\Greeting\Settings;
1111

12-
interface ModuleSettingsServiceInterface
12+
interface GreetingSettingsInterface
1313
{
1414
public const GREETING_MODE = 'oeexamplesmodule_GreetingMode';
1515

1616
public const GREETING_MODE_GENERIC = 'generic';
1717

1818
public const GREETING_MODE_PERSONAL = 'personal';
1919

20-
public const LOGGER_STATUS = 'oeexamplesmodule_LoggerEnabled';
21-
2220
public function isPersonalGreetingMode(): bool;
2321

2422
public function getGreetingMode(): string;
2523

2624
public function saveGreetingMode(string $value): void;
27-
28-
public function isLoggingEnabled(): bool;
2925
}

src/Greeting/services.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ services:
99
OxidEsales\Eshop\Core\Request: '@=service("OxidEsales\\ExamplesModule\\Core\\Registry").getRequest()'
1010
OxidEsales\Eshop\Core\Language: '@=service("OxidEsales\\ExamplesModule\\Core\\Registry").getLang()'
1111

12+
OxidEsales\ExamplesModule\Greeting\Settings\GreetingSettingsInterface:
13+
class: OxidEsales\ExamplesModule\Greeting\Settings\GreetingSettings
14+
public: true
15+
1216
OxidEsales\ExamplesModule\Greeting\Service\GreetingMessageServiceInterface:
1317
class: OxidEsales\ExamplesModule\Greeting\Service\GreetingMessageService
1418
arguments:

src/Logging/Service/BasketProductLoggerService.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace OxidEsales\ExamplesModule\Logging\Service;
1111

12-
use OxidEsales\ExamplesModule\Settings\Service\ModuleSettingsServiceInterface;
12+
use OxidEsales\ExamplesModule\Logging\Settings\LoggingSettingsInterface;
1313
use Psr\Log\LoggerInterface as PsrLoggerInterface;
1414

1515
/**
@@ -21,13 +21,13 @@
2121

2222
public function __construct(
2323
private PsrLoggerInterface $logger,
24-
private ModuleSettingsServiceInterface $moduleSettingService,
24+
private LoggingSettingsInterface $loggingSettings,
2525
) {
2626
}
2727

2828
public function log(string $productID): void
2929
{
30-
if ($this->moduleSettingService->isLoggingEnabled()) {
30+
if ($this->loggingSettings->isLoggingEnabled()) {
3131
$message = sprintf(self::MESSAGE, $productID);
3232
$this->logger->info($message);
3333
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/**
4+
* Copyright © . All rights reserved.
5+
* See LICENSE file for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace OxidEsales\ExamplesModule\Logging\Settings;
11+
12+
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
13+
use OxidEsales\ExamplesModule\Core\Module;
14+
15+
/**
16+
* @extendable-class
17+
*/
18+
readonly class LoggingSettings implements LoggingSettingsInterface
19+
{
20+
public function __construct(
21+
private ModuleSettingServiceInterface $moduleSettingService,
22+
) {
23+
}
24+
25+
public function isLoggingEnabled(): bool
26+
{
27+
return $this->moduleSettingService->getBoolean(self::LOGGER_STATUS, Module::MODULE_ID);
28+
}
29+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/**
4+
* Copyright © . All rights reserved.
5+
* See LICENSE file for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace OxidEsales\ExamplesModule\Logging\Settings;
11+
12+
interface LoggingSettingsInterface
13+
{
14+
public const LOGGER_STATUS = 'oeexamplesmodule_LoggerEnabled';
15+
16+
public function isLoggingEnabled(): bool;
17+
}

0 commit comments

Comments
 (0)