Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
carsten-walther committed May 15, 2023
1 parent 9e6e5f3 commit 48d1e79
Show file tree
Hide file tree
Showing 18 changed files with 295 additions and 516 deletions.
89 changes: 0 additions & 89 deletions .editorconfig

This file was deleted.

19 changes: 0 additions & 19 deletions .gitignore

This file was deleted.

88 changes: 27 additions & 61 deletions Classes/Configuration/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
<?php

namespace Walther\Html2pdf\Configuration;
namespace CarstenWalther\Html2pdf\Configuration;

use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException;

/**
* Class Configuration
*
* @package Walther\Html2pdf\Configuration
*/
class Configuration
{
/**
Expand All @@ -22,111 +17,82 @@ class Configuration
/**
* @var array
*/
protected static $data = [];
protected static array $data = [];

/**
* @var \TYPO3\CMS\Core\Localization\LanguageService
* @var LanguageService
*/
protected static $languageService;
protected static LanguageService $languageService;

/**
* Configuration constructor.
*
* @param \TYPO3\CMS\Core\Localization\LanguageService $languageService
* @param LanguageServiceFactory $languageServiceFactory
*/
public function __construct(LanguageService $languageService = NULL)
public function __construct(protected readonly LanguageServiceFactory $languageServiceFactory)
{
self::$languageService = $languageService;
if (!self::$languageService) {
self::$languageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Localization\LanguageService::class);
}
self::$languageService->includeLLFile('EXT:html2pdf/Resources/Private/Language/locallang.xlf');
self::$languageService = $this->languageServiceFactory->createFromUserPreferences($GLOBALS['BE_USER'] ?? null);
}

/**
* set
*
* set a value of an array of values
*
* @param $name
* @param null $value
*
* @throws \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
* @param mixed $name
* @param $value
* @return void
* @throws InvalidArgumentException
*/
public static function set($name, $value = null) : void
public static function set(mixed $name, $value = null): void
{
if (is_string($name)) {
self::$data[$name] = $value;
} elseif (is_array($name)) {
self::$data = array_merge(self::$data, $name);
} else {
throw new InvalidArgumentException(sprintf(self::$languageService->getLL('html2pdf.config.set.error'), $name, self::EXTENSION_KEY));
throw new InvalidArgumentException(sprintf(self::$languageService->sL('LLL:EXT:html2pdf/Resources/Private/Language/locallang.xlf:html2pdf.config.set.error'), $name, self::EXTENSION_KEY));
}
}

/**
* getBinaryPath
*
* get the binary path
*
* @return mixed|string
* @throws \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
* @return mixed
* @throws InvalidArgumentException
*/
public static function getBinaryPath()
public static function getBinaryPath(): mixed
{
$binPath = self::get('binPath');

if ($binPath === 'custom') {
return self::get('binPathCustom');
}

return ExtensionManagementUtility::extPath(self::EXTENSION_KEY, 'Vendor/wkhtmltopdf/' . $binPath);
return ExtensionManagementUtility::extPath(self::EXTENSION_KEY, 'Resources/Private/bin/' . $binPath);
}

/**
* get
*
* @param $name
*
* @param string $name
* @return mixed
* @throws \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException
* @throws InvalidArgumentException
*/
public static function get($name)
public static function get(string $name): mixed
{
self::init();

if (!self::exists($name)) {
throw new InvalidArgumentException(sprintf(self::$languageService->getLL('html2pdf.config.get.error'), $name, self::EXTENSION_KEY));
throw new InvalidArgumentException(sprintf(self::$languageService->sL('LLL:EXT:html2pdf/Resources/Private/Language/locallang.xlf:html2pdf.config.get.error'), $name, self::EXTENSION_KEY));
}

return self::$data[$name];
}

/**
* init
*
* initializing method that will be called as soon as it is needed
* @return void
*/
protected static function init() : void
protected static function init(): void
{
if (empty(self::$data)) {
self::$data = $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'][self::EXTENSION_KEY];
}
}

/**
* exists
*
* check if the value exists
*
* @param $name
*
* @return boolean
* @param string $name
* @return bool
*/
public static function exists($name) : bool
public static function exists(string $name): bool
{
self::init();

return is_array(self::$data) && array_key_exists($name, self::$data);
}
}
Loading

0 comments on commit 48d1e79

Please sign in to comment.