Skip to content

Commit 9bc08c0

Browse files
idn2104fabpot
authored andcommitted
[Translation] Make IcuDatFileLoader/IcuResFileLoader::load invalid resource compatible with HHVM.
1 parent 73f6c16 commit 9bc08c0

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

src/Symfony/Component/Intl/ResourceBundle/Reader/BinaryBundleReader.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ public function read($path, $locale)
2828
{
2929
// Point for future extension: Modify this class so that it works also
3030
// if the \ResourceBundle class is not available.
31-
$bundle = new \ResourceBundle($locale, $path);
31+
try {
32+
$bundle = new \ResourceBundle($locale, $path);
33+
} catch (\Exception $e) {
34+
// HHVM compatibility: constructor throws on invalid resource
35+
$bundle = null;
36+
}
3237

3338
if (null === $bundle) {
3439
throw new RuntimeException(sprintf(

src/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/LocaleBundleTransformationRule.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,12 @@ private function scanLocales(CompilationContextInterface $context)
119119
}
120120

121121
// Delete locales that have no content (i.e. only "Version" key)
122-
$bundle = new \ResourceBundle($locale, $tempDir);
122+
try {
123+
$bundle = new \ResourceBundle($locale, $tempDir);
124+
} catch (\Exception $e) {
125+
// HHVM compatibility: constructor throws on invalid resource
126+
$bundle = null;
127+
}
123128

124129
if (null === $bundle) {
125130
throw new RuntimeException('The resource bundle for locale ' . $locale . ' could not be loaded from directory ' . $tempDir);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ public function load($resource, $locale, $domain = 'messages')
3636
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
3737
}
3838

39-
$rb = new \ResourceBundle($locale, $resource);
39+
try {
40+
$rb = new \ResourceBundle($locale, $resource);
41+
} catch (\Exception $e) {
42+
// HHVM compatibility: constructor throws on invalid resource
43+
$rb = null;
44+
}
4045

4146
if (!$rb) {
4247
throw new InvalidResourceException(sprintf('Cannot load resource "%s"', $resource));

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ public function load($resource, $locale, $domain = 'messages')
3636
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
3737
}
3838

39-
$rb = new \ResourceBundle($locale, $resource);
39+
try {
40+
$rb = new \ResourceBundle($locale, $resource);
41+
} catch (\Exception $e) {
42+
// HHVM compatibility: constructor throws on invalid resource
43+
$rb = null;
44+
}
4045

4146
if (!$rb) {
4247
throw new InvalidResourceException(sprintf('Cannot load resource "%s"', $resource));

0 commit comments

Comments
 (0)