[Translations] Throw exception if xFileLoader dependencies don't exist.

This commit is contained in:
Jesse Rushlow 2020-05-02 10:52:09 -04:00 committed by Fabien Potencier
parent c30d6f9e38
commit 627e476eb4
2 changed files with 10 additions and 0 deletions

View File

@ -15,6 +15,7 @@ use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Config\Util\XmlUtils;
use Symfony\Component\Translation\Exception\InvalidResourceException;
use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Translation\Exception\RuntimeException;
use Symfony\Component\Translation\MessageCatalogue;
/**
@ -29,6 +30,10 @@ class QtFileLoader implements LoaderInterface
*/
public function load($resource, string $locale, string $domain = 'messages')
{
if (!class_exists(XmlUtils::class)) {
throw new RuntimeException('Loading translations from the QT format requires the Symfony Config component.');
}
if (!stream_is_local($resource)) {
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
}

View File

@ -15,6 +15,7 @@ use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Config\Util\XmlUtils;
use Symfony\Component\Translation\Exception\InvalidResourceException;
use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Translation\Exception\RuntimeException;
use Symfony\Component\Translation\MessageCatalogue;
use Symfony\Component\Translation\Util\XliffUtils;
@ -30,6 +31,10 @@ class XliffFileLoader implements LoaderInterface
*/
public function load($resource, string $locale, string $domain = 'messages')
{
if (!class_exists(XmlUtils::class)) {
throw new RuntimeException('Loading translations from the Xliff format requires the Symfony Config component.');
}
if (!stream_is_local($resource)) {
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
}