Skip to content

Commit 4603907

Browse files
committed
[Translation] added Base Exception for the component.
1 parent 3dedbc8 commit 4603907

23 files changed

+133
-49
lines changed

Catalogue/AbstractOperation.php

Lines changed: 7 additions & 5 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.
@@ -72,12 +74,12 @@ abstract class AbstractOperation implements OperationInterface
7274
* @param MessageCatalogueInterface $source The source catalogue
7375
* @param MessageCatalogueInterface $target The target catalogue
7476
*
75-
* @throws \LogicException
77+
* @throws LogicException
7678
*/
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'])) {

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 <[email protected]>
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;

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

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
/**

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 <[email protected]>
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 <[email protected]>
18+
*/
19+
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
20+
{
21+
}

Exception/LogicException.php

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 <[email protected]>
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 <[email protected]>
18+
*/
19+
class LogicException extends \LogicException implements ExceptionInterface
20+
{
21+
}

Exception/RuntimeException.php

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 <[email protected]>
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 <[email protected]>
18+
*/
19+
class RuntimeException extends \RuntimeException implements ExceptionInterface
20+
{
21+
}

Extractor/AbstractFileExtractor.php

Lines changed: 4 additions & 2 deletions
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
*
@@ -56,12 +58,12 @@ private function toSplFileInfo($file)
5658
*
5759
* @return bool
5860
*
59-
* @throws \InvalidArgumentException
61+
* @throws InvalidArgumentException
6062
*/
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;

Interval.php

Lines changed: 4 additions & 2 deletions
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
*
@@ -41,14 +43,14 @@ class Interval
4143
*
4244
* @return bool
4345
*
44-
* @throws \InvalidArgumentException
46+
* @throws InvalidArgumentException
4547
*/
4648
public static function test($number, $interval)
4749
{
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]) {

0 commit comments

Comments
 (0)