NotIdenticalTo

Validates that a value is not identical to another value, defined in the options. To force that a value is identical, see IdenticalTo.

値が、オプションで定義された別の値と同一でないことを検証します。値が同一であることを強制するには、IdenticalTo を参照してください。

Caution

注意

This constraint compares using !==, so 3 and "3" are considered not equal. Use NotEqualTo to compare with !=.

この制約は !== を使用して比較されるため、3 と "3" は等しくないと見なされます。 != と比較するには、NotEqualTo を使用します。

Basic Usage

The following constraints ensure that:

次の制約により、次のことが保証されます。
  • firstName of Person is not equal to Mary or not of the same type
    Person の firstName が Mary と等しくないか、同じタイプではありません
  • age of Person class is not equal to 15 or not of the same type
    Person クラスの age が 15 ではないか、同じタイプではありません
  • Attributes
    属性
  • YAML
    YAML
  • XML
    XML
  • PHP
    PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// src/Entity/Person.php
namespace App\Entity;

use Symfony\Component\Validator\Constraints as Assert;

class Person
{
    #[Assert\NotIdenticalTo('Mary')]
    protected $firstName;

    #[Assert\NotIdenticalTo(
        value: 15,
    )]
    protected $age;
}

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 should not be identical to {{ compared_value_type }} {{ compared_value }}.

タイプ: 文字列 デフォルト: この値は {{ 比較値のタイプ }} {{ 比較値 }} と同じであってはなりません。

This is the message that will be shown if the value is identical.

これは、値が同一である場合に表示されるメッセージです。

You can use the following parameters in this message:

このメッセージでは、次のパラメーターを使用できます。
Parameter Description
{{ compared_value }} The expected value
{{ compared_value_type }} The expected value type
{{ value }} The current (invalid) value

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.

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

propertyPath

type: string

タイプ: 文字列

It defines the object property whose value is used to make the comparison.

比較に使用される値を持つオブジェクト プロパティを定義します。

For example, if you want to compare the $endDate property of some object with regard to the $startDate property of the same object, use propertyPath="startDate" in the comparison constraint of $endDate.

たとえば、あるオブジェクトの $endDate プロパティを同じオブジェクトの $startDate プロパティと比較する場合、$endDate の比較制約でpropertyPath="startDate" を使用します。

Tip

ヒント

When using this option, its value is available in error messages as the {{ compared_value_path }} placeholder. Although it's not intended to include it in the error messages displayed to end users, it's useful when using APIs for doing any mapping logic on client-side.

このオプションを使用する場合、その値はエラー メッセージで {{比較値パス}} プレースホルダーとして利用できます。エンド ユーザーに表示されるエラー メッセージに含めることは意図されていませんが、クライアント側でマッピング ロジックを実行するために API を使用する場合に役立ちます。

value

type: mixed [default option]

タイプ: 混合 [デフォルト オプション]

This option is required. It defines the comparison value. It can be a string, number or object.

このオプションは必須です。比較値を定義します。文字列、数値、またはオブジェクトにすることができます。