Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix the documentation of the Traverse constraint #12967

Closed
@guilliamxavier

Description

@guilliamxavier

#11310 (comment)

The current code fromhttps://symfony.com/doc/4.4/reference/constraints/Traverse.html:

<?php// src/Entity/Book.phpnamespaceApp\Entity;useDoctrine\ORM\MappingasORM;useSymfony\Component\Validator\ConstraintsasAssert;/** * @ORM\Entity * @Assert\Traverse */class Book{/**     * @var Author     *     * @ORM\ManyToOne(targetEntity="App\Entity\Author")     */protected$author;/**     * @var Editor     *     * @ORM\ManyToOne(targetEntity="App\Entity\Editor")     */protected$editor;// ...}

throws a\Symfony\Component\Validator\Exception\ConstraintDefinitionException with messageTraversal was enabled for "App\Entity\Book", but this class does not implement "\Traversable". (fromvendor/symfony/validator/Validator/RecursiveContextualValidator.php).

Fromsymfony/symfony#10287:

Control traversal at class level (symfony/symfony#8617)

Currently, it is possible whether to traverse aTraversable object or not in theValid constraint:

/** * @Assert\Valid(traverse=true) */private $tags = new TagList();

(actually,true is the default)

In this way, the validator will iterate theTagList instance and validate each of the contained objects. You can also set "traverse" tofalse to disable iteration.

What if you want to specify, thatTagList instances should always (or never) be traversed? That's currently not possible.

With this PR, you can do the following:

/** * @Assert\Traverse(false) */class TagList implements \IteratorAggregate{    // ...}

I understand that theTraverse constraint is not at all a "shorthand" forValid constraints on all nested objects, but rather a means to always disable validator traversal on a custom\Traversable class. (But I may be wrong)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp