[Validator] Added ExceptionInterface, BadMethodCallException and InvalidArgumentException

This commit is contained in:
Bernhard Schussek 2013-01-08 15:20:14 +01:00
parent e00e5ecf4e
commit cd662ccf7a
5 changed files with 69 additions and 3 deletions

View File

@ -38,6 +38,7 @@ CHANGELOG
* [BC BREAK] added `setTranslator()` and `setTranslationDomain()` to `ValidatorBuilderInterface` * [BC BREAK] added `setTranslator()` and `setTranslationDomain()` to `ValidatorBuilderInterface`
* improved the Validator to support pluralized messages by default * improved the Validator to support pluralized messages by default
* [BC BREAK] changed the source of all pluralized messages in the translation files to the pluralized version * [BC BREAK] changed the source of all pluralized messages in the translation files to the pluralized version
* added ExceptionInterface, BadMethodCallException and InvalidArgumentException
2.1.0 2.1.0
----- -----

View File

@ -11,6 +11,8 @@
namespace Symfony\Component\Validator; namespace Symfony\Component\Validator;
use Symfony\Component\Validator\Exception\BadMethodCallException;
use Symfony\Component\Validator\Exception\InvalidArgumentException;
use Symfony\Component\Translation\TranslatorInterface; use Symfony\Component\Translation\TranslatorInterface;
/** /**
@ -43,7 +45,7 @@ class DefaultTranslator implements TranslatorInterface
} }
if (!isset($ids[1])) { if (!isset($ids[1])) {
throw new \InvalidArgumentException(sprintf('The message "%s" cannot be pluralized, because it is missing a plural (e.g. "There is one apple|There are %%count%% apples").', $id)); throw new InvalidArgumentException(sprintf('The message "%s" cannot be pluralized, because it is missing a plural (e.g. "There is one apple|There are %%count%% apples").', $id));
} }
return strtr($ids[1], $parameters); return strtr($ids[1], $parameters);
@ -54,7 +56,7 @@ class DefaultTranslator implements TranslatorInterface
*/ */
public function setLocale($locale) public function setLocale($locale)
{ {
throw new \BadMethodCallException('Unsupported method.'); throw new BadMethodCallException('Unsupported method.');
} }
/** /**
@ -62,6 +64,6 @@ class DefaultTranslator implements TranslatorInterface
*/ */
public function getLocale() public function getLocale()
{ {
throw new \BadMethodCallException('Unsupported method.'); throw new BadMethodCallException('Unsupported method.');
} }
} }

View File

@ -0,0 +1,21 @@
<?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\Exception;
/**
* Base BadMethodCallException for the Validator component.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class BadMethodCallException extends \BadMethodCallException implements ExceptionInterface
{
}

View File

@ -0,0 +1,21 @@
<?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\Exception;
/**
* Base ExceptionInterface for the Validator component.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
interface ExceptionInterface
{
}

View File

@ -0,0 +1,21 @@
<?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\Exception;
/**
* Base InvalidArgumentException for the Validator component.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{
}