This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Validator/ConstraintViolation.php
Fabien Potencier df3d543349 Merge branch '2.4'
* 2.4:
  made types consistent with those defined in Hack
  made {@inheritdoc} annotations consistent across the board
  made {@inheritdoc} annotations consistent across the board
  fixed types in phpdocs
  [Debug] Fixed ClassNotFoundFatalErrorHandler on windows.
  made phpdoc types consistent with those defined in Hack
  Add support Thai translations
  [Validator] Add missing czech translations
  made types consistent with those defined in Hack
  removed extra/unsupported arguments
  [HttpKernel] fixed an error message
  [TwigBundle] removed undefined argument
  [Translation] Make IcuDatFileLoader/IcuResFileLoader::load invalid resource compatible with HHVM.

Conflicts:
	src/Symfony/Component/Console/Helper/TableHelper.php
	src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php
	src/Symfony/Component/Form/FormError.php
	src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php
	src/Symfony/Component/Process/ProcessPipes.php
	src/Symfony/Component/PropertyAccess/PropertyAccessor.php
	src/Symfony/Component/Security/Acl/Dbal/MutableAclProvider.php
	src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeServices.php
	src/Symfony/Component/Translation/Dumper/FileDumper.php
	src/Symfony/Component/Validator/ConstraintViolation.php
	src/Symfony/Component/Validator/Constraints/EmailValidator.php
	src/Symfony/Component/Validator/ExecutionContextInterface.php
	src/Symfony/Component/Validator/Mapping/BlackholeMetadataFactory.php
2014-04-16 10:08:40 +02:00

199 lines
4.3 KiB
PHP

<?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\Validator;
/**
* Default implementation of {@ConstraintViolationInterface}.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class ConstraintViolation implements ConstraintViolationInterface
{
/**
* @var string
*/
private $message;
/**
* @var string
*/
private $messageTemplate;
/**
* @var array
*/
private $parameters;
/**
* @var integer|null
*/
private $plural;
/**
* @var mixed
*/
private $root;
/**
* @var string
*/
private $propertyPath;
/**
* @var mixed
*/
private $invalidValue;
/**
* @var mixed
*/
private $code;
/**
* Creates a new constraint violation.
*
* @param string $message The violation message
* @param string $messageTemplate The raw violation message
* @param array $parameters The parameters to substitute in the
* raw violation message
* @param mixed $root The value originally passed to the
* validator
* @param string $propertyPath The property path from the root
* value to the invalid value
* @param mixed $invalidValue The invalid value that caused this
* violation
* @param int|null $plural The number for determining the plural
* form when translating the message
* @param mixed $code The error code of the violation
*/
public function __construct($message, $messageTemplate, array $parameters, $root, $propertyPath, $invalidValue, $plural = null, $code = null)
{
$this->message = $message;
$this->messageTemplate = $messageTemplate;
$this->parameters = $parameters;
$this->plural = $plural;
$this->root = $root;
$this->propertyPath = $propertyPath;
$this->invalidValue = $invalidValue;
$this->code = $code;
}
/**
* Converts the violation into a string for debugging purposes.
*
* @return string The violation as string.
*/
public function __toString()
{
if (is_object($this->root)) {
$class = get_class($this->root);
} elseif (is_array($this->root)) {
$class = "Array";
} else {
$class = (string) $this->root;
}
$propertyPath = (string) $this->propertyPath;
$code = $this->code;
if ('' !== $propertyPath && '[' !== $propertyPath[0] && '' !== $class) {
$class .= '.';
}
if (!empty($code)) {
$code = ' (code '.$code.')';
}
return $class.$propertyPath.":\n ".$this->getMessage().$code;
}
/**
* {@inheritdoc}
*/
public function getMessageTemplate()
{
return $this->messageTemplate;
}
/**
* {@inheritdoc}
*/
public function getMessageParameters()
{
return $this->parameters;
}
/**
* Alias of {@link getMessageParameters()}.
*/
public function getParameters()
{
return $this->parameters;
}
/**
* {@inheritdoc}
*/
public function getMessagePluralization()
{
return $this->plural;
}
/**
* Alias of {@link getMessagePluralization()}.
*/
public function getPlural()
{
return $this->plural;
}
/**
* {@inheritdoc}
*/
public function getMessage()
{
return $this->message;
}
/**
* {@inheritdoc}
*/
public function getRoot()
{
return $this->root;
}
/**
* {@inheritdoc}
*/
public function getPropertyPath()
{
return $this->propertyPath;
}
/**
* {@inheritdoc}
*/
public function getInvalidValue()
{
return $this->invalidValue;
}
/**
* {@inheritdoc}
*/
public function getCode()
{
return $this->code;
}
}