events: extend system configurations and set invoice formatter (#1995)
This commit is contained in:
@@ -120,12 +120,14 @@ final class ReloadCommand extends Command
|
||||
'bin/console cache:warmup --env=' . $environment
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$io->success(
|
||||
sprintf('Kimai config was reloaded')
|
||||
);
|
||||
|
||||
return $cacheResult;
|
||||
}
|
||||
|
||||
$io->success(
|
||||
sprintf('Kimai config was reloaded')
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,8 +57,8 @@ trait StringAccessibleConfigTrait
|
||||
}
|
||||
foreach ($temp as $key2) {
|
||||
if (!\array_key_exists($key2, $array)) {
|
||||
// unknown values will silently be skipped
|
||||
continue 2;
|
||||
$array[$key2] = $configuration->getValue();
|
||||
continue;
|
||||
}
|
||||
if (\is_array($array[$key2])) {
|
||||
$array = &$array[$key2];
|
||||
@@ -87,6 +87,13 @@ trait StringAccessibleConfigTrait
|
||||
public function find(string $key)
|
||||
{
|
||||
$this->prepare();
|
||||
$key = $this->prepareSearchKey($key);
|
||||
|
||||
return $this->get($key, $this->settings);
|
||||
}
|
||||
|
||||
private function prepareSearchKey(string $key): string
|
||||
{
|
||||
$prefix = $this->getPrefix() . '.';
|
||||
$length = \strlen($prefix);
|
||||
|
||||
@@ -94,7 +101,7 @@ trait StringAccessibleConfigTrait
|
||||
$key = substr($key, $length);
|
||||
}
|
||||
|
||||
return $this->get($key, $this->settings);
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,7 +115,7 @@ trait StringAccessibleConfigTrait
|
||||
$search = array_shift($keys);
|
||||
|
||||
if (!\array_key_exists($search, $config)) {
|
||||
throw new \InvalidArgumentException('Unknown config: ' . $key);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (\is_array($config[$search]) && !empty($keys)) {
|
||||
@@ -118,18 +125,27 @@ trait StringAccessibleConfigTrait
|
||||
return $config[$search];
|
||||
}
|
||||
|
||||
public function has(string $key): bool
|
||||
{
|
||||
$this->prepare();
|
||||
$key = $this->prepareSearchKey($key);
|
||||
|
||||
$keys = explode('.', $key);
|
||||
$search = array_shift($keys);
|
||||
|
||||
if (!\array_key_exists($search, $this->settings)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
try {
|
||||
$this->find($offset);
|
||||
} catch (\Exception $ex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return $this->has($offset);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -202,6 +202,10 @@ final class SystemConfigurationController extends AbstractController
|
||||
|
||||
foreach ($event->getConfigurations() as $configs) {
|
||||
foreach ($configs->getConfiguration() as $config) {
|
||||
if (!$this->configurations->has($config->getName())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$configValue = $this->configurations->find($config->getName());
|
||||
if (null !== $configValue) {
|
||||
$config->setValue($configValue);
|
||||
|
||||
@@ -21,27 +21,20 @@ class SystemConfiguration
|
||||
public const SECTION_BRANDING = 'branding';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var string|null
|
||||
*/
|
||||
private $section;
|
||||
/**
|
||||
* @var Configuration[]
|
||||
*/
|
||||
private $configuration;
|
||||
private $configuration = [];
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSection(): string
|
||||
public function getSection(): ?string
|
||||
{
|
||||
return $this->section;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $section
|
||||
* @return SystemConfiguration
|
||||
*/
|
||||
public function setSection(string $section)
|
||||
public function setSection(?string $section): SystemConfiguration
|
||||
{
|
||||
$this->section = $section;
|
||||
|
||||
@@ -60,10 +53,17 @@ class SystemConfiguration
|
||||
* @param Configuration[] $configuration
|
||||
* @return SystemConfiguration
|
||||
*/
|
||||
public function setConfiguration(array $configuration)
|
||||
public function setConfiguration(array $configuration): SystemConfiguration
|
||||
{
|
||||
$this->configuration = $configuration;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addConfiguration(Configuration $configuration): SystemConfiguration
|
||||
{
|
||||
$this->configuration[] = $configuration;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,11 +267,18 @@ final class InvoiceModel
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFormatter(): ?InvoiceFormatter
|
||||
public function getFormatter(): InvoiceFormatter
|
||||
{
|
||||
return $this->formatter;
|
||||
}
|
||||
|
||||
public function setFormatter(InvoiceFormatter $formatter): InvoiceModel
|
||||
{
|
||||
$this->formatter = $formatter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCurrency(): string
|
||||
{
|
||||
if (null === $this->getCustomer()) {
|
||||
|
||||
Reference in New Issue
Block a user