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
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Bernhard Schussek <bernhard.schussek@symfony.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
|
|
|
{
|
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.
|
|
|
|
* @see Symfony\Component\Translation\Translator
|
|
|
|
*
|
2012-05-15 21:19:31 +01:00
|
|
|
* @param string $messageTemplate The template for the error message
|
|
|
|
* @param array $messageParameters The parameters that should be
|
2012-02-02 12:36:42 +00:00
|
|
|
* substituted in the message template.
|
|
|
|
* @param integer $messagePluralization The value for error message pluralization
|
2011-03-21 20:01:14 +00:00
|
|
|
*/
|
2012-02-02 12:36:42 +00:00
|
|
|
public function __construct($messageTemplate, array $messageParameters = array(), $messagePluralization = null)
|
2011-03-21 20:01:14 +00:00
|
|
|
{
|
|
|
|
$this->messageTemplate = $messageTemplate;
|
|
|
|
$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()
|
|
|
|
{
|
|
|
|
return strtr($this->messageTemplate, $this->messageParameters);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|