Skip to content

Commit

Permalink
update TYPO3 v12 version
Browse files Browse the repository at this point in the history
  • Loading branch information
Carsten Walther committed Sep 23, 2024
1 parent 48d1e79 commit 09af020
Show file tree
Hide file tree
Showing 23 changed files with 32 additions and 544 deletions.
28 changes: 0 additions & 28 deletions Classes/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,17 @@

class Configuration
{
/**
* EXTENSION_KEY
*/
public const EXTENSION_KEY = 'html2pdf';

/**
* @var array
*/
protected static array $data = [];

/**
* @var LanguageService
*/
protected static LanguageService $languageService;

/**
* @param LanguageServiceFactory $languageServiceFactory
*/
public function __construct(protected readonly LanguageServiceFactory $languageServiceFactory)
{
self::$languageService = $this->languageServiceFactory->createFromUserPreferences($GLOBALS['BE_USER'] ?? null);
}

/**
* @param mixed $name
* @param $value
* @return void
* @throws InvalidArgumentException
*/
public static function set(mixed $name, $value = null): void
{
if (is_string($name)) {
Expand All @@ -50,7 +32,6 @@ public static function set(mixed $name, $value = null): void
}

/**
* @return mixed
* @throws InvalidArgumentException
*/
public static function getBinaryPath(): mixed
Expand All @@ -63,8 +44,6 @@ public static function getBinaryPath(): mixed
}

/**
* @param string $name
* @return mixed
* @throws InvalidArgumentException
*/
public static function get(string $name): mixed
Expand All @@ -76,20 +55,13 @@ public static function get(string $name): mixed
return self::$data[$name];
}

/**
* @return void
*/
protected static function init(): void
{
if (empty(self::$data)) {
self::$data = $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'][self::EXTENSION_KEY];
}
}

/**
* @param string $name
* @return bool
*/
public static function exists(string $name): bool
{
self::init();
Expand Down
38 changes: 4 additions & 34 deletions Classes/Converter/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,20 @@
use TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException;
use CarstenWalther\Html2pdf\Configuration\Configuration;

/**
* Class Converter
*
* @package CarstenWalther\Html2pdf\Converter
*/
class Converter implements LoggerAwareInterface
{
use LoggerAwareTrait;

/**
* @var LanguageService
*/
protected mixed $languageService;
protected LanguageService $languageService;

/**
* @param LanguageServiceFactory $languageServiceFactory
*/
public function __construct(protected readonly LanguageServiceFactory $languageServiceFactory)
{
$this->languageService = $this->languageServiceFactory->createFromUserPreferences($GLOBALS['BE_USER'] ?? null);
}

/**
* @param string $input
* @param array $options
*
* @return bool|string
* @throws InvalidArgumentException|DOMException
* @throws DOMException
* @throws InvalidArgumentException
*/
public function convert(string $input, array $options = []): bool|string
{
Expand Down Expand Up @@ -108,15 +94,6 @@ public function convert(string $input, array $options = []): bool|string
return $stdout;
}

/**
* formatBinaryOptions
*
* format and escape all options for the binary call
*
* @param $options
*
* @return string
*/
protected function formatBinaryOptions($options): string
{
$return = [];
Expand All @@ -135,18 +112,11 @@ protected function formatBinaryOptions($options): string
}

/**
* makeAbsoluteURLs
*
* add absolute urls to the html output
*
* @param string $html
*
* @return string
* @throws DOMException
*/
protected function makeAbsoluteURLs(string $html): string
{
if (is_null($html) || empty($html)) {
if (empty($html)) {
return false;
}

Expand Down
3 changes: 0 additions & 3 deletions Classes/Hook/ContentPostProc.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
class ContentPostProc
{
/**
* @param array $parameters
* @param TypoScriptFrontendController $tsfe
* @return void
* @throws DOMException
* @throws InvalidArgumentExceptionAlias
*/
Expand Down
48 changes: 10 additions & 38 deletions Classes/Report/ExtensionStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,28 @@

namespace CarstenWalther\Html2pdf\Report;

use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException;
use TYPO3\CMS\Reports\Status;
use TYPO3\CMS\Reports\StatusProviderInterface;
use CarstenWalther\Html2pdf\Configuration\Configuration;

class ExtensionStatus implements StatusProviderInterface
{
/**
* @var array
*/
protected array $reports = [];

/**
* @var LanguageService
*/
protected mixed $languageService;
protected LanguageService $languageService;

/**
* @param LanguageServiceFactory $languageServiceFactory
*/
public function __construct(protected readonly LanguageServiceFactory $languageServiceFactory)
{
$this->languageService = $this->languageServiceFactory->createFromUserPreferences($GLOBALS['BE_USER'] ?? null);
}

/**
* @return array|Status[]
* @throws InvalidArgumentException
*/
public function getStatus(): array
{
$this->reports = [];
Expand All @@ -47,15 +36,17 @@ public function getStatus(): array
}

$this->checkOperatingSystem();
$this->checkPostProcHook();
$this->checkPageIndexingHook();

$typo3Version = GeneralUtility::makeInstance(Typo3Version::class);

if ($typo3Version->getMajorVersion() < 12) {
$this->checkPostProcHook();
$this->checkPageIndexingHook();
}

return $this->reports;
}

/**
* @return bool
*/
protected function checkConfiguration(): bool
{
$pass = false;
Expand All @@ -77,9 +68,6 @@ protected function checkConfiguration(): bool
return $pass;
}

/**
* @return bool
*/
protected function checkProcOpenFunctionExists(): bool
{
$pass = function_exists('proc_open');
Expand All @@ -94,10 +82,6 @@ protected function checkProcOpenFunctionExists(): bool
return $pass;
}

/**
* @return bool
* @throws InvalidArgumentException
*/
protected function checkBinary(): bool
{
$binary = Configuration::getBinaryPath();
Expand Down Expand Up @@ -169,9 +153,6 @@ protected function checkBinary(): bool
return $pass;
}

/**
* @return void
*/
protected function checkOperatingSystem(): void
{
$os = PHP_OS;
Expand Down Expand Up @@ -204,9 +185,6 @@ protected function checkOperatingSystem(): void
}
}

/**
* @return void
*/
protected function checkPostProcHook(): void
{
$hooking = implode('</li><li>',
Expand All @@ -231,9 +209,6 @@ protected function checkPostProcHook(): void
}
}

/**
* @return void
*/
protected function checkPageIndexingHook(): void
{
$hooking = implode('</li><li>',
Expand All @@ -258,9 +233,6 @@ protected function checkPageIndexingHook(): void
}
}

/**
* @return string
*/
public function getLabel(): string
{
return 'HTML2PDF';
Expand Down
18 changes: 2 additions & 16 deletions Classes/Service/PdfService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,27 @@

class PdfService
{
/**
* @var array|null
*/
private ?array $pluginConfiguration;

/**
* @param array $tsfeConfigArray
*/
public function __construct(array $tsfeConfigArray)
{
$configuration = GeneralUtility::removeDotsFromTS($tsfeConfigArray);
$this->pluginConfiguration = $configuration['tx_html2pdf'] ?? [];
}

/**
* @return bool
*/
public function isEnabled() : bool
{
return array_key_exists('enable', $this->pluginConfiguration) && $this->pluginConfiguration['enable'];
}

/**
* @return array
*/
private function getBinaryOptions() : array
{
return array_key_exists('binOptions', $this->pluginConfiguration) ? $this->pluginConfiguration['binOptions'] : [];
}

/**
* @param string $content
*
* @return string
* @throws InvalidArgumentException|DOMException
* @throws DOMException
* @throws InvalidArgumentException
*/
public function generatePdf(string $content) : string
{
Expand Down
2 changes: 1 addition & 1 deletion Configuration/TypoScript/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ html2pdf {
footer-font-size = 8
# values as string
footer-left = [date] - [time]
footer-center = (C) 2023
footer-center = (C) 2024
footer-right = [page]/[topage]

# options without values
Expand Down
13 changes: 0 additions & 13 deletions Documentation/ChangeLog/Index.rst

This file was deleted.

39 changes: 0 additions & 39 deletions Documentation/Configuration/Index.rst

This file was deleted.

Loading

0 comments on commit 09af020

Please sign in to comment.