2010-11-18 22:33:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-01-15 13:29:43 +00:00
|
|
|
* This file is part of the Symfony package.
|
2010-11-18 22:33:44 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-11-18 22:33:44 +00:00
|
|
|
*
|
2011-01-15 13:29:43 +00:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
2010-11-18 22:33:44 +00:00
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Component\Form;
|
|
|
|
|
2010-11-18 22:33:44 +00:00
|
|
|
/**
|
2011-03-21 20:01:14 +00:00
|
|
|
* Wraps errors in forms
|
2010-11-18 22:33:44 +00:00
|
|
|
*
|
2012-05-26 08:48:33 +01:00
|
|
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
2010-11-18 22:33:44 +00:00
|
|
|
*/
|
2011-03-21 20:01:14 +00:00
|
|
|
class FormError
|
2010-11-18 22:33:44 +00:00
|
|
|
{
|
2012-11-27 22:17:30 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $message;
|
|
|
|
|
2011-03-21 20:01:14 +00:00
|
|
|
/**
|
|
|
|
* The template for the error message
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $messageTemplate;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The parameters that should be substituted in the message template
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $messageParameters;
|
|
|
|
|
2012-02-02 12:36:42 +00:00
|
|
|
/**
|
|
|
|
* The value for error message pluralization
|
|
|
|
* @var integer|null
|
|
|
|
*/
|
|
|
|
protected $messagePluralization;
|
|
|
|
|
2011-03-21 20:01:14 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
2011-07-09 15:14:57 +01:00
|
|
|
* Any array key in $messageParameters will be used as a placeholder in
|
|
|
|
* $messageTemplate.
|
|
|
|
*
|
2012-11-27 22:17:30 +00:00
|
|
|
* @param string $message The translated error message
|
|
|
|
* @param string|null $messageTemplate The template for the error message
|
2012-08-26 07:28:19 +01:00
|
|
|
* @param array $messageParameters The parameters that should be
|
|
|
|
* substituted in the message template.
|
|
|
|
* @param integer|null $messagePluralization The value for error message pluralization
|
2012-11-27 22:17:30 +00:00
|
|
|
*
|
|
|
|
* @see \Symfony\Component\Translation\Translator
|
2011-03-21 20:01:14 +00:00
|
|
|
*/
|
2012-11-27 22:17:30 +00:00
|
|
|
public function __construct($message, $messageTemplate = null, array $messageParameters = array(), $messagePluralization = null)
|
2011-03-21 20:01:14 +00:00
|
|
|
{
|
2012-11-27 22:17:30 +00:00
|
|
|
$this->message = $message;
|
|
|
|
$this->messageTemplate = $messageTemplate ?: $message;
|
2011-03-21 20:01:14 +00:00
|
|
|
$this->messageParameters = $messageParameters;
|
2012-02-02 12:36:42 +00:00
|
|
|
$this->messagePluralization = $messagePluralization;
|
2011-03-21 20:01:14 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 17:26:32 +00:00
|
|
|
/**
|
|
|
|
* Returns the error message
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getMessage()
|
|
|
|
{
|
2012-11-27 22:17:30 +00:00
|
|
|
return $this->message;
|
2011-11-29 17:26:32 +00:00
|
|
|
}
|
|
|
|
|
2011-03-21 20:01:14 +00:00
|
|
|
/**
|
|
|
|
* Returns the error message template
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getMessageTemplate()
|
|
|
|
{
|
|
|
|
return $this->messageTemplate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the parameters to be inserted in the message template
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getMessageParameters()
|
|
|
|
{
|
|
|
|
return $this->messageParameters;
|
|
|
|
}
|
2012-02-02 12:36:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the value for error message pluralization.
|
|
|
|
*
|
|
|
|
* @return integer|null
|
|
|
|
*/
|
|
|
|
public function getMessagePluralization()
|
|
|
|
{
|
|
|
|
return $this->messagePluralization;
|
|
|
|
}
|
2011-06-08 11:16:48 +01:00
|
|
|
}
|