Skip to content

Commit 0de05d0

Browse files
committed
[RELEASE] Version 9.2.0 with env vars, internal_type file_reference and config debug
2 parents a97505e + fff39e3 commit 0de05d0

26 files changed

+746
-170
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# In2publish Core Change Log
22

3+
9.2.0:
4+
5+
- [META] Set the branch alias version number to 9.1.x-dev
6+
- [META] Set the EM conf version number to 9.2.0
7+
- [BUGFIX] Use provided editRecord VH and fix RecordHistory VH return URL
8+
- [FEATURE] Debug provider specific config in "show config" and sysinfo export
9+
- [FEATURE] Support the use of env vars in the yaml config
10+
- [BUGFIX] Allow empty database password (e.g. for local development)
11+
- [DOCS] Add a security notice about public yaml config files
12+
- [DOCS] Update the example configuration to encourage the use of env vars
13+
- [DOCS] Add the guide about configuration post processing
14+
- [FEATURE] Support the use of env vars in the yaml config
15+
- [DOCS] Update installation for new core version
16+
- [FEATURE] Support TCA type group internal_type file_reference
17+
- [FEATURE] Support internal type file_reference
18+
- [BIGFIX] Log "unauthorized" if no backend user is yet logged in
19+
- [RELEASE] Version 9.1.0 with translated record handling and support info
20+
321
9.1.0:
422

523
- [META] Set the branch alias version number to 9.1.x-dev

Classes/Config/ConfigContainer.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use In2code\In2publishCore\Config\Definer\DefinerInterface;
3333
use In2code\In2publishCore\Config\Node\Node;
3434
use In2code\In2publishCore\Config\Node\NodeCollection;
35+
use In2code\In2publishCore\Config\PostProcessor\PostProcessorInterface;
3536
use In2code\In2publishCore\Config\Provider\ContextualProvider;
3637
use In2code\In2publishCore\Config\Provider\ProviderInterface;
3738
use In2code\In2publishCore\Service\Context\ContextService;
@@ -40,6 +41,8 @@
4041
use TYPO3\CMS\Core\SingletonInterface;
4142
use TYPO3\CMS\Core\Utility\GeneralUtility;
4243

44+
use function array_combine;
45+
use function array_fill;
4346
use function array_keys;
4447
use function asort;
4548

@@ -58,6 +61,11 @@ class ConfigContainer implements SingletonInterface
5861
*/
5962
protected $definers = [];
6063

64+
/**
65+
* @var PostProcessorInterface[]
66+
*/
67+
protected $postProcessors = [];
68+
6169
/**
6270
* @var array|null
6371
*/
@@ -169,6 +177,16 @@ protected function processConfig(array $priority): array
169177
$config = ConfigurationUtility::mergeConfiguration($config, $providerConfig);
170178
}
171179

180+
foreach ($this->postProcessors as $class => $object) {
181+
if (null === $object) {
182+
$object = GeneralUtility::makeInstance($class);
183+
$this->postProcessors[$class] = $object;
184+
}
185+
if ($object instanceof PostProcessorInterface) {
186+
$config = $object->process($config);
187+
}
188+
}
189+
172190
if (GeneralUtility::makeInstance(ContextService::class)->isLocal()) {
173191
$config = $this->getLocalDefinition()->cast($config);
174192
} else {
@@ -244,4 +262,51 @@ public function registerDefiner($definer)
244262
{
245263
$this->definers[$definer] = null;
246264
}
265+
266+
/**
267+
* All post processors must be registered in ext_localconf.php!
268+
* PostProcessors must implement the PostProcessorInterface or they won't be called.
269+
*
270+
* @param string $postProcessor
271+
*/
272+
public function registerPostProcessor(string $postProcessor): void
273+
{
274+
$this->postProcessors[$postProcessor] = null;
275+
}
276+
277+
/**
278+
* Returns the information about all registered classes which are responsible for the resulting configuration.
279+
*
280+
* @return array
281+
*/
282+
public function dump(): array
283+
{
284+
// Clone this instance and reset it
285+
$cloned = clone $this;
286+
$cloned->config = null;
287+
$cloned->providers = array_combine(array_keys($this->providers), array_fill(0, count($this->providers), null));
288+
$cloned->definers = array_combine(array_keys($this->definers), array_fill(0, count($this->definers), null));
289+
$cloned->postProcessors = array_combine(array_keys($this->postProcessors), array_fill(0, count($this->postProcessors), null));
290+
$fullConfig = $cloned->get();
291+
292+
$priority = [];
293+
foreach ($cloned->providers as $class => $config) {
294+
$provider = GeneralUtility::makeInstance($class);
295+
$priority[$class] = $provider->getPriority();
296+
}
297+
298+
asort($priority);
299+
300+
$orderedProviderConfig = [];
301+
foreach (array_keys($priority) as $class) {
302+
$orderedProviderConfig[$class] = $cloned->providers[$class];
303+
}
304+
305+
return [
306+
'fullConfig' => $fullConfig,
307+
'providers' => $orderedProviderConfig,
308+
'definers' => array_keys($cloned->definers),
309+
'postProcessors' => array_keys($cloned->postProcessors),
310+
];
311+
}
247312
}

Classes/Config/Definer/In2publishCoreDefiner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function getLocalDefinition()
164164
Builder::start()
165165
->addString('name', 'database_123')
166166
->addString('username', 'username_123')
167-
->addString('password', 'Password_123')
167+
->addOptionalString('password', 'Password_123')
168168
->addString('hostname', '127.0.0.1')
169169
->addInteger('port', 3306, [IPv4PortValidator::class])
170170
)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace In2code\In2publishCore\Config\PostProcessor\DynamicValueProvider;
6+
7+
/*
8+
* Copyright notice
9+
*
10+
* (c) 2020 in2code.de and the following authors:
11+
* Oliver Eglseder <[email protected]>
12+
*
13+
* All rights reserved
14+
*
15+
* This script is part of the TYPO3 project. The TYPO3 project is
16+
* free software; you can redistribute it and/or modify
17+
* it under the terms of the GNU General Public License as published by
18+
* the Free Software Foundation; either version 3 of the License, or
19+
* (at your option) any later version.
20+
*
21+
* The GNU General Public License can be found at
22+
* http://www.gnu.org/copyleft/gpl.html.
23+
*
24+
* This script is distributed in the hope that it will be useful,
25+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+
* GNU General Public License for more details.
28+
*
29+
* This copyright notice MUST APPEAR in all copies of the script!
30+
*/
31+
32+
interface DynamicValueProviderInterface
33+
{
34+
/**
35+
* @param string $string The configuration string from between the round brackets
36+
* @return mixed The scalar value which replaces the dynamic configuration reference.
37+
*/
38+
public function getValueFor(string $string);
39+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace In2code\In2publishCore\Config\PostProcessor\DynamicValueProvider;
6+
7+
/*
8+
* Copyright notice
9+
*
10+
* (c) 2020 in2code.de and the following authors:
11+
* Oliver Eglseder <[email protected]>
12+
*
13+
* All rights reserved
14+
*
15+
* This script is part of the TYPO3 project. The TYPO3 project is
16+
* free software; you can redistribute it and/or modify
17+
* it under the terms of the GNU General Public License as published by
18+
* the Free Software Foundation; either version 3 of the License, or
19+
* (at your option) any later version.
20+
*
21+
* The GNU General Public License can be found at
22+
* http://www.gnu.org/copyleft/gpl.html.
23+
*
24+
* This script is distributed in the hope that it will be useful,
25+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+
* GNU General Public License for more details.
28+
*
29+
* This copyright notice MUST APPEAR in all copies of the script!
30+
*/
31+
32+
use In2code\In2publishCore\Config\PostProcessor\DynamicValueProvider\Exception\InvalidDynamicValueProviderKeyException;
33+
use TYPO3\CMS\Core\SingletonInterface;
34+
use TYPO3\CMS\Core\Utility\GeneralUtility;
35+
36+
class DynamicValueProviderRegistry implements SingletonInterface
37+
{
38+
/**
39+
* @var string[]
40+
*/
41+
protected $classes = [];
42+
43+
/**
44+
* @var DynamicValueProviderInterface[]
45+
*/
46+
protected $objects = [];
47+
48+
/**
49+
* @param string $key The key which will be used in the configuration to call the registered provider
50+
* @param string $class The FQCN of the provider. Must implement `DynamicValueProviderInterface`.
51+
*/
52+
public function registerDynamicValue(string $key, string $class): void
53+
{
54+
$this->classes[$key] = $class;
55+
}
56+
57+
public function getRegisteredClasses(): array
58+
{
59+
return $this->classes;
60+
}
61+
62+
public function hasDynamicValueProviderForKey(string $key): bool
63+
{
64+
return isset($this->classes[$key]);
65+
}
66+
67+
public function getDynamicValueProviderByKey(string $key): DynamicValueProviderInterface
68+
{
69+
if (!$this->hasDynamicValueProviderForKey($key)) {
70+
throw InvalidDynamicValueProviderKeyException::forProviderKey($key);
71+
}
72+
if (!isset($this->objects[$key])) {
73+
$this->objects[$key] = GeneralUtility::makeInstance($this->classes[$key]);
74+
}
75+
return $this->objects[$key];
76+
}
77+
}

Classes/ViewHelpers/Link/EditRecordViewHelper.php renamed to Classes/Config/PostProcessor/DynamicValueProvider/EnvVarProvider.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
declare(strict_types=1);
44

5-
namespace In2code\In2publishCore\ViewHelpers\Link;
5+
namespace In2code\In2publishCore\Config\PostProcessor\DynamicValueProvider;
66

77
/*
88
* Copyright notice
99
*
10-
* (c) 2017 in2code.de and the following authors:
10+
* (c) 2020 in2code.de and the following authors:
1111
* Oliver Eglseder <[email protected]>
1212
*
1313
* All rights reserved
@@ -29,25 +29,15 @@
2929
* This copyright notice MUST APPEAR in all copies of the script!
3030
*/
3131

32-
use In2code\In2publishCore\Utility\BackendUtility;
33-
use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException;
32+
use function getenv;
3433

3534
/**
36-
* Class EditRecordViewHelper
35+
* Replaces configurations values like %env(MYSQL_PASSWORD)% with the env var value of MYSQL_PASSWORD.
3736
*/
38-
class EditRecordViewHelper extends AbstractRecordActionLinkViewHelper
37+
class EnvVarProvider implements DynamicValueProviderInterface
3938
{
40-
/**
41-
* @param string $table
42-
* @param int $identifier
43-
*
44-
* @return string
45-
*
46-
* @SuppressWarnings(PHPMD.StaticAccess)
47-
* @throws RouteNotFoundException
48-
*/
49-
protected function buildUri(string $table, int $identifier): string
39+
public function getValueFor(string $string)
5040
{
51-
return BackendUtility::buildEditUri($table, $identifier);
41+
return getenv($string);
5242
}
5343
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace In2code\In2publishCore\Config\PostProcessor\DynamicValueProvider\Exception;
6+
7+
/*
8+
* Copyright notice
9+
*
10+
* (c) 2020 in2code.de and the following authors:
11+
* Oliver Eglseder <[email protected]>
12+
*
13+
* All rights reserved
14+
*
15+
* This script is part of the TYPO3 project. The TYPO3 project is
16+
* free software; you can redistribute it and/or modify
17+
* it under the terms of the GNU General Public License as published by
18+
* the Free Software Foundation; either version 3 of the License, or
19+
* (at your option) any later version.
20+
*
21+
* The GNU General Public License can be found at
22+
* http://www.gnu.org/copyleft/gpl.html.
23+
*
24+
* This script is distributed in the hope that it will be useful,
25+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+
* GNU General Public License for more details.
28+
*
29+
* This copyright notice MUST APPEAR in all copies of the script!
30+
*/
31+
32+
use In2code\In2publishCore\In2publishCoreException;
33+
34+
class InvalidDynamicValueProviderKeyException extends In2publishCoreException
35+
{
36+
const MESSAGE = 'A dynamic value provider for key "%s" was not registered';
37+
const CODE = 1595409903;
38+
39+
public static function forProviderKey(string $providerKey): InvalidDynamicValueProviderKeyException
40+
{
41+
return new self(sprintf(self::MESSAGE, $providerKey), self::CODE);
42+
}
43+
}

0 commit comments

Comments
 (0)