added new rounding mode: closest (#611)

This commit is contained in:
Kevin Papst
2019-03-03 20:33:35 +01:00
committed by GitHub
parent bea4be881b
commit 642db480ce
11 changed files with 554 additions and 73 deletions

View File

@@ -11,6 +11,7 @@ namespace App\DependencyInjection;
use App\Model\DashboardSection;
use App\Model\Widget;
use App\Timesheet\Rounding\RoundingInterface;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
@@ -81,6 +82,21 @@ class Configuration implements ConfigurationInterface
->integerNode('duration')
->defaultValue(0)
->end()
->scalarNode('mode')
->defaultValue('default')
->validate()
->thenInvalid('Chosen rounding mode is invalid')
->ifTrue(function ($value) {
$class = 'App\\Timesheet\\Rounding\\' . ucfirst($value) . 'Rounding';
if (class_exists($class)) {
$rounding = new $class();
return !($rounding instanceof RoundingInterface);
}
return false;
})
->thenInvalid('Chosen rounding mode is invalid')
->end()
->end()
->end()
->end()
->defaultValue([])