Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Form] Greatly improved the error mapping done in DelegatingValidatio…
…nListener
- Loading branch information
Showing
17 changed files
with
2,769 additions
and
641 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/Symfony/Component/Form/Exception/ErrorMappingException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Form\Exception; | ||
|
||
class ErrorMappingException extends FormException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/Symfony/Component/Form/Extension/Validator/ViolationMapper/FormMapping.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Form\Extension\Validator\ViolationMapper; | ||
|
||
use Symfony\Component\Form\FormInterface; | ||
use Symfony\Component\Form\Exception\ErrorMappingException; | ||
|
||
/** | ||
* @author Bernhard Schussek <bschussek@gmail.com> | ||
*/ | ||
class FormMapping | ||
{ | ||
/** | ||
* @var FormInterface | ||
*/ | ||
private $origin; | ||
|
||
/** | ||
* @var FormInterface | ||
*/ | ||
private $target; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $targetPath; | ||
|
||
public function __construct(FormInterface $origin, $targetPath) | ||
{ | ||
$this->origin = $origin; | ||
$this->targetPath = $targetPath; | ||
} | ||
|
||
/** | ||
* @return FormInterface | ||
*/ | ||
public function getOrigin() | ||
{ | ||
return $this->origin; | ||
} | ||
|
||
/** | ||
* @return FormInterface | ||
* | ||
* @throws ErrorMappingException | ||
*/ | ||
public function getTarget() | ||
{ | ||
// Lazy initialization to make sure that the constructor is cheap | ||
if (null === $this->target) { | ||
$childNames = explode('.', $this->targetPath); | ||
$target = $this->origin; | ||
|
||
foreach ($childNames as $childName) { | ||
if (!$target->has($childName)) { | ||
throw new ErrorMappingException(sprintf('The child "%s" of "%s" mapped by the rule "%s" in "%s" does not exist.', $childName, $target->getName(), $this->targetPath, $this->origin->getName())); | ||
} | ||
$target = $target->get($childName); | ||
} | ||
|
||
// Only set once successfully resolved | ||
$this->target = $target; | ||
} | ||
|
||
return $this->target; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/Symfony/Component/Form/Extension/Validator/ViolationMapper/RelativePath.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Form\Extension\Validator\ViolationMapper; | ||
|
||
use Symfony\Component\Form\FormInterface; | ||
use Symfony\Component\Form\Util\PropertyPath; | ||
|
||
/** | ||
* @author Bernhard Schussek <bschussek@gmail.com> | ||
*/ | ||
class RelativePath extends PropertyPath | ||
{ | ||
/** | ||
* @var FormInterface | ||
*/ | ||
private $root; | ||
|
||
/** | ||
* @param FormInterface $root | ||
* @param string $propertyPath | ||
*/ | ||
public function __construct(FormInterface $root, $propertyPath) | ||
{ | ||
parent::__construct($propertyPath); | ||
|
||
$this->root = $root; | ||
} | ||
|
||
/** | ||
* @return FormInterface | ||
*/ | ||
public function getRoot() | ||
{ | ||
return $this->root; | ||
} | ||
} |
Oops, something went wrong.