-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from sitegeist/CHORE/refactor
CHORE: Refactor code as a result of testing
- Loading branch information
Showing
10 changed files
with
172 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
Classes/Infrastructure/DeepL/DeepLAuthenticationKeyFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Sitegeist\LostInTranslation\Infrastructure\DeepL; | ||
|
||
use InvalidArgumentException; | ||
use Neos\Flow\Annotations as Flow; | ||
|
||
/** | ||
* @Flow\Scope("singleton") | ||
*/ | ||
class DeepLAuthenticationKeyFactory | ||
{ | ||
/** | ||
* @var array{authenticationKey: string} | ||
* @Flow\InjectConfiguration(path="DeepLApi") | ||
*/ | ||
protected array $settings; | ||
|
||
/** | ||
* @Flow\Inject | ||
* @var DeepLCustomAuthenticationKeyService | ||
*/ | ||
protected $customAuthenticationKeyService; | ||
|
||
/** | ||
* @return DeepLAuthenticationKey | ||
*/ | ||
public function create(): DeepLAuthenticationKey | ||
{ | ||
$customKey = $this->customAuthenticationKeyService->get(); | ||
$settingsKey = $this->settings['authenticationKey'] ?? null; | ||
if (!isset($settingsKey) && !isset($customKey)) { | ||
throw new InvalidArgumentException('Empty strings are not allowed as authentication key'); | ||
} | ||
return new DeepLAuthenticationKey($customKey ?? $settingsKey, !is_null($customKey)); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Classes/Infrastructure/DeepL/DeepLCustomAuthenticationKeyService.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Sitegeist\LostInTranslation\Infrastructure\DeepL; | ||
|
||
use Neos\Cache\Frontend\StringFrontend; | ||
|
||
class DeepLCustomAuthenticationKeyService | ||
{ | ||
private const API_KEY_CACHE_ID = 'lostInTranslationApiKey'; | ||
/** | ||
* @var StringFrontend | ||
*/ | ||
protected $apiKeyCache; | ||
|
||
public function get(): ?string | ||
{ | ||
return $this->apiKeyCache->get(self::API_KEY_CACHE_ID) ?: null; | ||
} | ||
|
||
public function set(string $key): void | ||
{ | ||
$this->apiKeyCache->set(self::API_KEY_CACHE_ID, $key); | ||
} | ||
|
||
public function remove(): void | ||
{ | ||
$this->apiKeyCache->remove(self::API_KEY_CACHE_ID); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.