Skip to content

Commit f50b2c5

Browse files
committed
bug symfony#10697 [Translation] Make IcuDatFileLoader/IcuResFileLoader::load invalid resource compatible with HHVM. (idn2104)
This PR was squashed before being merged into the 2.3 branch (closes symfony#10697). Discussion ---------- [Translation] Make IcuDatFileLoader/IcuResFileLoader::load invalid resource compatible with HHVM. [Translation] HHVM throws when an invalid ResourceBundle is constructed, while zend returns FALSE from the constructor. This patch makes IcuResFileLoader and IcuDatFileLoader compatible with HHVM. The following tests now pass on HHVM: https://github.com/symfony/symfony/blob/2.3/src/Symfony/Component/Translation/Tests/Loader/IcuDatFileLoaderTest.php#L33 https://github.com/symfony/symfony/blob/2.3/src/Symfony/Component/Translation/Tests/Loader/IcuResFileLoaderTest.php#L54 | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | N/A | License | MIT | Doc PR | N/A Commits ------- 9bc08c0 [Translation] Make IcuDatFileLoader/IcuResFileLoader::load invalid resource compatible with HHVM.
2 parents e81c872 + 9bc08c0 commit f50b2c5

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)