8000 [Translation] added Base Exception for the component. · symfony/symfony@0fa2bce · GitHub
[go: up one dir, main page]

Skip to content

Commit 0fa2bce

Browse files
committed
[Translation] added Base Exception for the component.
1 parent a4a2019 commit 0fa2bce

22 files changed

+120
-36
lines changed

src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php

B422 Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Translation\Translator as BaseTranslator;
1616
use Symfony\Component\Translation\MessageSelector;
1717
use Symfony\Component\DependencyInjection\ContainerInterface;
18+
use Symfony\Component\Translation\Exception\InvalidArgumentException;
1819

1920
/**
2021
* Translator.
@@ -60,7 +61,7 @@ public function __construct(ContainerInterface $container, MessageSelector $sele
6061

6162
// check option names
6263
if ($diff = array_diff(array_keys($options), array_keys($this->options))) {
63-
throw new \InvalidArgumentException(sprintf('The Translator does not support the following options: \'%s\'.', implode('\', \'', $diff)));
64+
throw new InvalidArgumentException(sprintf('The Translator does not support the following options: \'%s\'.', implode('\', \'', $diff)));
6465
}
6566

6667
$this->options = array_merge($this->options, $options);

src/Symfony/Component/Translation/Catalogue/AbstractOperation.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use Symfony\Component\Translation\MessageCatalogue;
1515
use Symfony\Component\Translation\MessageCatalogueInterface;
16+
use Symfony\Component\Translation\Exception\InvalidArgumentException;
17+
use Symfony\Component\Translation\Exception\LogicException;
1618

1719
/**
1820
* Base catalogues binary operation class.
@@ -77,7 +79,7 @@ abstract class AbstractOperation implements OperationInterface
7779
public function __construct(MessageCatalogueInterface $source, MessageCatalogueInterface $target)
7880
{
7981
if ($source->getLocale() !== $target->getLocale()) {
80-
throw new \LogicException('Operated catalogues must belong to the same locale.');
82+
throw new LogicException('Operated catalogues must belong to the same locale.');
8183
}
8284

8385
$this->source = $source;
@@ -105,7 +107,7 @@ public function getDomains()
105107
public function getMessages($domain)
106108
{
107109
if (!in_array($domain, $this->getDomains())) {
108-
throw new \InvalidArgumentException(sprintf('Invalid domain: %s.', $domain));
110+
throw new InvalidArgumentException(sprintf('Invalid domain: %s.', $domain));
109111
}
110112

111113
if (!isset($this->messages[$domain]['all'])) {
@@ -121,7 +123,7 @@ public function getMessages($domain)
121123
public function getNewMessages($domain)
122124
{
123125
if (!in_array($domain, $this->getDomains())) {
124-
throw new \InvalidArgumentException(sprintf('Invalid domain: %s.', $domain));
126+
throw new InvalidArgumentException(sprintf('Invalid domain: %s.', $domain));
125127
}
126128

127129
if (!isset($this->messages[$domain]['new'])) {
@@ -137,7 +139,7 @@ public function getNewMessages($domain)
137139
public function getObsoleteMessages($domain)
138140
{
139141
if (!in_array($domain, $this->getDomains())) {
140-
throw new \InvalidArgumentException(sprintf('Invalid domain: %s.', $domain));
142+
throw new InvalidArgumentException(sprintf('Invalid domain: %s.', $domain));
141143
}
142144

143145
if (!isset($this->messages[$domain]['obsolete'])) {

src/Symfony/Component/Translation/DataCollectorTranslator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Translation;
1313

14+
use Symfony\Component\Translation\Exception\InvalidArgumentException;
15+
1416
/**
1517
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
1618
*/
@@ -36,7 +38,7 @@ class DataCollectorTranslator implements TranslatorInterface, TranslatorBagInter
3638
public function __construct(TranslatorInterface $translator)
3739
{
3840
if (!$translator instanceof TranslatorBagInterface) {
39-
throw new \InvalidArgumentException(sprintf('The Translator "%s" must implement TranslatorInterface and TranslatorBagInterface.', get_class($translator)));
41+
throw new InvalidArgumentException(sprintf('The Translator "%s" must implement TranslatorInterface and TranslatorBagInterface.', get_class($translator)));
4042
}
4143

4244
$this->translator = $translator;

src/Symfony/Component/Translation/Dumper/FileDumper.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Translation\Dumper;
1313

1414
use Symfony\Component\Translation\MessageCatalogue;
15+
use Symfony\Component\Translation\Exception\InvalidArgumentException;
1516

1617
/**
1718
* FileDumper is an implementation of DumperInterface that dump a message catalogue to file(s).
@@ -64,7 +65,7 @@ public function setBackup($backup)
6465
public function dump(MessageCatalogue $messages, $options = array())
6566
{
6667
if (!array_key_exists('path', $options)) {
67-
throw new \InvalidArgumentException('The file dumper needs a path option.');
68+
throw new InvalidArgumentException('The file dumper needs a path option.');
6869
}
6970

7071
// save a file for each domain
@@ -79,7 +80,7 @@ public function dump(MessageCatalogue $messages, $options = array())
7980
} else {
8081
$directory = dirname($fullpath);
8182
if (!file_exists($directory) && !@mkdir($directory, 0777, true)) {
82-
throw new \RuntimeException(sprintf('Unable to create directory "%s".', $directory));
83+
throw new RuntimeException(sprintf('Unable to create directory "%s".', $directory));
8384
}
8485
}
8586
// save file

src/Symfony/Component/Translation/Dumper/XliffFileDumper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Translation\Dumper;
1313

1414
use Symfony\Component\Translation\MessageCatalogue;
15+
use Symfony\Component\Translation\Exception\InvalidArgumentException;
1516

1617
/**
1718
* XliffFileDumper generates xliff files from a message catalogue.
@@ -43,7 +44,7 @@ public function formatCatalogue(MessageCatalogue $messages, $domain, array $opti
4344
return $this->dumpXliff2($defaultLocale, $messages, $domain, $options);
4445
}
4546

46-
throw new \InvalidArgumentException(sprintf('No support implemented for dumping XLIFF version "%s".', $xliffVersion));
47+
throw new InvalidArgumentException(sprintf('No support implemented for dumping XLIFF version "%s".', $xliffVersion));
4748
}
4849

4950
/**

src/Symfony/Component/Translation/Dumper/YamlFileDumper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Translation\MessageCatalogue;
1515
use Symfony\Component\Translation\Util\ArrayConverter;
1616
use Symfony\Component\Yaml\Yaml;
17+
use Symfony\Component\Translation\Exception\LogicException;
1718

1819
/**
1920
* YamlFileDumper generates yaml files from a message catalogue.
@@ -28,7 +29,7 @@ class YamlFileDumper extends FileDumper
2829
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
2930
{
3031
if (!class_exists('Symfony\Component\Yaml\Yaml')) {
31-
throw new \LogicException('Dumping translations in the YAML format requires the Symfony Yaml component.');
32+
throw new LogicException('Dumping translations in the YAML format requires the Symfony Yaml component.');
3233
}
3334

3435
$data = $messages->all($domain);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Translation\Exception;
13+
14+
/**
15+
* Base InvalidArgumentException for the Translation component.
16+
*
17+
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
18+
*/
19+
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
20+
{
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Translation\Exception;
13+
14+
/**
15+
* Base LogicException for Translation component.
16+
*
17+
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
18+
*/
19+
class LogicException extends \LogicException implements ExceptionInterface
20+
{
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Translation\Exception;
13+
14+
/**
15+
* Base RuntimeException for the Translation component.
16+
*
17+
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
18+
*/
19+
class RuntimeException extends \RuntimeException implements ExceptionInterface
20+
{
21+
}

src/Symfony/Component/Translation/Extractor/AbstractFileExtractor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Translation\Extractor;
1313

14+
use Symfony\Component\Translation\Exception\InvalidArgumentException;
15+
1416
/**
1517
* Base class used by classes that extract translation messages from files.
1618
*
@@ -61,7 +63,7 @@ private function toSplFileInfo($file)
6163
protected function isFile($file)
6264
{
6365
if (!is_file($file)) {
64-
throw new \InvalidArgumentException(sprintf('The "%s" file does not exist.', $file));
66+
throw new InvalidArgumentException(sprintf('The "%s" file does not exist.', $file));
6567
}
6668

6769
return true;

src/Symfony/Component/Translation/Interval.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Translation;
1313

14+
use Symfony\Component\Translation\Exception\InvalidArgumentException;
15+
1416
/**
1517
* Tests if a given number belongs to a given math interval.
1618
*
@@ -48,7 +50,7 @@ public static function test($number, $interval)
4850
$interval = trim($interval);
4951

5052
if (!preg_match('/^'.self::getIntervalRegexp().'$/x', $interval, $matches)) {
51-
throw new \InvalidArgumentException(sprintf('"%s" is not a valid interval.', $interval));
53+
throw new InvalidArgumentException(sprintf('"%s" is not a valid interval.', $interval));
5254
}
5355

5456
if ($matches[1]) {

src/Symfony/Component/Translation/Loader/XliffFileLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ private function getSchema($xliffVersion)
202202
$schemaSource = file_get_contents(__DIR__.'/schema/dic/xliff-core/xliff-core-2.0.xsd');
203203
$xmlUri = 'informativeCopiesOf3rdPartySchemas/w3c/xml.xsd';
204204
} else {
205-
throw new \InvalidArgumentException(sprintf('No support implemented for loading XLIFF version "%s".', $xliffVersion));
205+
throw new InvalidArgumentException(sprintf('No support implemented for loading XLIFF version "%s".', $xliffVersion));
206206
}
207207

208208
return $this->fixXmlLocation($schemaSource, $xmlUri);
@@ -283,7 +283,7 @@ private function getVersionNumber(\DOMDocument $dom)
283283
$namespace = $xliff->attributes->getNamedItem('xmlns');
284284
if ($namespace) {
285285
if (substr_compare('urn:oasis:names:tc:xliff:document:', $namespace->nodeValue, 0, 34) !== 0) {
286-
throw new \InvalidArgumentException(sprintf('Not a valid XLIFF namespace "%s"', $namespace));
286+
throw new InvalidArgumentException(sprintf('Not a valid XLIFF namespace "%s"', $namespace));
287287
}
288288

289289
return substr($namespace, 34);

src/Symfony/Component/Translation/Loader/YamlFileLoader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Translation\Loader;
1313

1414
use Symfony\Component\Translation\Exception\InvalidResourceException;
15+
use Symfony\Component\Translation\Exception\LogicException;
1516
use Symfony\Component\Yaml\Parser as YamlParser;
1617
use Symfony\Component\Yaml\Exception\ParseException;
1718

@@ -31,7 +32,7 @@ protected function loadResource($resource)
3132
{
3233
if (null === $this->yamlParser) {
3334
if (!class_exists('Symfony\Component\Yaml\Parser')) {
34-
throw new \LogicException('Loading translations from the YAML format requires the Symfony Yaml component.');
35+
throw new LogicException('Loading translations from the YAML format requires the Symfony Yaml component.');
3536
}
3637

3738
$this->yamlParser = new YamlParser();

src/Symfony/Component/Translation/LoggingTranslator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Translation;
1313

1414
use Psr\Log\LoggerInterface;
15+
use Symfony\Component\Translation\Exception\InvalidArgumentException;
1516

1617
/**
1718
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
@@ -35,7 +36,7 @@ class LoggingTranslator implements TranslatorInterface, TranslatorBagInterface
3536
public function __construct(TranslatorInterface $translator, LoggerInterface $logger)
3637
{
3738
if (!$translator instanceof TranslatorBagInterface) {
38-
throw new \InvalidArgumentException(sprintf('The Translator "%s" must implement TranslatorInterface and TranslatorBagInterface.', get_class($translator)));
39+
throw new InvalidArgumentException(sprintf('The Translator "%s" must implement TranslatorInterface and TranslatorBagInterface.', get_class($translator)));
3940
}
4041

4142
$this->translator = $translator;

src/Symfony/Component/Translation/MessageCatalogue.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Translation;
1313

1414
use Symfony\Component\Config\Resource\ResourceInterface;
15+
use Symfony\Component\Translation\Exception\LogicException;
1516

1617
/**
1718
* MessageCatalogue.
@@ -143,7 +144,7 @@ public function add($messages, $domain = 'messages')
143144
public function addCatalogue(MessageCatalogueInterface $catalogue)
144145
{
145146
if ($catalogue->getLocale() !== $this->locale) {
146-
throw new \LogicException(sprintf('Cannot add a catalogue for locale "%s" as the current locale for this catalogue is "%s"', $catalogue->getLocale(), $this->locale));
147+
throw new LogicException(sprintf('Cannot add a catalogue for locale "%s" as the current locale for this catalogue is "%s"', $catalogue->getLocale(), $this->locale));
147148
}
148149

149150
foreach ($catalogue->all() as $domain => $messages) {
@@ -169,14 +170,14 @@ public function addFallbackCatalogue(MessageCatalogueInterface $catalogue)
169170
$c = $catalogue;
170171
while ($c = $c->getFallbackCatalogue()) {
171172
if ($c->getLocale() === $this->getLocale()) {
172-
throw new \LogicException(sprintf('Circular reference detected when adding a fallback catalogue for locale "%s".', $catalogue->getLocale()));
173+
throw new LogicException(sprintf('Circular reference detected when adding a fallback catalogue for locale "%s".', $catalogue->getLocale()));
173174
}
174175
}
175176

176177
$c = $this;
177178
do {
178179
if ($c->getLocale() === $catalogue->getLocale()) {
179-
throw new \LogicException(sprintf('Circular reference detected when adding a fallback catalogue for locale "%s".', $catalogue->getLocale()));
180+
throw new LogicException(sprintf('Circular reference detected when adding a fallback catalogue for locale "%s".', $catalogue->getLocale()));
180181
}
181182
} while ($c = $c->parent);
182183

src/Symfony/Component/Translation/MessageSelector.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Translation;
1313

14+
use Symfony\Component\Translation\Exception\InvalidArgumentException;
15+
1416
/**
1517
* MessageSelector.
1618
*
@@ -78,7 +80,7 @@ public function choose($message, $number, $locale)
7880
return $standardRules[0];
7981
}
8082

81-
throw new \InvalidArgumentException(sprintf('Unable to choose a translation for "%s" with locale "%s" for value "%d". Double check that this translation has the correct plural options (e.g. "There is one apple|There are %%count%% apples").', $message, $locale, $number));
83+
throw new InvalidArgumentException(sprintf('Unable to choose a translation for "%s" with locale "%s" for value "%d". Double check that this translation has the correct plural options (e.g. "There is one apple|There are %%count%% apples").', $message, $locale, $number));
8284
}
8385

8486
return $standardRules[$position];

src/Symfony/Component/Translation/Tests/IntervalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testTest($expected, $number, $interval)
2424
}
2525

2626
/**
27-
* @expectedException \InvalidArgumentException
27+
* @expectedException \Symfony\Component\Translation\Exception\InvalidArgumentException
2828
*/
2929
public function testTestException()
3030
{

src/Symfony/Component/Translation/Tests/MessageCatalogueTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function testAddFallbackCatalogue()
125125
}
126126

127127
/**
128-
* @expectedException \LogicException
128+
* @expectedException \Symfony\Component\Translation\Exception\LogicException
129129
*/
130130
public function testAddFallbackCatalogueWithParentCircularReference()
131131
{
@@ -137,7 +137,7 @@ public function testAddFallbackCatalogueWithParentCircularReference()
137137
}
138138

139139
/**
140-
* @expectedException \LogicException
140+
* @expectedException \Symfony\Component\Translation\Exception\LogicException
141141
*/
142142
public function testAddFallbackCatalogueWithFallbackCircularReference()
143143
{
@@ -151,7 +151,7 @@ public function testAddFallbackCatalogueWithFallbackCircularReference()
151151
}
152152

153153
/**
154-
* @expectedException \LogicException
154+
* @expectedException \Symfony\Component\Translation\Exception\LogicException
155155
*/
156156
public function testAddCatalogueWhenLocaleIsNotTheSameAsTheCurrentOne()
157157
{

src/Symfony/Component/Translation/Tests/MessageSelectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testReturnMessageIfExactlyOneStandardRuleIsGiven()
3434

3535
/**
3636
* @dataProvider getNonMatchingMessages
37-
* @expectedException \InvalidArgumentException
37+
* @expectedException \Symfony\Component\Translation\Exception\InvalidArgumentException
3838
*/
3939
public function testThrowExceptionIfMatchingMessageCannotBeFound($id, $number)
4040
{

0 commit comments

Comments
 (0)
0