Skip to content

Commit 0b87dea

Browse files
author
Mathieu Lechat
committed
Implement check using an interface
1 parent 559d573 commit 0b87dea

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\Validator\Constraints;
13+
14+
interface EntityDto
15+
{
16+
public function isForEntity($entity): bool;
17+
}

src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntity.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class UniqueEntity extends Constraint
3333
public $fields = array();
3434
public $errorPath = null;
3535
public $ignoreNull = true;
36-
public $forUpdate = false;
3736

3837
protected static $errorNames = array(
3938
self::NOT_UNIQUE_ERROR => 'NOT_UNIQUE_ERROR',

src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,13 @@ public function validate($entity, Constraint $constraint)
147147
}
148148

149149
if (1 === count($result)) {
150-
if ($constraint->forUpdate) {
150+
$match = $result instanceof \Iterator ? $result->current() : current($result);
151+
152+
if ($entity === $match) {
151153
return;
152154
}
153155

154-
if ($entity === ($result instanceof \Iterator ? $result->current() : current($result))) {
156+
if ($entity instanceof EntityDto && $entity->isForEntity($match)) {
155157
return;
156158
}
157159
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy