* added api URL for simpler integration * allow to request password change upon next login * make ModifiedAt timesheet independent * improved plugin api * replace kernel calls with AutoconfigureTag and TaggedIterator attributes * new translation keys (e.g. for days) * support setting min and max date on date and daterange pickers
56 lines
1.7 KiB
PHP
56 lines
1.7 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Kimai time-tracking app.
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace App\Validator\Constraints;
|
|
|
|
use App\Entity\Timesheet as TimesheetEntity;
|
|
use App\Validator\Constraints\QuickEntryTimesheet as QuickEntryTimesheetConstraint;
|
|
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
|
|
use Symfony\Component\Validator\Constraint;
|
|
use Symfony\Component\Validator\ConstraintValidator;
|
|
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
|
|
|
final class QuickEntryTimesheetValidator extends ConstraintValidator
|
|
{
|
|
/**
|
|
* @param TimesheetConstraint[] $constraints
|
|
*/
|
|
public function __construct(
|
|
#[TaggedIterator(TimesheetConstraint::class)]
|
|
private iterable $constraints
|
|
)
|
|
{
|
|
}
|
|
|
|
public function validate(mixed $value, Constraint $constraint): void
|
|
{
|
|
if (!$constraint instanceof QuickEntryTimesheetConstraint) {
|
|
throw new UnexpectedTypeException($constraint, QuickEntryTimesheetConstraint::class);
|
|
}
|
|
|
|
if (!\is_object($value) || !($value instanceof TimesheetEntity)) {
|
|
throw new UnexpectedTypeException($value, TimesheetEntity::class);
|
|
}
|
|
|
|
$timesheet = $value;
|
|
|
|
if ($timesheet->getId() === null && $timesheet->getDuration(false) === null) {
|
|
return;
|
|
}
|
|
|
|
foreach ($this->constraints as $innerConstraint) {
|
|
$this->context
|
|
->getValidator()
|
|
->inContext($this->context)
|
|
->atPath('duration')
|
|
->validate($timesheet, $innerConstraint, [Constraint::DEFAULT_GROUP]);
|
|
}
|
|
}
|
|
}
|