generated from OXID-eSales/module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #7 from OXID-eSales/TC-14_APIOptions
Tc 14 api options
- Loading branch information
Showing
24 changed files
with
1,480 additions
and
46 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
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,25 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
namespace OxidSolutionCatalysts\TeleCash\Core\Service; | ||
|
||
/** | ||
* use this service as an alternative to oxid core oxNew, for writing more readable code and better unit tests | ||
*/ | ||
class OxNewService | ||
{ | ||
/** | ||
* @template T of object | ||
* @param class-string<T> $fqcn | ||
* @param array<int|string, mixed> $constructorArgs | ||
* @return T | ||
*/ | ||
public function oxNew(string $fqcn, array $constructorArgs = []): object | ||
{ | ||
return oxNew($fqcn, ...$constructorArgs); | ||
} | ||
} |
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,53 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
namespace OxidSolutionCatalysts\TeleCash\Core\Service; | ||
|
||
use OxidEsales\Eshop\Core\Config; | ||
use OxidEsales\Eshop\Core\Language; | ||
use OxidEsales\Eshop\Core\Registry; | ||
use OxidEsales\Eshop\Core\Request; | ||
use OxidEsales\Eshop\Core\UtilsView; | ||
|
||
class RegistryService | ||
{ | ||
/** | ||
* for better testing and to avoid "'static' methods cannot be mocked" | ||
* @SuppressWarnings(PHPMD.StaticAccess) | ||
*/ | ||
public function getConfig(): Config | ||
{ | ||
return Registry::getConfig(); | ||
} | ||
|
||
/** | ||
* for better testing and to avoid "'static' methods cannot be mocked" | ||
* @SuppressWarnings(PHPMD.StaticAccess) | ||
*/ | ||
public function getLang(): Language | ||
{ | ||
return Registry::getLang(); | ||
} | ||
|
||
/** | ||
* for better testing and to avoid "'static' methods cannot be mocked" | ||
* @SuppressWarnings(PHPMD.StaticAccess) | ||
*/ | ||
public function getRequest(): Request | ||
{ | ||
return Registry::getRequest(); | ||
} | ||
|
||
/** | ||
* for better testing and to avoid "'static' methods cannot be mocked" | ||
* @SuppressWarnings(PHPMD.StaticAccess) | ||
*/ | ||
public function getUtilsView(): UtilsView | ||
{ | ||
return Registry::getUtilsView(); | ||
} | ||
} |
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,12 @@ | ||
services: | ||
_defaults: | ||
public: false | ||
autowire: true | ||
|
||
OxidSolutionCatalysts\TeleCash\Core\Service\OxNewService: | ||
class: OxidSolutionCatalysts\TeleCash\Core\Service\OxNewService | ||
public: true | ||
|
||
OxidSolutionCatalysts\TeleCash\Core\Service\RegistryService: | ||
class: OxidSolutionCatalysts\TeleCash\Core\Service\RegistryService | ||
public: true |
140 changes: 140 additions & 0 deletions
140
src/Extension/Application/Controller/Admin/ModuleConfiguration.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,140 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidSolutionCatalysts\TeleCash\Extension\Application\Controller\Admin; | ||
|
||
use Exception; | ||
use OxidSolutionCatalysts\TeleCash\Core\Module; | ||
use OxidSolutionCatalysts\TeleCash\Core\Service\RegistryService; | ||
use OxidSolutionCatalysts\TeleCash\Settings\Service\ModuleFileSettingsService; | ||
use OxidSolutionCatalysts\TeleCash\Settings\Service\ModuleFileSettingsServiceInterface; | ||
use OxidSolutionCatalysts\TeleCash\Settings\Service\ModuleSettingsServiceInterface; | ||
use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
|
||
class ModuleConfiguration extends ModuleConfiguration_parent | ||
{ | ||
protected RegistryService $registryService; | ||
protected ModuleFileSettingsServiceInterface $fileSettingsService; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
$this->fileSettingsService = $this->getService(ModuleFileSettingsServiceInterface::class); | ||
$this->registryService = $this->getService(RegistryService::class); | ||
} | ||
|
||
/** | ||
* OXID-Core | ||
* @inheritDoc | ||
* @return string | ||
*/ | ||
public function render() | ||
{ | ||
$result = parent::render(); | ||
|
||
$this->_aViewData['sTeleCashModuleId'] = Module::MODULE_ID; | ||
$this->_aViewData['sTeleCashVarGroupAPI'] = ModuleSettingsServiceInterface::MODULE_CONFIG_API_VARGROUP; | ||
$this->_aViewData['sTeleCashOptionTrigger'] = ModuleSettingsServiceInterface::CLIENT_CERT_PRIVATEKEY_PASSWORD; | ||
|
||
// collect setted options for template | ||
$fileSettingsService = $this->getService(ModuleFileSettingsServiceInterface::class); | ||
$aTeleCashFiles = []; | ||
foreach (ModuleFileSettingsService::TELECASH_GET_FILENAME_METHODS as $teleCashFile => $teleCashGetMethod) { | ||
$aTeleCashFiles[$teleCashFile] = $fileSettingsService->$teleCashGetMethod($teleCashFile); | ||
} | ||
$this->_aViewData['aTeleCashFiles'] = $aTeleCashFiles; | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* OXID-Core | ||
* @inheritDoc | ||
* @return void | ||
*/ | ||
public function saveConfVars() | ||
{ | ||
parent::saveConfVars(); | ||
$this->storeTeleCashFiles(); | ||
$this->deleteTeleCashFiles(); | ||
} | ||
|
||
|
||
/** | ||
* store the necessary telecash files | ||
* | ||
* @return void | ||
*/ | ||
protected function storeTeleCashFiles(): void | ||
{ | ||
$lang = $this->registryService->getLang(); | ||
$config = $this->registryService->getConfig(); | ||
$utilsView = $this->registryService->getUtilsView(); | ||
|
||
foreach (ModuleFileSettingsService::TELECASH_STORE_METHODS as $teleCashFile => $teleCashStoreMethod) { | ||
/** @var array<string, mixed> $aFile */ | ||
$aFile = $config->getUploadedFile($teleCashFile); | ||
if ($aFile !== null && !empty($aFile['name'])) { | ||
$sTmpName = $aFile['tmp_name'] ?? ''; | ||
$sName = $aFile['name']; | ||
$iError = $aFile['error'] ?? UPLOAD_ERR_NO_FILE; | ||
|
||
if ($iError === UPLOAD_ERR_OK && is_uploaded_file($sTmpName)) { | ||
try { | ||
$uploadedFile = new UploadedFile( | ||
$sTmpName, | ||
$sName, | ||
$aFile['type'], | ||
$aFile['error'], | ||
true | ||
); | ||
|
||
$this->fileSettingsService->$teleCashStoreMethod($uploadedFile); | ||
/** @var string $translate */ | ||
$translate = $lang->translateString('TELECASH_FILE_UPLOAD_SUCCESSFUL'); | ||
$utilsView->addErrorToDisplay(sprintf( | ||
$translate, | ||
$sName | ||
)); | ||
} catch (Exception $e) { | ||
/** @var string $translate */ | ||
$translate = $lang->translateString('TELECASH_FILE_UPLOAD_ERROR'); | ||
$utilsView->addErrorToDisplay(sprintf( | ||
$translate, | ||
$e->getMessage() | ||
)); | ||
} | ||
} else { | ||
/** @var string $translate */ | ||
$translate = $lang->translateString('TELECASH_FILE_UPLOAD_NOTVALID'); | ||
$utilsView->addErrorToDisplay(sprintf( | ||
$translate, | ||
$sName | ||
)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* delete the unnecessary telecash files | ||
* | ||
* @return void | ||
*/ | ||
protected function deleteTeleCashFiles(): void | ||
{ | ||
$request = $this->registryService->getRequest(); | ||
|
||
foreach (ModuleFileSettingsService::TELECASH_DELETE_METHODS as $teleCashFile => $teleCashDeleteMethod) { | ||
if ($request->getRequestParameter($teleCashFile . '_delete')) { | ||
$this->fileSettingsService->$teleCashDeleteMethod(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.