checkDate example

$value = (string) $value;

        if (!preg_match(static::PATTERN, $value$matches)) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ value }}', $this->formatValue($value))
                ->setCode(Date::INVALID_FORMAT_ERROR)
                ->addViolation();

            return;
        }

        if (!self::checkDate(
            $matches['year'] ?? $matches[1],
            $matches['month'] ?? $matches[2],
            $matches['day'] ?? $matches[3]
        )) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ value }}', $this->formatValue($value))
                ->setCode(Date::INVALID_DATE_ERROR)
                ->addViolation();
        }
    }
}
$value = (string) $value;

        if (!preg_match(static::PATTERN, $value$matches)) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ value }}', $this->formatValue($value))
                ->setCode(Date::INVALID_FORMAT_ERROR)
                ->addViolation();

            return;
        }

        if (!self::checkDate(
            $matches['year'] ?? $matches[1],
            $matches['month'] ?? $matches[2],
            $matches['day'] ?? $matches[3]
        )) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ value }}', $this->formatValue($value))
                ->setCode(Date::INVALID_DATE_ERROR)
                ->addViolation();
        }
    }
}
EOT;

            $prepareStatement = $this->pdo->prepare($sql);
            $prepareStatement->execute([
                ':module' => $license->module,
                ':host' => $license->host,
                ':label' => $license->label,
                ':license' => $license->license,
                ':version' => $license->version,
                ':type' => $license->type,
                ':source' => $license->source,
                ':creation' => $this->checkDate($license->creation),
                ':expiration' => $this->checkDate($license->expiration),
            ]);
        } catch (PDOException $e) {
            throw new RuntimeException('Could not insert license into database', 0, $e);
        }
    }

    /** * Checks if a date string is plausible. * If not, returns null. Otherwise the string. * * @param string $date * * @return string|null */
EOT;

            $prepareStatement = $this->connection->prepare($sql);
            $prepareStatement->execute([
                ':module' => $license->module,
                ':host' => $license->host,
                ':label' => $license->label,
                ':license' => $license->license,
                ':version' => $license->version,
                ':type' => $license->type,
                ':source' => $license->source,
                ':creation' => $this->checkDate($license->creation),
                ':expiration' => $this->checkDate($license->expiration),
            ]);
        } catch (PDOException $e) {
            throw new RuntimeException('Could not insert license into database', 0, $e);
        }
    }

    /** * Checks if a date string is plausible. * If not, returns null. Otherwise the string. * * @param string $date * * @return string|null */
Home | Imprint | This part of the site doesn't use cookies.