refactor configurations (#2626)

* composition instead of inheritance
* refactored some twig extensions to runtime extensions
This commit is contained in:
Kevin Papst
2021-06-26 13:03:54 +02:00
committed by GitHub
parent 3d1fba650b
commit 6d196879b4
22 changed files with 255 additions and 358 deletions

View File

@@ -9,7 +9,7 @@
namespace App\Configuration;
class MailConfiguration
final class MailConfiguration
{
/**
* @var string

View File

@@ -11,6 +11,9 @@ namespace App\Configuration;
use App\Entity\Configuration;
/**
* @internal do NOT use this trait, but access your configs via SystemConfiguration
*/
trait StringAccessibleConfigTrait
{
/**

View File

@@ -376,4 +376,21 @@ class SystemConfiguration implements SystemBundleConfiguration
return $this->default('theme.color_choices');
}
// ========== Branding configurations ==========
public function getBrandingTitle(): ?string
{
return $this->find('theme.branding.title');
}
public function getBrandingCompany(): ?string
{
return $this->find('theme.branding.company');
}
public function isAllowTagCreation(): bool
{
return (bool) $this->find('theme.tags_create');
}
}

View File

@@ -10,43 +10,66 @@
namespace App\Configuration;
/**
* @internal will be deprecated soon, use SystemConfiguration instead
* @internal might be deprecated in the future, use SystemConfiguration instead
*/
class ThemeConfiguration implements SystemBundleConfiguration, \ArrayAccess
final class ThemeConfiguration implements \ArrayAccess
{
use StringAccessibleConfigTrait;
private $systemConfiguration;
public function getPrefix(): string
public function __construct(SystemConfiguration $systemConfiguration)
{
return 'theme';
}
public function isAutoReloadDatatable(): bool
{
@trigger_error('The configuration auto_reload_datatable is deprecated and was removed with 1.4', E_USER_DEPRECATED);
return false;
}
public function isAllowTagCreation(): bool
{
return (bool) $this->find('tags_create');
$this->systemConfiguration = $systemConfiguration;
}
/**
* Currently unused, as JS selects are always activated.
* @deprecated since 1.7 will be removed with 2.0
* @return bool
*/
public function getSelectPicker(): string
public function offsetExists($offset)
{
@trigger_error('getSelectPicker() is deprecated and will be removed with 2.0', E_USER_DEPRECATED);
return (string) $this->find('select_type');
return $this->systemConfiguration->has('theme.' . $offset);
}
/**
* @return mixed
*/
public function offsetGet($offset)
{
return $this->systemConfiguration->find('theme.' . $offset);
}
/**
* @param mixed $offset
* @param mixed $value
* @throws \BadMethodCallException
*/
public function offsetSet($offset, $value)
{
throw new \BadMethodCallException('ThemeConfiguration does not support offsetSet()');
}
/**
* @param mixed $offset
* @throws \BadMethodCallException
*/
public function offsetUnset($offset)
{
throw new \BadMethodCallException('ThemeConfiguration does not support offsetUnset()');
}
/**
* @deprecated since 1.15
*/
public function isAllowTagCreation(): bool
{
return (bool) $this->offsetGet('tags_create');
}
/**
* @deprecated since 1.15
*/
public function getTitle(): ?string
{
$title = $this->find('branding.title');
$title = $this->offsetGet('branding.title');
if (null === $title) {
return null;
}