Skip to content

Commit

Permalink
[Validator] Added ExceptionInterface, BadMethodCallException and Inva…
Browse files Browse the repository at this point in the history
…lidArgumentException
  • Loading branch information
webmozart committed Jan 8, 2013
1 parent e00e5ec commit cd662cc
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Symfony/Component/Validator/CHANGELOG.md
Expand Up @@ -38,6 +38,7 @@ CHANGELOG
* [BC BREAK] added `setTranslator()` and `setTranslationDomain()` to `ValidatorBuilderInterface`
* 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
* added ExceptionInterface, BadMethodCallException and InvalidArgumentException

2.1.0
-----
Expand Down
8 changes: 5 additions & 3 deletions src/Symfony/Component/Validator/DefaultTranslator.php
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\Validator;

use Symfony\Component\Validator\Exception\BadMethodCallException;
use Symfony\Component\Validator\Exception\InvalidArgumentException;
use Symfony\Component\Translation\TranslatorInterface;

/**
Expand Down Expand Up @@ -43,7 +45,7 @@ public function transChoice($id, $number, array $parameters = array(), $domain =
}

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);
Expand All @@ -54,14 +56,14 @@ public function transChoice($id, $number, array $parameters = array(), $domain =
*/
public function setLocale($locale)
{
throw new \BadMethodCallException('Unsupported method.');
throw new BadMethodCallException('Unsupported method.');
}

/**
* {@inheritdoc}
*/
public function getLocale()
{
throw new \BadMethodCallException('Unsupported method.');
throw new BadMethodCallException('Unsupported method.');
}
}
@@ -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
{
}
21 changes: 21 additions & 0 deletions src/Symfony/Component/Validator/Exception/ExceptionInterface.php
@@ -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
{
}
@@ -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
{
}

0 comments on commit cd662cc

Please sign in to comment.