Skip to content

Commit

Permalink
Merge branch 'release/12.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
astehlik committed May 11, 2023
2 parents d0ea590 + 15e4469 commit f54c286
Show file tree
Hide file tree
Showing 55 changed files with 1,033 additions and 1,533 deletions.
7 changes: 2 additions & 5 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ version: "2"

prepare:
fetch:
- url: "https://raw.githubusercontent.com/astehlik/php-codestyle/master/PhpMd/RulesetTypo3.xml"
- url: "https://raw.githubusercontent.com/astehlik/php-codestyle/main/PhpMd/RulesetTypo3.xml"
path: "PhpMdRulesetTypo3.xml"

plugins:
phpcodesniffer:
enabled: true
config:
file_extensions: "php"
standard: "PSR1,PSR2"
enabled: false
fixme:
enabled: true
phpmd:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/composer/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ runs:
- uses: php-actions/composer@v6
with:
php_version: ${{ inputs.php_version }}
php_extensions: zip
php_extensions: intl zip
- run: sudo chown -R $(id -u):$(id -g) .
shell: bash
42 changes: 21 additions & 21 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: "Composer validate"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./.github/workflows/composer
with:
php_version: "${{ env.MAIN_PHP_VERSION }}"
Expand All @@ -23,18 +23,18 @@ jobs:
name: "Composer normalize"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./.github/workflows/composer
with:
php_version: "${{ env.MAIN_PHP_VERSION }}"
- run: |
bash .Build/bin/t3_run_tests.sh -s composerNormalize -n -p ${{ env.MAIN_PHP_VERSION }}
"check-codestyle-codesniffer":
name: "PHP code style check"
name: "PHP_CodeSniffer check"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./.github/workflows/composer
with:
php_version: "${{ env.MAIN_PHP_VERSION }}"
Expand All @@ -45,24 +45,24 @@ jobs:
bash .Build/bin/t3_check_codestyle.sh PSRTinyurls
"check-codestyle-php-cs-fixer":
name: "PHP code style check"
name: "PHP CS Fixer check"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./.github/workflows/composer
with:
php_version: "8.1"
- run: |
bash .Build/bin/t3_run_tests.sh -s cgl -n -p 8.1
bash .Build/bin/t3_run_tests.sh -s cgl -n -p ${{ env.MAIN_PHP_VERSION }}
"php-unit-tests":
name: "PHP Unit tests"
strategy:
matrix:
php_version: ["7.4", "8.2"]
php_version: ["8.1", "8.2"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./.github/workflows/composer
with:
php_version: ${{ matrix.php_version }}
Expand All @@ -73,7 +73,7 @@ jobs:
name: "Functional tests on SQLite"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./.github/workflows/composer
with:
php_version: "${{ env.MAIN_PHP_VERSION }}"
Expand All @@ -84,21 +84,21 @@ jobs:
name: "Functional tests on MariaDB"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./.github/workflows/composer
with:
php_version: ${{ env.MAIN_PHP_VERSION }}
- run: |
bash .Build/bin/t3_run_tests.sh -s functional -p ${{ env.MAIN_PHP_VERSION }}
bash .Build/bin/t3_run_tests.sh -s functional -d mariadb -p ${{ env.MAIN_PHP_VERSION }}
"php-lint":
name: "PHP linting"
strategy:
matrix:
php_version: ["7.4", "8.0", "8.1", "8.2"]
php_version: ["8.1", "8.2"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./.github/workflows/composer
with:
php_version: ${{ matrix.php_version }}
Expand All @@ -110,12 +110,12 @@ jobs:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/develop'
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./.github/workflows/composer
with:
php_version: ${{ env.MAIN_PHP_VERSION }}
- run: |
bash .Build/bin/t3_run_tests.sh -s unit -p ${{ env.MAIN_PHP_VERSION }} -x -z coverage -e "--coverage-clover Logs/clover-unit.xml --whitelist ../Classes"
bash .Build/bin/t3_run_tests.sh -s unit -p ${{ env.MAIN_PHP_VERSION }} -x -z coverage -e "--coverage-clover Logs/clover-unit.xml --coverage-filter ../Classes"
- uses: actions/upload-artifact@v3
with:
name: coverage-phpunit
Expand All @@ -127,12 +127,12 @@ jobs:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/develop'
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./.github/workflows/composer
with:
php_version: ${{ env.MAIN_PHP_VERSION }}
- run: |
bash .Build/bin/t3_run_tests.sh -s functional -d mysql -j 5.7 -p ${{ env.MAIN_PHP_VERSION }} -x -z coverage -e "--coverage-clover Logs/clover-functional.xml --whitelist ../Classes"
bash .Build/bin/t3_run_tests.sh -s functional -d mariadb -p ${{ env.MAIN_PHP_VERSION }} -x -z coverage -e "--coverage-clover Logs/clover-functional.xml --coverage-filter ../Classes"
- uses: actions/upload-artifact@v3
with:
name: coverage-functional
Expand All @@ -149,7 +149,7 @@ jobs:
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: coverage-phpunit
Expand All @@ -172,11 +172,11 @@ jobs:
name: "Scan for deprecated and breaking code using typo3scan"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./.github/workflows/composer
with:
php_version: "${{ env.MAIN_PHP_VERSION }}"
- uses: shivammathur/setup-php@v2
with:
php-version: "${{ env.MAIN_PHP_VERSION }}"
- run: php .Build/bin/typo3scan scan --target 11 .
- run: php .Build/bin/typo3scan scan --target 12 .
57 changes: 9 additions & 48 deletions Classes/Configuration/ExtensionConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration as TYPO3ExtensionConfiguration;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;

/**
* Contains utilities for getting configuration.
Expand All @@ -44,6 +43,10 @@ class ExtensionConfiguration implements SingletonInterface

protected ?TypoScriptConfigurator $typoScriptConfigurator = null;

public function __construct(protected readonly TYPO3ExtensionConfiguration $typo3extensionConfiguration)
{
}

/**
* Appends a PID query to the given where statement.
*
Expand Down Expand Up @@ -72,33 +75,6 @@ public function getBase62Dictionary(): string
return (string)$this->getExtensionConfigurationValueInternal('base62Dictionary');
}

/**
* Returns the extension configuration.
*
* @deprecated please use the matching getter for retrieving a config value
*/
public function getExtensionConfiguration(): array
{
$this->initializeExtensionConfiguration();
return $this->extensionConfiguration;
}

/**
* Returns an extension configuration value.
*
* @param string $key the configuration key
*
* @return mixed the configuration value
*
* @throws \InvalidArgumentException if the configuration key does not exist
*
* @deprecated please use the matching getter for retrieving the config value
*/
public function getExtensionConfigurationValue(string $key)
{
return $this->getExtensionConfigurationValueInternal($key);
}

public function getMinimalRandomKeyLength(): int
{
return (int)$this->getExtensionConfigurationValueInternal('minimalRandomKeyLength');
Expand All @@ -119,21 +95,6 @@ public function getUrlRecordStoragePid(): int
return (int)$this->getExtensionConfigurationValueInternal('urlRecordStoragePID');
}

/**
* Initializes the tinyurl configuration with default values and
* if the user set his own values they are parsed through stdWrap.
*
* @deprecated please use the TypoScriptConfigurator class instead
*/
public function initializeConfigFromTyposcript(
array $config,
ContentObjectRenderer $contentObject,
TinyUrlGenerator $tinyUrlGenerator
): void {
$typoScriptConfigurator = $this->getTypoScriptConfigurator($tinyUrlGenerator);
$typoScriptConfigurator->initializeConfigFromTyposcript($config, $contentObject);
}

public function setTypoScriptConfigurator(TypoScriptConfigurator $typoScriptConfigurator): void
{
$this->typoScriptConfigurator = $typoScriptConfigurator;
Expand Down Expand Up @@ -178,19 +139,19 @@ protected function initializeExtensionConfiguration(): void
$finalConfiguration = [];

foreach ($this->extensionConfigurationDefaults as $configKey => $defaultValue) {
if (array_key_exists($configKey, $extensionConfiguration)) {
$finalConfiguration[$configKey] = $extensionConfiguration[$configKey];
} else {
if (!array_key_exists($configKey, $extensionConfiguration)) {
$finalConfiguration[$configKey] = $defaultValue;
continue;
}

$finalConfiguration[$configKey] = $extensionConfiguration[$configKey];
}

$this->extensionConfiguration = $finalConfiguration;
}

private function loadExtensionConfiguration(): array
{
$extensionConfiguration = GeneralUtility::makeInstance(TYPO3ExtensionConfiguration::class);
return $extensionConfiguration->get('tinyurls');
return $this->typo3extensionConfiguration->get('tinyurls');
}
}
90 changes: 66 additions & 24 deletions Classes/Configuration/TypoScriptConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* The TYPO3 project - inspiring people to share! *
* */

use Tx\Tinyurls\TinyUrl\TinyUrlGenerator;
use Tx\Tinyurls\Domain\Model\TinyUrl;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;

class TypoScriptConfigurator
Expand All @@ -28,44 +28,86 @@ class TypoScriptConfigurator
'urlKey' => false,
];

protected TinyUrlGenerator $tinyUrlGenerator;
/**
* Initializes the tinyurl configuration with default values and
* if the user set his own values they are parsed through stdWrap.
*/
public function initializeConfigFromTyposcript(
TinyUrl $tinyUrl,
array $config,
ContentObjectRenderer $contentObjectRenderer
): void {
if (!array_key_exists('tinyurl.', $config)) {
return;
}

foreach (array_keys($this->tinyurlConfigDefaults) as $configKey) {
$configValue = $this->getConfigValue($configKey, $config['tinyurl.'], $contentObjectRenderer);

public function __construct(TinyUrlGenerator $tinyUrlGenerator)
match ($configKey) {
'deleteOnUse' => $this->setOptionDeleteOnUse($tinyUrl, (bool)$configValue),
'validUntil' => $this->setOptionValidUntil($tinyUrl, (int)$configValue),
'urlKey' => $this->setOptionUrlKey($tinyUrl, (string)$configValue),
};
}
}

/**
* @internal Only used for backwards compatibility. Will become private with next major version.
*/
public function setOptionDeleteOnUse(TinyUrl $tinyUrl, bool $deleteOnUse): void
{
$this->tinyUrlGenerator = $tinyUrlGenerator;
if (!$deleteOnUse) {
$tinyUrl->disableDeleteOnUse();
return;
}

$tinyUrl->enableDeleteOnUse();
}

/**
* Initializes the tinyurl configuration with default values and
* if the user set his own values they are parsed through stdWrap.
* @internal Only used for backwards compatibility. Will become private with next major version.
*/
public function initializeConfigFromTyposcript(array $config, ContentObjectRenderer $contentObjectRenderer): void
public function setOptionUrlKey(TinyUrl $tinyUrl, string $urlKey): void
{
if (!array_key_exists('tinyurl.', $config)) {
if ($urlKey === '') {
$tinyUrl->resetCustomUrlKey();
return;
}

$tinyUrlConfig = $config['tinyurl.'];
$tinyUrl->setCustomUrlKey($urlKey);
}

/**
* @internal Only used for backwards compatibility. Will become private with next major version.
*/
public function setOptionValidUntil(TinyUrl $tinyUrl, int $validUntil): void
{
if ($validUntil <= 0) {
$tinyUrl->resetValidUntil();
return;
}

foreach ($this->tinyurlConfigDefaults as $configKey => $defaultValue) {
$configValue = $defaultValue;
$tinyUrl->setValidUntil(new \DateTimeImmutable('@' . $validUntil));
}

if (array_key_exists($configKey, $tinyUrlConfig)) {
$configValue = $tinyUrlConfig[$configKey];
private function getConfigValue(
string $configKey,
array $tinyUrlConfig,
ContentObjectRenderer $contentObjectRenderer
): mixed {
$configValue = $this->tinyurlConfigDefaults[$configKey];

if (array_key_exists($configKey . '.', $tinyUrlConfig)) {
$configValue = $contentObjectRenderer->stdWrap(
$configValue,
$tinyUrlConfig[$configKey . '.']
);
}
}
if (!array_key_exists($configKey, $tinyUrlConfig)) {
return $configValue;
}

$configSetter = 'setOption' . ucfirst($configKey);
$configValue = $tinyUrlConfig[$configKey];

if (method_exists($this->tinyUrlGenerator, $configSetter)) {
$this->tinyUrlGenerator->{$configSetter}($configValue);
}
if (!array_key_exists($configKey . '.', $tinyUrlConfig)) {
return $configValue;
}

return $contentObjectRenderer->stdWrap($configValue, $tinyUrlConfig[$configKey . '.']);
}
}

0 comments on commit f54c286

Please sign in to comment.