improve code for PHP 8

This commit is contained in:
Daniel Seifert 2024-03-04 13:57:10 +01:00 committed by Daniel Seifert
parent 220f8a1c7c
commit b77642666b
9 changed files with 126 additions and 124 deletions

View File

@ -18,20 +18,21 @@ namespace D3\DataWizard\Application\Controller\Admin;
use D3\DataWizard\Application\Model\Configuration; use D3\DataWizard\Application\Model\Configuration;
use D3\DataWizard\Application\Model\Exceptions\DataWizardException; use D3\DataWizard\Application\Model\Exceptions\DataWizardException;
use D3\DataWizard\Application\Model\Exceptions\DebugException; use D3\DataWizard\Application\Model\Exceptions\DebugException;
use D3\DataWizard\Application\Model\Exceptions\InputUnvalidException;
use D3\DataWizard\Application\Model\Exceptions\TaskException;
use D3\ModCfg\Application\Model\d3database; use D3\ModCfg\Application\Model\d3database;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Exception as DBALException;
use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController; use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController;
use OxidEsales\Eshop\Core\Config; use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class d3ActionWizard extends AdminDetailsController class d3ActionWizard extends AdminDetailsController
{ {
protected $_sThisTemplate = 'd3ActionWizard.tpl'; protected $_sThisTemplate = 'd3ActionWizard.tpl';
/** @var Configuration */ protected Configuration $configuration;
protected $configuration;
public function __construct() public function __construct()
{ {
@ -55,23 +56,28 @@ class d3ActionWizard extends AdminDetailsController
} }
/** /**
* @throws DatabaseConnectionException * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
public function runTask() public function runTask(): void
{ {
try { try {
$this->execute(); $this->execute();
} catch (DataWizardException|DBALException|DatabaseErrorException $e) { } catch (DataWizardException|DBALException $e) {
Registry::getLogger()->error($e->getMessage()); Registry::getLogger()->error($e->getMessage());
Registry::getUtilsView()->addErrorToDisplay($e); Registry::getUtilsView()->addErrorToDisplay($e);
} }
} }
/** /**
* @throws DatabaseConnectionException * @throws ContainerExceptionInterface
* @throws DatabaseErrorException * @throws DBALException
* @throws DebugException
* @throws InputUnvalidException
* @throws NotFoundExceptionInterface
* @throws TaskException
*/ */
protected function execute() protected function execute(): void
{ {
$id = Registry::getRequest()->getRequestEscapedParameter('taskid'); $id = Registry::getRequest()->getRequestEscapedParameter('taskid');
$action = $this->configuration->getActionById($id); $action = $this->configuration->getActionById($id);
@ -79,10 +85,12 @@ class d3ActionWizard extends AdminDetailsController
[ $queryString, $parameters ] = $action->getQuery(); [ $queryString, $parameters ] = $action->getQuery();
if ($this->d3GetConfig()->getConfigParam('d3datawizard_debug')) { if ($this->d3GetConfig()->getConfigParam('d3datawizard_debug')) {
throw oxNew( /** @var DebugException $debug */
$debug = oxNew(
DebugException::class, DebugException::class,
d3database::getInstance()->getPreparedStatementQuery($queryString, $parameters) d3database::getInstance()->getPreparedStatementQuery($queryString, $parameters)
); );
throw $debug;
} }
$action->run(); $action->run();
@ -96,12 +104,12 @@ class d3ActionWizard extends AdminDetailsController
return Registry::getConfig(); return Registry::getConfig();
} }
public function getUserMessages() public function getUserMessages(): ?string
{ {
return null; return null;
} }
public function getHelpURL() public function getHelpURL(): ?string
{ {
return null; return null;
} }

View File

@ -19,24 +19,25 @@ use D3\DataWizard\Application\Model\Configuration;
use D3\DataWizard\Application\Model\Exceptions\DataWizardException; use D3\DataWizard\Application\Model\Exceptions\DataWizardException;
use D3\DataWizard\Application\Model\Exceptions\DebugException; use D3\DataWizard\Application\Model\Exceptions\DebugException;
use D3\DataWizard\Application\Model\Exceptions\NoSuitableRendererException; use D3\DataWizard\Application\Model\Exceptions\NoSuitableRendererException;
use D3\DataWizard\Application\Model\Exceptions\TaskException;
use D3\ModCfg\Application\Model\d3database; use D3\ModCfg\Application\Model\d3database;
use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception; use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception;
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException; use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Exception as DBALException;
use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController; use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController;
use OxidEsales\Eshop\Core\Config; use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException; use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException; use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Exception\StandardException; use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class d3ExportWizard extends AdminDetailsController class d3ExportWizard extends AdminDetailsController
{ {
protected $_sThisTemplate = 'd3ExportWizard.tpl'; protected $_sThisTemplate = 'd3ExportWizard.tpl';
/** @var Configuration */ protected Configuration $configuration;
protected $configuration;
public function __construct() public function __construct()
{ {
@ -61,12 +62,15 @@ class d3ExportWizard extends AdminDetailsController
} }
/** /**
* @throws ContainerExceptionInterface
* @throws DatabaseConnectionException * @throws DatabaseConnectionException
* @throws Exception
* @throws NotFoundExceptionInterface
* @throws StandardException * @throws StandardException
* @throws d3ShopCompatibilityAdapterException * @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception * @throws d3_cfg_mod_exception
*/ */
public function runTask() public function runTask(): void
{ {
try { try {
$this->execute(); $this->execute();
@ -80,13 +84,15 @@ class d3ExportWizard extends AdminDetailsController
* @throws DBALException * @throws DBALException
* @throws DatabaseConnectionException * @throws DatabaseConnectionException
* @throws DatabaseErrorException * @throws DatabaseErrorException
* @throws StandardException
* @throws NoSuitableRendererException * @throws NoSuitableRendererException
* @throws TaskException * @throws StandardException
* @throws Exception
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws d3ShopCompatibilityAdapterException * @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception * @throws d3_cfg_mod_exception
*/ */
protected function execute() protected function execute(): void
{ {
$id = Registry::getRequest()->getRequestEscapedParameter('taskid'); $id = Registry::getRequest()->getRequestEscapedParameter('taskid');
$export = $this->configuration->getExportById($id); $export = $this->configuration->getExportById($id);
@ -111,12 +117,12 @@ class d3ExportWizard extends AdminDetailsController
return Registry::getConfig(); return Registry::getConfig();
} }
public function getUserMessages() public function getUserMessages(): ?string
{ {
return null; return null;
} }
public function getHelpURL() public function getHelpURL(): ?string
{ {
return null; return null;
} }

View File

@ -16,18 +16,20 @@ declare(strict_types=1);
namespace D3\DataWizard\Application\Model; namespace D3\DataWizard\Application\Model;
use D3\DataWizard\Application\Model\Exceptions\InputUnvalidException; use D3\DataWizard\Application\Model\Exceptions\InputUnvalidException;
use D3\DataWizard\Application\Model\Exceptions\TaskException;
use Doctrine\DBAL\Exception as DBALException;
use FormManager\Inputs\Checkbox; use FormManager\Inputs\Checkbox;
use FormManager\Inputs\Input; use FormManager\Inputs\Input;
use FormManager\Inputs\Radio; use FormManager\Inputs\Radio;
use OxidEsales\Eshop\Core\Database\Adapter\DatabaseInterface;
use OxidEsales\Eshop\Core\DatabaseProvider;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Database\ConnectionProviderInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
abstract class ActionBase implements QueryBase abstract class ActionBase implements QueryBase
{ {
protected $formElements = []; protected array $formElements = [];
/** /**
* Ensure that the translations are equally available in the frontend and the backend * Ensure that the translations are equally available in the frontend and the backend
@ -39,16 +41,21 @@ abstract class ActionBase implements QueryBase
} }
/** /**
* @throws DatabaseConnectionException * @throws ContainerExceptionInterface
* @throws DatabaseErrorException * @throws DBALException
* @throws InputUnvalidException
* @throws NotFoundExceptionInterface
* @throws TaskException
*/ */
public function run() public function run(): void
{ {
if ($this->hasFormElements()) { if ($this->hasFormElements()) {
/** @var Input $element */ /** @var Input $element */
foreach ($this->getFormElements() as $element) { foreach ($this->getFormElements() as $element) {
if (false === $element->isValid()) { if (false === $element->isValid()) {
throw oxNew(InputUnvalidException::class, $this, $element); /** @var InputUnvalidException $exception */
$exception = oxNew(InputUnvalidException::class, $this, $element);
throw $exception;
} }
} }
} }
@ -59,28 +66,34 @@ abstract class ActionBase implements QueryBase
/** /**
* @param array $query * @param array $query
* *
* @return int * @return void
* @throws DatabaseConnectionException * @throws ContainerExceptionInterface
* @throws DatabaseErrorException * @throws NotFoundExceptionInterface
* @throws TaskException
* @throws DBALException
*/ */
public function executeAction(array $query): int public function executeAction(array $query): void
{ {
[ $queryString, $parameters ] = $query; [ $queryString, $parameters ] = $query;
$queryString = trim($queryString); $queryString = trim($queryString);
if (strtolower(substr($queryString, 0, 6)) === 'select') { if (strtolower(substr($queryString, 0, 6)) === 'select') {
throw oxNew( /** @var TaskException $exception */
Exceptions\TaskException::class, $exception = oxNew(
TaskException::class,
$this, $this,
Registry::getLang()->translateString('D3_DATAWIZARD_ERR_ACTIONSELECT') Registry::getLang()->translateString('D3_DATAWIZARD_ERR_ACTIONSELECT')
); );
throw $exception;
} }
$affected = $this->d3GetDb()->execute($queryString, $parameters); $connection = ContainerFactory::getInstance()->getContainer()->get(ConnectionProviderInterface::class)->get();
$affected = (int) $connection->executeStatement($queryString, $parameters);
throw oxNew( /** @var TaskException $exception */
Exceptions\TaskException::class, $exception = oxNew(
TaskException::class,
$this, $this,
sprintf( sprintf(
Registry::getLang()->translateString( Registry::getLang()->translateString(
@ -89,15 +102,7 @@ abstract class ActionBase implements QueryBase
$affected $affected
) )
); );
} throw $exception;
/**
* @return DatabaseInterface|null
* @throws DatabaseConnectionException
*/
public function d3GetDb(): ?DatabaseInterface
{
return DatabaseProvider::getDb(DatabaseProvider::FETCH_MODE_ASSOC);
} }
/** /**
@ -111,7 +116,7 @@ abstract class ActionBase implements QueryBase
/** /**
* @param Input $input * @param Input $input
*/ */
public function registerFormElement(Input $input) public function registerFormElement(Input $input): void
{ {
if ($input instanceof Radio || $input instanceof Checkbox) { if ($input instanceof Radio || $input instanceof Checkbox) {
$input->setTemplate('<p class="form-check">{{ input }} {{ label }}</p>'); $input->setTemplate('<p class="form-check">{{ input }} {{ label }}</p>');

View File

@ -27,8 +27,8 @@ class Configuration
public const GROUP_REMARKS = 'D3_DATAWIZARD_GROUP_REMARKS'; public const GROUP_REMARKS = 'D3_DATAWIZARD_GROUP_REMARKS';
public const GROUP_CMS = 'D3_DATAWIZARD_GROUP_CMS'; public const GROUP_CMS = 'D3_DATAWIZARD_GROUP_CMS';
protected $actions = []; protected array $actions = [];
protected $exports = []; protected array $exports = [];
public function __construct() public function __construct()
{ {
@ -44,7 +44,7 @@ class Configuration
* @param $group * @param $group
* @param ActionBase $action * @param ActionBase $action
*/ */
public function registerAction($group, ActionBase $action) public function registerAction($group, ActionBase $action): void
{ {
$this->actions[$group][md5(get_class($action))] = $action; $this->actions[$group][md5(get_class($action))] = $action;
} }
@ -53,7 +53,7 @@ class Configuration
* @param $group * @param $group
* @param ExportBase $export * @param ExportBase $export
*/ */
public function registerExport($group, ExportBase $export) public function registerExport($group, ExportBase $export): void
{ {
$this->exports[$group][md5(get_class($export))] = $export; $this->exports[$group][md5(get_class($export))] = $export;
} }
@ -147,7 +147,7 @@ class Configuration
{ {
$allActions = $this->getAllActions(); $allActions = $this->getAllActions();
if (false == $allActions[$id]) { if ( ! $allActions[ $id ] ) {
throw oxNew(DataWizardException::class, 'no action with id '.$id); throw oxNew(DataWizardException::class, 'no action with id '.$id);
} }
@ -163,7 +163,7 @@ class Configuration
{ {
$allExports = $this->getAllExports(); $allExports = $this->getAllExports();
if (false == $allExports[$id]) { if ( ! $allExports[ $id ] ) {
throw oxNew(DataWizardException::class, 'no export with id '.$id); throw oxNew(DataWizardException::class, 'no export with id '.$id);
} }

View File

@ -21,8 +21,7 @@ use FormManager\Inputs\Input;
class InputUnvalidException extends DataWizardException class InputUnvalidException extends DataWizardException
{ {
/** @var QueryBase */ public QueryBase $task;
public $task;
/** /**
* InputUnvalidException constructor. * InputUnvalidException constructor.

View File

@ -20,8 +20,7 @@ use Exception;
class TaskException extends DataWizardException class TaskException extends DataWizardException
{ {
/** @var QueryBase */ public QueryBase $task;
public $task;
public function __construct(QueryBase $task, $sMessage = "not set", $iCode = 0, Exception $previous = null) public function __construct(QueryBase $task, $sMessage = "not set", $iCode = 0, Exception $previous = null)
{ {

View File

@ -17,24 +17,30 @@ namespace D3\DataWizard\Application\Model;
use D3\DataWizard\Application\Model\Exceptions\ExportFileException; use D3\DataWizard\Application\Model\Exceptions\ExportFileException;
use D3\DataWizard\Application\Model\Exceptions\InputUnvalidException; use D3\DataWizard\Application\Model\Exceptions\InputUnvalidException;
use D3\DataWizard\Application\Model\Exceptions\NoSuitableRendererException;
use D3\DataWizard\Application\Model\ExportRenderer\RendererBridge; use D3\DataWizard\Application\Model\ExportRenderer\RendererBridge;
use D3\DataWizard\Application\Model\ExportRenderer\RendererInterface;
use D3\ModCfg\Application\Model\d3filesystem; use D3\ModCfg\Application\Model\d3filesystem;
use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception; use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception;
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException; use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Exception as DBALException;
use FormManager\Inputs\Checkbox; use FormManager\Inputs\Checkbox;
use FormManager\Inputs\Input; use FormManager\Inputs\Input;
use FormManager\Inputs\Radio; use FormManager\Inputs\Radio;
use OxidEsales\Eshop\Core\Database\Adapter\DatabaseInterface;
use OxidEsales\Eshop\Core\DatabaseProvider;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException; use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException; use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Exception\StandardException; use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Database\ConnectionProviderInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
abstract class ExportBase implements QueryBase abstract class ExportBase implements QueryBase
{ {
protected $formElements = []; protected array $formElements = [];
/** /**
* Ensure that the translations are equally available in the frontend and the backend * Ensure that the translations are equally available in the frontend and the backend
@ -47,17 +53,19 @@ abstract class ExportBase implements QueryBase
/** /**
* @param string $format * @param string $format
* @param $path * @param null $path
* *
* @return string
* @throws ContainerExceptionInterface
* @throws DBALException * @throws DBALException
* @throws DatabaseConnectionException * @throws DatabaseConnectionException
* @throws DatabaseErrorException * @throws DatabaseErrorException
* @throws Exceptions\NoSuitableRendererException * @throws Exception
* @throws Exceptions\TaskException * @throws NoSuitableRendererException
* @throws NotFoundExceptionInterface
* @throws StandardException * @throws StandardException
* @throws d3ShopCompatibilityAdapterException * @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception * @throws d3_cfg_mod_exception
* @return string
*/ */
public function run(string $format = RendererBridge::FORMAT_CSV, $path = null): string public function run(string $format = RendererBridge::FORMAT_CSV, $path = null): string
{ {
@ -82,31 +90,22 @@ abstract class ExportBase implements QueryBase
} }
/** /**
* @param $format * @throws NoSuitableRendererException
*
* @return ExportRenderer\RendererInterface
* @throws Exceptions\NoSuitableRendererException
*/ */
public function getRenderer($format): ExportRenderer\RendererInterface public function getRenderer(string $format): RendererInterface
{ {
return $this->getRendererBridge()->getRenderer($format); return $this->getRendererBridge()->getRenderer($format);
} }
/**
* @return RendererBridge
*/
public function getRendererBridge(): RendererBridge public function getRendererBridge(): RendererBridge
{ {
return oxNew(RendererBridge::class); return oxNew(RendererBridge::class);
} }
/** /**
* @param $format * @throws NoSuitableRendererException
*
* @return string
* @throws Exceptions\NoSuitableRendererException
*/ */
public function getFileExtension($format): string public function getFileExtension(string $format): string
{ {
return $this->getRenderer($format)->getFileExtension(); return $this->getRenderer($format)->getFileExtension();
} }
@ -148,8 +147,10 @@ abstract class ExportBase implements QueryBase
* @param array $query * @param array $query
* *
* @return array * @return array
* @throws DatabaseConnectionException * @throws DBALException
* @throws DatabaseErrorException * @throws Exception
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
public function getExportData(array $query): array public function getExportData(array $query): array
{ {
@ -165,7 +166,9 @@ abstract class ExportBase implements QueryBase
); );
} }
$rows = $this->d3GetDb()->getAll($queryString, $parameters); /** @var Connection $connection */
$connection = ContainerFactory::getInstance()->getContainer()->get(ConnectionProviderInterface::class)->get();
$rows = $connection->executeQuery($queryString, $parameters)->fetchAllAssociative();
if (count($rows) <= 0) { if (count($rows) <= 0) {
throw oxNew( throw oxNew(
@ -180,10 +183,7 @@ abstract class ExportBase implements QueryBase
return [ $rows, $fieldNames ]; return [ $rows, $fieldNames ];
} }
/** public function registerFormElement(Input $input): void
* @param Input $input
*/
public function registerFormElement(Input $input)
{ {
if ($input instanceof Radio || $input instanceof Checkbox) { if ($input instanceof Radio || $input instanceof Checkbox) {
$input->setTemplate('<p class="form-check">{{ input }} {{ label }}</p>'); $input->setTemplate('<p class="form-check">{{ input }} {{ label }}</p>');
@ -213,12 +213,16 @@ abstract class ExportBase implements QueryBase
/** /**
* @param string $format * @param string $format
* @param $path * @param $path
*
* @return string * @return string
* @throws ContainerExceptionInterface
* @throws DBALException * @throws DBALException
* @throws DatabaseConnectionException * @throws DatabaseConnectionException
* @throws DatabaseErrorException * @throws DatabaseErrorException
* @throws Exceptions\NoSuitableRendererException * @throws Exception
* @throws NoSuitableRendererException
* @throws NotFoundExceptionInterface
* @throws StandardException * @throws StandardException
* @throws d3ShopCompatibilityAdapterException * @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception * @throws d3_cfg_mod_exception
@ -227,13 +231,12 @@ abstract class ExportBase implements QueryBase
{ {
$content = $this->getContent($format); $content = $this->getContent($format);
/** @var $oFS d3filesystem */
$oFS = $this->getFileSystem(); $oFS = $this->getFileSystem();
if (is_null($path)) { if (is_null($path)) {
$oFS->startDirectDownload($oFS->filterFilename($this->getExportFileName($format)), $content); $oFS->startDirectDownload($oFS->filterFilename($this->getExportFileName($format)), $content);
} else { } else {
$filePath = $oFS->trailingslashit($path) . $oFS->filterFilename($this->getExportFileName($format)); $filePath = $oFS->trailingslashit($path) . $oFS->filterFilename($this->getExportFileName($format));
if (false === $oFS->createFile($filePath, $content, true)) { if (false === $oFS->createFile($filePath, $content)) {
throw oxNew(ExportFileException::class, $filePath); throw oxNew(ExportFileException::class, $filePath);
} }
return $filePath; return $filePath;
@ -242,19 +245,7 @@ abstract class ExportBase implements QueryBase
return ''; return '';
} }
/** protected function getFileSystem(): d3filesystem
* @return DatabaseInterface|null
* @throws DatabaseConnectionException
*/
protected function d3GetDb(): ?DatabaseInterface
{
return DatabaseProvider::getDb(DatabaseProvider::FETCH_MODE_ASSOC);
}
/**
* @return d3filesystem|mixed
*/
protected function getFileSystem()
{ {
return oxNew(d3filesystem::class); return oxNew(d3filesystem::class);
} }
@ -263,16 +254,16 @@ abstract class ExportBase implements QueryBase
* @param string $format * @param string $format
* *
* @return string * @return string
* @throws DatabaseConnectionException * @throws ContainerExceptionInterface
* @throws DatabaseErrorException * @throws DBALException
* @throws Exceptions\NoSuitableRendererException * @throws Exception
* @throws NoSuitableRendererException
* @throws NotFoundExceptionInterface
*/ */
public function getContent(string $format): string public function getContent(string $format): string
{ {
[ $rows, $fieldNames ] = $this->getExportData($this->getQuery()); [ $rows, $fieldNames ] = $this->getExportData($this->getQuery());
$content = $this->renderContent($rows, $fieldNames, $format); return $this->renderContent($rows, $fieldNames, $format);
return $content;
} }
} }

View File

@ -60,16 +60,10 @@ class Csv implements RendererInterface
EncloseField::addTo($csv, "\t\x1f"); EncloseField::addTo($csv, "\t\x1f");
$sEncloser = $this->d3GetConfig()->getConfigParam('sGiCsvFieldEncloser'); $sEncloser = $this->d3GetConfig()->getConfigParam('sGiCsvFieldEncloser') ?? '"';
if (false == $sEncloser) {
$sEncloser = '"';
}
$csv->setEnclosure($sEncloser); $csv->setEnclosure($sEncloser);
$sDelimiter = $this->d3GetConfig()->getConfigParam('sCSVSign'); $sDelimiter = $this->d3GetConfig()->getConfigParam('sCSVSign') ?? ';';
if (false == $sDelimiter) {
$sDelimiter = ';';
}
$csv->setDelimiter($sDelimiter); $csv->setDelimiter($sDelimiter);
return $csv; return $csv;

View File

@ -45,7 +45,7 @@ class RendererBridge
/** /**
* @param RendererInterface $instance * @param RendererInterface $instance
*/ */
protected function translateRendererId(RendererInterface &$instance) protected function translateRendererId(RendererInterface &$instance): void
{ {
$instance = $instance->getTitleTranslationId(); $instance = $instance->getTitleTranslationId();
} }
@ -60,8 +60,8 @@ class RendererBridge
{ {
$format = strtolower($format); $format = strtolower($format);
$rendererList = array_change_key_case($this->getRendererList(), CASE_LOWER); $rendererList = array_change_key_case($this->getRendererList());
$rendererListTypes = array_keys(array_change_key_case($rendererList, CASE_LOWER)); $rendererListTypes = array_keys(array_change_key_case($rendererList));
if (in_array($format, $rendererListTypes, true)) { if (in_array($format, $rendererListTypes, true)) {
return $rendererList[$format]; return $rendererList[$format];