Skip to content

Commit

Permalink
[v1.1.3] fix xml config renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Calef committed Nov 17, 2023
1 parent 6cea7f6 commit 1969793
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
28 changes: 14 additions & 14 deletions Model/ConfigRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@
class ConfigRequest
{
/** @var string */
public const REST_API_SERVICE_BASE_URI = 'rest_api/%s/base_uri';
public const XML_CONFIG_REST_API_SERVICE_BASE_URI = 'rest_api/%s/base_uri';

/** @var string */
public const REST_API_SERVICE_TIMEOUT = 'rest_api/%s/timeout';
public const XML_CONFIG_REST_API_SERVICE_TIMEOUT = 'rest_api/%s/timeout';

/** @var string */
public const REST_API_SERVICE_IS_DEBUG = 'rest_api/%s/is_debug';
public const XML_CONFIG_REST_API_SERVICE_IS_DEBUG = 'rest_api/%s/is_debug';

/** @var string */
public const REST_API_SERVICE_CACHE_TTL = 'rest_api/%s/cache_ttl';
public const XML_CONFIG_REST_API_SERVICE_CACHE_TTL = 'rest_api/%s/cache_ttl';

/** @var string */
public const REST_API_DEFAULT_IS_FORCE_DEBUG = 'rest_api/default/is_force_debug';
public const XML_CONFIG_REST_API_GENERAL_IS_FORCE_DEBUG = 'rest_api/general/is_force_debug';

/** @var string */
public const REST_API_CONFIG_DEFAULT = 'general';
public const XML_CONFIG_REST_API_GROUP_GENERAL = 'general';

public function __construct(
private ScopeConfigInterface $scopeConfig,
Expand All @@ -48,7 +48,7 @@ public function __construct(
public function getBaseUri(): string
{
return $this->scopeConfig->getValue(
sprintf(self::REST_API_SERVICE_BASE_URI, $this->configName)
sprintf(self::XML_CONFIG_REST_API_SERVICE_BASE_URI, $this->configName)
);
}

Expand All @@ -58,11 +58,11 @@ public function getBaseUri(): string
public function getTimeout(): int
{
$timeout = $this->scopeConfig->getValue(
sprintf(self::REST_API_SERVICE_TIMEOUT, $this->configName)
sprintf(self::XML_CONFIG_REST_API_SERVICE_TIMEOUT, $this->configName)
);
if ($timeout === null) {
$timeout = $this->scopeConfig->getValue(
sprintf(self::REST_API_SERVICE_TIMEOUT, self::REST_API_CONFIG_DEFAULT)
sprintf(self::XML_CONFIG_REST_API_SERVICE_TIMEOUT, self::XML_CONFIG_REST_API_GROUP_GENERAL)
);
}

Expand All @@ -75,11 +75,11 @@ public function getTimeout(): int
public function getCacheLifetime(): int
{
$cacheLifetime = $this->scopeConfig->getValue(
sprintf(self::REST_API_SERVICE_CACHE_TTL, $this->configName)
sprintf(self::XML_CONFIG_REST_API_SERVICE_CACHE_TTL, $this->configName)
);
if ($cacheLifetime === null) {
$cacheLifetime = $this->scopeConfig->getValue(
sprintf(self::REST_API_SERVICE_CACHE_TTL, self::REST_API_CONFIG_DEFAULT)
sprintf(self::XML_CONFIG_REST_API_SERVICE_CACHE_TTL, self::XML_CONFIG_REST_API_GROUP_GENERAL)
);
}

Expand All @@ -91,16 +91,16 @@ public function getCacheLifetime(): int
*/
public function isDebugEnabled(): bool
{
if ($this->scopeConfig->isSetFlag(self::REST_API_DEFAULT_IS_FORCE_DEBUG)) {
if ($this->scopeConfig->isSetFlag(self::XML_CONFIG_REST_API_GENERAL_IS_FORCE_DEBUG)) {
return true;
}

$debugEnabled = $this->scopeConfig->getValue(
sprintf(self::REST_API_SERVICE_IS_DEBUG, $this->configName)
sprintf(self::XML_CONFIG_REST_API_SERVICE_IS_DEBUG, $this->configName)
);
if ($debugEnabled === null) {
$debugEnabled = $this->scopeConfig->getValue(
sprintf(self::REST_API_SERVICE_IS_DEBUG, self::REST_API_CONFIG_DEFAULT)
sprintf(self::XML_CONFIG_REST_API_SERVICE_IS_DEBUG, self::XML_CONFIG_REST_API_GROUP_GENERAL)
);
}

Expand Down
4 changes: 2 additions & 2 deletions Service/ApiProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(
private ConfigRequestFactory $configRequestFactory,
private SerializerInterface $serializer,
private RequestAdapter $requestAdapter,
private string $configName = ConfigRequest::REST_API_CONFIG_DEFAULT,
private string $configName = ConfigRequest::XML_CONFIG_REST_API_GROUP_GENERAL,
private string $method = Request::METHOD_GET,
private bool $isVerify = true,
private bool $isJsonRequest = true,
Expand Down Expand Up @@ -100,7 +100,7 @@ protected function buildParameters(string $serviceName): ParametersInterface
*/
protected function buildConfigRequest(): ConfigRequest
{
if ($this->getConfigName() === ConfigRequest::REST_API_CONFIG_DEFAULT) {
if ($this->getConfigName() === ConfigRequest::XML_CONFIG_REST_API_GROUP_GENERAL) {
throw new LogicException(__('ConfigName parameter is missing and must be injected'));
}

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "zepgram/module-rest",
"description": "Technical module to industrialize API REST call with dependency injection pattern using Guzzle library in Magento 2",
"description": "Technical module to industrialize API REST call with dependency injection pattern using Guzzle library",
"type": "magento2-module",
"version": "1.1.2",
"version": "1.1.3",
"authors": [
{
"name": "Benjamin Calef",
Expand Down

0 comments on commit 1969793

Please sign in to comment.