Time

Validates that a value is a valid time, meaning a string (or an object that can be cast into a string) that follows a valid HH:MM:SS format.

値が有効な時刻、つまり有効な HH:MM:SS 形式に従う文字列 (または文字列にキャストできるオブジェクト) であることを検証します。
Applies to property or method
Class Time
Validator TimeValidator

Basic Usage

Suppose you have an Event class, with a startsAt field that is the time of the day when the event starts:

イベントが開始する時刻である startsAt フィールドを持つ Event クラスがあるとします。
  • Attributes
    属性
  • YAML
    YAML
  • XML
    XML
  • PHP
    PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
// src/Entity/Event.php
namespace App\Entity;

use Symfony\Component\Validator\Constraints as Assert;

class Event
{
    /**
     * @var string A "H:i:s" formatted value
     */
    #[Assert\Time]
    protected $startsAt;
}

Note

ノート

As with most of the other constraints, null and empty strings are considered valid values. This is to allow them to be optional values. If the value is mandatory, a common solution is to combine this constraint with NotBlank.

他のほとんどの制約と同様に、null および空の文字列は有効な値と見なされます。これは、それらをオプションの値にできるようにするためです。値が必須の場合、一般的な解決策は、この制約と NotBlank を組み合わせることです。

Options

groups

type: array | string

タイプ: 配列 |ストリング

It defines the validation group or groups of this constraint. Read more about validation groups.

この制約の検証グループを定義します。検証グループの詳細を参照してください。

message

type: string default: This value is not a valid time.

タイプ: 文字列 デフォルト: この値は有効な時刻ではありません。

This message is shown if the underlying data is not a valid time.

このメッセージは、基になるデータが有効な時間でない場合に表示されます。

You can use the following parameters in this message:

このメッセージでは、次のパラメーターを使用できます。
Parameter Description
{{ value }} The current (invalid) value
{{ label }} Corresponding form field label

payload

type: mixed default: null

タイプ: 混合 デフォルト: null

This option can be used to attach arbitrary domain-specific data to a constraint. The configured payload is not used by the Validator component, but its processing is completely up to you.

このオプションは、任意のドメイン固有のデータを制約に添付するために使用できます。構成されたペイロードは Validator コンポーネントによって使用されませんが、その処理は完全にユーザー次第です。

For example, you may want to use several error levels to present failed constraints differently in the front-end depending on the severity of the error.

たとえば、いくつかのエラー レベルを使用して、エラーの重大度に応じて、失敗した制約をフロントエンドで異なる方法で提示することができます。