Skip to content

[2.2] [Locale] add StubResourceBundle #4081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions autoload.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ if (!function_exists('intl_get_error_code')) {
$loader->add('Collator', __DIR__.'/src/Symfony/Component/Locale/Resources/stubs');
$loader->add('Locale', __DIR__.'/src/Symfony/Component/Locale/Resources/stubs');
$loader->add('NumberFormatter', __DIR__.'/src/Symfony/Component/Locale/Resources/stubs');
$loader->add('ResourceBundle', __DIR__.'/src/Symfony/Component/Locale/Resources/stubs');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add this in the composer.json files too

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah sorry, the stub is not in composer because the functions cannot be autoloaded

}

AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/Locale/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static public function getDisplayCountries($locale)
throw new \RuntimeException(sprintf('The country resource bundle could not be loaded for locale "%s"', $locale));
}

$collator = new \Collator($locale);
$collator = new \Collator(!extension_loaded('intl') ? 'en' : $locale);
$countries = array();
$bundleCountries = $bundle->get('Countries') ?: array();

Expand Down Expand Up @@ -104,7 +104,7 @@ static public function getDisplayLanguages($locale)
throw new \RuntimeException(sprintf('The language resource bundle could not be loaded for locale "%s"', $locale));
}

$collator = new \Collator($locale);
$collator = new \Collator(!extension_loaded('intl') ? 'en' : $locale);
$languages = array();
$bundleLanguages = $bundle->get('Languages') ?: array();

Expand Down Expand Up @@ -155,7 +155,7 @@ static public function getDisplayLocales($locale)
throw new \RuntimeException(sprintf('The locale resource bundle could not be loaded for locale "%s"', $locale));
}

$collator = new \Collator($locale);
$collator = new \Collator(!extension_loaded('intl') ? 'en' : $locale);
$locales = array();
$bundleLocales = $bundle->get('Locales') ?: array();

Expand Down Expand Up @@ -243,7 +243,7 @@ static public function getIcuDataVersion()
* @param $locale The locale to find the fallback for
* @return string|null The fallback locale, or null if no parent exists
*/
static protected function getFallbackLocale($locale)
static public function getFallbackLocale($locale)
{
if ($locale === self::getDefault()) {
return null;
Expand Down
23 changes: 23 additions & 0 deletions src/Symfony/Component/Locale/Resources/stubs/ResourceBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* Stub implementation for the ResourceBundle class of the intl extension
*
* @author stealth35
* @see Symfony\Component\Locale\Stub\StubResourceBundle
*/

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This docblock is misplaced. It should be before the class declaration line.

use Symfony\Component\Locale\Stub\StubResourceBundle;

class ResourceBundle extends StubResourceBundle
{
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Locale/Stub/StubIntl.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ abstract class StubIntl
*/
const U_ILLEGAL_ARGUMENT_ERROR = 1;

/**
* The requested resource cannot be found
*
* @var integer
*/
const U_MISSING_RESOURCE_ERROR = 2;

/**
* Indicates that the parse() operation failed
*
Expand All @@ -47,6 +54,7 @@ abstract class StubIntl
private static $errorCodes = array(
self::U_ZERO_ERROR => 'U_ZERO_ERROR',
self::U_ILLEGAL_ARGUMENT_ERROR => 'U_ILLEGAL_ARGUMENT_ERROR',
self::U_MISSING_RESOURCE_ERROR => 'U_MISSING_RESOURCE_ERROR',
self::U_PARSE_ERROR => 'U_PARSE_ERROR',
);

Expand Down
Loading