Skip to content

Commit

Permalink
OXDEV-7646 Remove usage of ID in Theme setting chains
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Fedurtsya <anton@fedurtsya.com>
  • Loading branch information
Sieg committed Dec 4, 2023
1 parent 4ed1125 commit 6e68112
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 206 deletions.
29 changes: 14 additions & 15 deletions src/Setting/Controller/ThemeSettingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use TheCodingMachine\GraphQLite\Annotations\Mutation;
use TheCodingMachine\GraphQLite\Annotations\Query;
use TheCodingMachine\GraphQLite\Annotations\Right;
use TheCodingMachine\GraphQLite\Types\ID;

final class ThemeSettingController
{
Expand All @@ -33,7 +32,7 @@ public function __construct(
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function getThemeSettingInteger(ID $name, string $themeId): IntegerSetting
public function getThemeSettingInteger(string $name, string $themeId): IntegerSetting
{
return $this->themeSettingService->getIntegerSetting($name, $themeId);
}
Expand All @@ -42,7 +41,7 @@ public function getThemeSettingInteger(ID $name, string $themeId): IntegerSettin
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function getThemeSettingFloat(ID $name, string $themeId): FloatSetting
public function getThemeSettingFloat(string $name, string $themeId): FloatSetting
{
return $this->themeSettingService->getFloatSetting($name, $themeId);
}
Expand All @@ -51,7 +50,7 @@ public function getThemeSettingFloat(ID $name, string $themeId): FloatSetting
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function getThemeSettingBoolean(ID $name, string $themeId): BooleanSetting
public function getThemeSettingBoolean(string $name, string $themeId): BooleanSetting
{
return $this->themeSettingService->getBooleanSetting($name, $themeId);
}
Expand All @@ -60,7 +59,7 @@ public function getThemeSettingBoolean(ID $name, string $themeId): BooleanSettin
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function getThemeSettingString(ID $name, string $themeId): StringSetting
public function getThemeSettingString(string $name, string $themeId): StringSetting
{
return $this->themeSettingService->getStringSetting($name, $themeId);
}
Expand All @@ -69,7 +68,7 @@ public function getThemeSettingString(ID $name, string $themeId): StringSetting
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function getThemeSettingSelect(ID $name, string $themeId): StringSetting
public function getThemeSettingSelect(string $name, string $themeId): StringSetting
{
return $this->themeSettingService->getSelectSetting($name, $themeId);
}
Expand All @@ -78,7 +77,7 @@ public function getThemeSettingSelect(ID $name, string $themeId): StringSetting
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function getThemeSettingCollection(ID $name, string $themeId): StringSetting
public function getThemeSettingCollection(string $name, string $themeId): StringSetting
{
return $this->themeSettingService->getCollectionSetting($name, $themeId);
}
Expand All @@ -87,7 +86,7 @@ public function getThemeSettingCollection(ID $name, string $themeId): StringSett
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function getThemeSettingAssocCollection(ID $name, string $themeId): StringSetting
public function getThemeSettingAssocCollection(string $name, string $themeId): StringSetting
{
return $this->themeSettingService->getAssocCollectionSetting($name, $themeId);
}
Expand All @@ -108,7 +107,7 @@ public function getThemeSettingsList(string $themeId): array
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function changeThemeSettingInteger(ID $name, int $value, string $themeId): IntegerSetting
public function changeThemeSettingInteger(string $name, int $value, string $themeId): IntegerSetting
{
return $this->themeSettingService->changeIntegerSetting($name, $value, $themeId);
}
Expand All @@ -117,7 +116,7 @@ public function changeThemeSettingInteger(ID $name, int $value, string $themeId)
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function changeThemeSettingFloat(ID $name, float $value, string $themeId): FloatSetting
public function changeThemeSettingFloat(string $name, float $value, string $themeId): FloatSetting
{
return $this->themeSettingService->changeFloatSetting($name, $value, $themeId);
}
Expand All @@ -126,7 +125,7 @@ public function changeThemeSettingFloat(ID $name, float $value, string $themeId)
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function changeThemeSettingBoolean(ID $name, bool $value, string $themeId): BooleanSetting
public function changeThemeSettingBoolean(string $name, bool $value, string $themeId): BooleanSetting
{
return $this->themeSettingService->changeBooleanSetting($name, $value, $themeId);
}
Expand All @@ -135,7 +134,7 @@ public function changeThemeSettingBoolean(ID $name, bool $value, string $themeId
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function changeThemeSettingString(ID $name, string $value, string $themeId): StringSetting
public function changeThemeSettingString(string $name, string $value, string $themeId): StringSetting
{
return $this->themeSettingService->changeStringSetting($name, $value, $themeId);
}
Expand All @@ -144,7 +143,7 @@ public function changeThemeSettingString(ID $name, string $value, string $themeI
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function changeThemeSettingSelect(ID $name, string $value, string $themeId): StringSetting
public function changeThemeSettingSelect(string $name, string $value, string $themeId): StringSetting
{
return $this->themeSettingService->changeSelectSetting($name, $value, $themeId);
}
Expand All @@ -153,7 +152,7 @@ public function changeThemeSettingSelect(ID $name, string $value, string $themeI
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function changeThemeSettingCollection(ID $name, string $value, string $themeId): StringSetting
public function changeThemeSettingCollection(string $name, string $value, string $themeId): StringSetting
{
return $this->themeSettingService->changeCollectionSetting($name, $value, $themeId);
}
Expand All @@ -162,7 +161,7 @@ public function changeThemeSettingCollection(ID $name, string $value, string $th
#[Logged]
#[HideIfUnauthorized]
#[Right('CHANGE_CONFIGURATION')]
public function changeThemeSettingAssocCollection(ID $name, string $value, string $themeId): StringSetting
public function changeThemeSettingAssocCollection(string $name, string $value, string $themeId): StringSetting
{
return $this->themeSettingService->changeAssocCollectionSetting($name, $value, $themeId);
}
Expand Down
39 changes: 19 additions & 20 deletions src/Setting/Infrastructure/ThemeSettingRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use OxidEsales\GraphQL\ConfigurationAccess\Setting\Exception\NoSettingsFoundForThemeException;
use OxidEsales\GraphQL\ConfigurationAccess\Setting\Exception\WrongSettingValueException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use TheCodingMachine\GraphQLite\Types\ID;

class ThemeSettingRepository implements ThemeSettingRepositoryInterface
{
Expand All @@ -30,7 +29,7 @@ public function __construct(
) {
}

public function getInteger(ID $name, string $themeId): int
public function getInteger(string $name, string $themeId): int
{
$value = $this->getSettingValue($name, FieldType::NUMBER, $themeId);

Expand All @@ -49,7 +48,7 @@ private function matchesOnlyDigits(string $value): bool
return (bool)preg_match("/^\d+$/", $value);
}

public function getFloat(ID $name, string $themeId): float
public function getFloat(string $name, string $themeId): float
{
$value = $this->getSettingValue($name, FieldType::NUMBER, $themeId);

Expand All @@ -69,35 +68,35 @@ private function matchesFloatDigits(string $value): bool
return (bool)preg_match("/^\d+(\.\d+)?$/", $value);
}

public function getBoolean(ID $name, string $themeId): bool
public function getBoolean(string $name, string $themeId): bool
{
$value = $this->getSettingValue($name, FieldType::BOOLEAN, $themeId);

return (bool)$value;
}

public function getString(ID $name, string $themeId): string
public function getString(string $name, string $themeId): string
{
$value = $this->getSettingValue($name, FieldType::STRING, $themeId);

return (string)$value;
}

public function getSelect(ID $name, string $themeId): string
public function getSelect(string $name, string $themeId): string
{
$value = $this->getSettingValue($name, FieldType::SELECT, $themeId);

return (string)$value;
}

public function getCollection(ID $name, string $themeId): array
public function getCollection(string $name, string $themeId): array
{
$value = $this->getSettingValue($name, FieldType::ARRAY, $themeId);

return $this->getArrayFromSettingValue($value);
}

public function getAssocCollection(ID $name, string $themeId): array
public function getAssocCollection(string $name, string $themeId): array
{
$fieldType = FieldType::ASSOCIATIVE_ARRAY;
$value = $this->getSettingValue($name, $fieldType, $themeId);
Expand Down Expand Up @@ -150,7 +149,7 @@ public function getSettingsList(string $themeId): array
return $value;
}

public function saveIntegerSetting(ID $name, int $value, string $themeId): void
public function saveIntegerSetting(string $name, int $value, string $themeId): void
{
$this->getInteger($name, $themeId);

Expand All @@ -159,7 +158,7 @@ public function saveIntegerSetting(ID $name, int $value, string $themeId): void
$this->saveSettingValue($name, $themeId, (string)$value);
}

public function saveFloatSetting(ID $name, float $value, string $themeId): void
public function saveFloatSetting(string $name, float $value, string $themeId): void
{
$this->getFloat($name, $themeId);

Expand All @@ -168,7 +167,7 @@ public function saveFloatSetting(ID $name, float $value, string $themeId): void
$this->saveSettingValue($name, $themeId, (string)$value);
}

public function saveBooleanSetting(ID $name, bool $value, string $themeId): void
public function saveBooleanSetting(string $name, bool $value, string $themeId): void
{
$this->getBoolean($name, $themeId);

Expand All @@ -177,7 +176,7 @@ public function saveBooleanSetting(ID $name, bool $value, string $themeId): void
$this->saveSettingValue($name, $themeId, (string)$value);
}

public function saveStringSetting(ID $name, string $value, string $themeId): void
public function saveStringSetting(string $name, string $value, string $themeId): void
{
$this->getString($name, $themeId);

Expand All @@ -186,7 +185,7 @@ public function saveStringSetting(ID $name, string $value, string $themeId): voi
$this->saveSettingValue($name, $themeId, (string)$value);
}

public function saveSelectSetting(ID $name, string $value, string $themeId): void
public function saveSelectSetting(string $name, string $value, string $themeId): void
{
$this->getSelect($name, $themeId);

Expand All @@ -195,7 +194,7 @@ public function saveSelectSetting(ID $name, string $value, string $themeId): voi
$this->saveSettingValue($name, $themeId, (string)$value);
}

public function saveCollectionSetting(ID $name, array $value, string $themeId): void
public function saveCollectionSetting(string $name, array $value, string $themeId): void
{
$this->getCollection($name, $themeId);

Expand All @@ -204,7 +203,7 @@ public function saveCollectionSetting(ID $name, array $value, string $themeId):
$this->saveSettingValue($name, $themeId, (string)$value);
}

public function saveAssocCollectionSetting(ID $name, array $value, string $themeId): void
public function saveAssocCollectionSetting(string $name, array $value, string $themeId): void
{
$this->getAssocCollection($name, $themeId);

Expand All @@ -213,7 +212,7 @@ public function saveAssocCollectionSetting(ID $name, array $value, string $theme
$this->saveSettingValue($name, $themeId, (string)$value);
}

protected function getSettingValue(ID $name, string $fieldType, string $theme): mixed
protected function getSettingValue(string $name, string $fieldType, string $theme): mixed
{
$queryBuilder = $this->queryBuilderFactory->create();
$queryBuilder->select('c.oxvarvalue')
Expand All @@ -224,7 +223,7 @@ protected function getSettingValue(ID $name, string $fieldType, string $theme):
->andWhere('c.oxshopid = :shopId')
->setParameters([
'module' => 'theme:' . $theme,
'name' => $name->val(),
'name' => $name,
'type' => $fieldType,
'shopId' => $this->basicContext->getCurrentShopId(),
]);
Expand All @@ -240,7 +239,7 @@ protected function getSettingValue(ID $name, string $fieldType, string $theme):
return $this->shopSettingEncoder->decode($fieldType, $value);
}

protected function saveSettingValue(ID $name, string $themeId, string $value): void
protected function saveSettingValue(string $name, string $themeId, string $value): void
{
$shopId = $this->basicContext->getCurrentShopId();

Expand All @@ -253,7 +252,7 @@ protected function saveSettingValue(ID $name, string $themeId, string $value): v
->set('oxvarvalue', ':value')
->setParameters([
'shopId' => $shopId,
'name' => $name->val(),
'name' => $name,
'themeId' => 'theme:' . $themeId,
'value' => $value
]);
Expand All @@ -262,7 +261,7 @@ protected function saveSettingValue(ID $name, string $themeId, string $value): v

$this->eventDispatcher->dispatch(
new ThemeSettingChangedEvent(
(string)$name,
$name,
$shopId,
$themeId
)
Expand Down
30 changes: 14 additions & 16 deletions src/Setting/Infrastructure/ThemeSettingRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,38 @@

namespace OxidEsales\GraphQL\ConfigurationAccess\Setting\Infrastructure;

use TheCodingMachine\GraphQLite\Types\ID;

interface ThemeSettingRepositoryInterface
{
public function getInteger(ID $name, string $themeId): int;
public function getInteger(string $name, string $themeId): int;

public function getFloat(ID $name, string $themeId): float;
public function getFloat(string $name, string $themeId): float;

public function getBoolean(ID $name, string $themeId): bool;
public function getBoolean(string $name, string $themeId): bool;

public function getString(ID $name, string $themeId): string;
public function getString(string $name, string $themeId): string;

public function getSelect(ID $name, string $themeId): string;
public function getSelect(string $name, string $themeId): string;

public function getCollection(ID $name, string $themeId): array;
public function getCollection(string $name, string $themeId): array;

public function getAssocCollection(ID $name, string $themeId): array;
public function getAssocCollection(string $name, string $themeId): array;

/**
* @return array<string, string>
*/
public function getSettingsList(string $themeId): array;

public function saveIntegerSetting(ID $name, int $value, string $themeId): void;
public function saveIntegerSetting(string $name, int $value, string $themeId): void;

public function saveFloatSetting(ID $name, float $value, string $themeId): void;
public function saveFloatSetting(string $name, float $value, string $themeId): void;

public function saveBooleanSetting(ID $name, bool $value, string $themeId): void;
public function saveBooleanSetting(string $name, bool $value, string $themeId): void;

public function saveStringSetting(ID $name, string $value, string $themeId): void;
public function saveStringSetting(string $name, string $value, string $themeId): void;

public function saveSelectSetting(ID $name, string $value, string $themeId): void;
public function saveSelectSetting(string $name, string $value, string $themeId): void;

public function saveCollectionSetting(ID $name, array $value, string $themeId): void;
public function saveCollectionSetting(string $name, array $value, string $themeId): void;

public function saveAssocCollectionSetting(ID $name, array $value, string $themeId): void;
public function saveAssocCollectionSetting(string $name, array $value, string $themeId): void;
}
Loading

0 comments on commit 6e68112

Please sign in to comment.