bug #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 #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.
This commit is contained in:
commit
f50b2c59d5
@ -28,7 +28,12 @@ class BinaryBundleReader extends AbstractBundleReader implements BundleReaderInt
|
|||||||
{
|
{
|
||||||
// Point for future extension: Modify this class so that it works also
|
// Point for future extension: Modify this class so that it works also
|
||||||
// if the \ResourceBundle class is not available.
|
// if the \ResourceBundle class is not available.
|
||||||
$bundle = new \ResourceBundle($locale, $path);
|
try {
|
||||||
|
$bundle = new \ResourceBundle($locale, $path);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// HHVM compatibility: constructor throws on invalid resource
|
||||||
|
$bundle = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (null === $bundle) {
|
if (null === $bundle) {
|
||||||
throw new RuntimeException(sprintf(
|
throw new RuntimeException(sprintf(
|
||||||
|
@ -119,7 +119,12 @@ class LocaleBundleTransformationRule implements TransformationRuleInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delete locales that have no content (i.e. only "Version" key)
|
// Delete locales that have no content (i.e. only "Version" key)
|
||||||
$bundle = new \ResourceBundle($locale, $tempDir);
|
try {
|
||||||
|
$bundle = new \ResourceBundle($locale, $tempDir);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// HHVM compatibility: constructor throws on invalid resource
|
||||||
|
$bundle = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (null === $bundle) {
|
if (null === $bundle) {
|
||||||
throw new RuntimeException('The resource bundle for locale ' . $locale . ' could not be loaded from directory ' . $tempDir);
|
throw new RuntimeException('The resource bundle for locale ' . $locale . ' could not be loaded from directory ' . $tempDir);
|
||||||
|
@ -36,7 +36,12 @@ class IcuDatFileLoader extends IcuResFileLoader
|
|||||||
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
|
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
|
||||||
}
|
}
|
||||||
|
|
||||||
$rb = new \ResourceBundle($locale, $resource);
|
try {
|
||||||
|
$rb = new \ResourceBundle($locale, $resource);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// HHVM compatibility: constructor throws on invalid resource
|
||||||
|
$rb = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (!$rb) {
|
if (!$rb) {
|
||||||
throw new InvalidResourceException(sprintf('Cannot load resource "%s"', $resource));
|
throw new InvalidResourceException(sprintf('Cannot load resource "%s"', $resource));
|
||||||
|
@ -36,7 +36,12 @@ class IcuResFileLoader implements LoaderInterface
|
|||||||
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
|
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
|
||||||
}
|
}
|
||||||
|
|
||||||
$rb = new \ResourceBundle($locale, $resource);
|
try {
|
||||||
|
$rb = new \ResourceBundle($locale, $resource);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// HHVM compatibility: constructor throws on invalid resource
|
||||||
|
$rb = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (!$rb) {
|
if (!$rb) {
|
||||||
throw new InvalidResourceException(sprintf('Cannot load resource "%s"', $resource));
|
throw new InvalidResourceException(sprintf('Cannot load resource "%s"', $resource));
|
||||||
|
Reference in New Issue
Block a user