-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Intl] Integrated ICU data into Intl component #1 #11920
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
<groups> | ||
<exclude> | ||
<group>benchmark</group> | ||
<group>intl-data</group> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why excluding them ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because these are insanely many tests (10000+) which take a lot of time to run (7 minutes on my machine). It's only necessary to run these tests when messing with the generator/provider classes and/or re-importing the data. Since nobody should be doing that except for a few core developers - who hopefully remember to run the tests ;) - it's better to keep the Travis build "fast", if you ask me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, thanks for the explanation |
||
</exclude> | ||
</groups> | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?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. | ||
*/ | ||
|
||
namespace Symfony\Component\Intl\Data\Bundle\Reader; | ||
|
||
use Symfony\Component\Intl\Exception\ResourceBundleNotFoundException; | ||
use Symfony\Component\Intl\Exception\RuntimeException; | ||
|
||
/** | ||
* Reads .json resource bundles. | ||
* | ||
* @author Bernhard Schussek <bschussek@gmail.com> | ||
* | ||
* @internal | ||
*/ | ||
class JsonBundleReader implements BundleReaderInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function read($path, $locale) | ||
{ | ||
$fileName = $path.'/'.$locale.'.json'; | ||
|
||
if (!file_exists($fileName)) { | ||
throw new ResourceBundleNotFoundException(sprintf( | ||
'The resource bundle "%s/%s.json" does not exist.', | ||
$path, | ||
$locale | ||
)); | ||
} | ||
|
||
if (!is_file($fileName)) { | ||
throw new RuntimeException(sprintf( | ||
'The resource bundle "%s/%s.json" is not a file.', | ||
$path, | ||
$locale | ||
)); | ||
} | ||
|
||
$data = json_decode(file_get_contents($fileName), true); | ||
|
||
if (null === $data) { | ||
throw new RuntimeException(sprintf( | ||
'The resource bundle "%s/%s.json" contains invalid JSON: %s', | ||
$path, | ||
$locale, | ||
self::getLastJsonError() | ||
)); | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* @return string The last error message created by {@link json_decode()} | ||
* | ||
* @link http://de2.php.net/manual/en/function.json-last-error-msg.php#113243 | ||
*/ | ||
private static function getLastJsonError() | ||
{ | ||
if (function_exists('json_last_error_msg')) { | ||
return json_last_error_msg(); | ||
} | ||
|
||
static $errors = array( | ||
JSON_ERROR_NONE => null, | ||
JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', | ||
JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch', | ||
JSON_ERROR_CTRL_CHAR => 'Unexpected control character found', | ||
JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON', | ||
JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded', | ||
F41A | ); | |
|
||
$error = json_last_error(); | ||
|
||
return array_key_exists($error, $errors) | ||
? $errors[$error] | ||
: sprintf('Unknown error (%s)', $error); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Intl\ResourceBundle\Reader; | ||
namespace Symfony\Component\Intl\Data\Bundle\Reader; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we deprecate this class? |
||
|
||
use Symfony\Component\Intl\Exception\ResourceBundleNotFoundException; | ||
use Symfony\Component\Intl\Exception\RuntimeException; | ||
|
@@ -48,18 +48,4 @@ public function read($path, $locale) | |
|
||
return include $fileName; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getLocales($path) | ||
{ | ||
$locales = glob($path.'/*.php'); | ||
|
||
// Remove file extension and sort | ||
array_walk($locales, function (&$locale) { $locale = basename($locale, '.php'); }); | ||
sort($locales); | ||
|
||
return $locales; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these changes are useless as the phpunit.xml.dist files are already excluding them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the impression that the build was not excluding the tests unless I added this here. I'll test again whether that's really true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The group benchmark is also excluded in phpunit.xml.dist. Do you know why it is explicitly excluded here?