8000 [Intl] Integrated ICU data into Intl component #1 by webmozart · Pull Request #11920 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[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

Merged
merged 1 commit into from
Sep 30, 2014
Merged
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
[Intl] Integrated ICU data into Intl component
  • Loading branch information
webmozart committed Sep 26, 2014
commit be819c162f7507cfe9585da96c26fd440d186aef
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ install:
- sh -c 'if [ "$components" = "no" ]; then sh -c "COMPOSER_ROOT_VERSION=dev-master composer --prefer-source --dev install"; fi;'

script:
- sh -c 'if [ "$components" = "no" ]; then sh -c "ls -d src/Symfony/*/* | parallel --gnu --keep-order '\''echo \"Running {} tests\"; phpunit --exclude-group tty,benchmark {};'\''"; fi;'
- sh -c 'if [ "$components" = "no" ]; then sh -c "ls -d src/Symfony/*/* | parallel --gnu --keep-order '\''echo \"Running {} tests\"; phpunit --exclude-group tty,benchmark,intl-data {};'\''"; fi;'
- sh -c 'if [ "$components" = "no" ]; then sh -c "echo "\""Running tests requiring tty"\""; phpunit --group tty"; fi;'
- sh -c 'if [ "$components" = "yes" ]; then sh -c "find src/Symfony -mindepth 3 -type f -name '\''phpunit.xml.dist'\'' | sed '\''s#\(.*\)/.*#\1#'\'' | parallel --gnu --keep-order '\''echo \"Running {} tests\"; cd {}; COMPOSER_ROOT_VERSION=dev-master composer --prefer-source --dev install; phpunit --exclude-group tty,benchmark;'\''"; fi;'
- sh -c 'if [ "$components" = "yes" ]; then sh -c "find src/Symfony -mindepth 3 -type f -name '\''phpunit.xml.dist'\'' | sed '\''s#\(.*\)/.*#\1#'\'' | parallel --gnu --keep-order '\''echo \"Running {} tests\"; cd {}; COMPOSER_ROOT_VERSION=dev-master composer --prefer-source --dev install; phpunit --exclude-group tty,benchmark,intl-data;'\''"; fi;'
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
],
"require": {
"php": ">=5.3.3",
"symfony/icu": "~1.0",
"doctrine/common": "~2.2",
"twig/twig": "~1.12",
"psr/log": "~1.0"
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<groups>
<exclude>
<group>benchmark</group>
<group>intl-data</group>
Copy link
Member

Choose a reason for hiding this comment

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

why excluding them ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

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

OK, thanks for the explanation

</exclude>
</groups>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testCountriesAreSelectable()

$this->assertContains(new ChoiceView('en', 'en', 'English'), $choices, '', false, false);
$this->assertContains(new ChoiceView('en_GB', 'en_GB', 'British English'), $choices, '', false, false);
$this->assertContains(new ChoiceView('en_US', 'en_US', 'U.S. English'), $choices, '', false, false);
$this->assertContains(new ChoiceView('en_US', 'en_US', 'American English'), $choices, '', false, false);
$this->assertContains(new ChoiceView('fr', 'fr', 'French'), $choices, '', false, false);
$this->assertContains(new ChoiceView('my', 'my', 'Burmese'), $choices, '', false, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\Intl\ResourceBundle\Compiler;
namespace Symfony\Component\Intl\Data\Bundle\Compiler;

/**
* Compiles a resource bundle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\Intl\ResourceBundle\Compiler;
namespace Symfony\Component\Intl\Data\Bundle\Compiler;

use Symfony\Component\Intl\Exception\RuntimeException;

Expand All @@ -20,7 +20,7 @@
*
* @internal
*/
class BundleCompiler implements BundleCompilerInterface
class GenrbCompiler implements BundleCompilerInterface
{
/**
* @var string The path to the "genrb" executable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\Intl\ResourceBundle\Reader;
namespace Symfony\Component\Intl\Data\Bundle\Reader;

use Symfony\Component\Intl\ResourceBundle\Util\RingBuffer;
use Symfony\Component\Intl\Data\Util\RingBuffer;

/**
* @author Bernhard Schussek <bschussek@gmail.com>
Expand Down Expand Up @@ -53,12 +53,4 @@ public function read($path, $locale)

return $this->buffer[$hash];
}

/**
* {@inheritdoc}
*/
public function getLocales($path)
{
return $this->reader->getLocales($path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\Intl\ResourceBundle\Reader;
namespace Symfony\Component\Intl\Data\Bundle\Reader;

use Symfony\Component\Intl\Exception\MissingResourceException;
use Symfony\Component\Intl\Exception\OutOfBoundsException;
use Symfony\Component\Intl\Exception\ResourceBundleNotFoundException;
use Symfony\Component\Intl\Locale;
use Symfony\Component\Intl\ResourceBundle\Util\RecursiveArrayAccess;
use Symfony\Component\Intl\Data\Util\RecursiveArrayAccess;

/**
* Default implementation of {@link StructuredBundleReaderInterface}.
* Default implementation of {@link BundleEntryReaderInterface}.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @see StructuredResourceBundleBundleReaderInterface
* @see BundleEntryReaderInterface
*
* @internal
*/
class StructuredBundleReader implements StructuredBundleReaderInterface
class BundleEntryReader implements BundleEntryReaderInterface
{
/**
* @var BundleReaderInterface
Expand Down Expand Up @@ -138,7 +138,7 @@ public function readEntry($path, $locale, array $indices, $fallback = true)
}

// Remember which locales we tried
$testedLocales[] = $currentLocale.'.res';
$testedLocales[] = $currentLocale;

// Check whether fallback is allowed
if (!$fallback) {
Expand All @@ -162,10 +162,10 @@ public function readEntry($path, $locale, array $indices, $fallback = true)
// Entry is still NULL, read error occurred. Throw an exception
// containing the detailed path and locale
$errorMessage = sprintf(
'Couldn\'t read the indices [%s] from "%s/%s.res".',
'Couldn\'t read the indices [%s] for the locale "%s" in "%s".',
implode('][', $indices),
$path,
$locale
$locale,
$path
);

// Append fallback locales, if any
Expand All @@ -174,19 +174,11 @@ public function readEntry($path, $locale, array $indices, $fallback = true)
array_shift($testedLocales);

$errorMessage .= sprintf(
' The indices also couldn\'t be found in the fallback locale(s) "%s".',
' The indices also couldn\'t be found for the fallback locale(s) "%s".',
implode('", "', $testedLocales)
);
}

throw new MissingResourceException($errorMessage, 0, $exception);
}

/**
* {@inheritdoc}
*/
public function getLocales($path)
{
return $this->reader->getLocales($path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

use Symfony\Component\Intl\Exception\MissingResourceException;

Expand All @@ -20,7 +20,7 @@
*
* @internal
*/
interface StructuredBundleReaderInterface extends BundleReaderInterface
interface BundleEntryReaderInterface extends BundleReaderInterface
{
/**
* Reads an entry from a resource bundle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* Reads resource bundle files.
Expand All @@ -30,13 +30,4 @@ interface BundleReaderInterface
* complex data, a scalar value otherwise.
*/
public function read($path, $locale);

/**
* Reads the available locales of a resource bundle.
*
* @param string $path The path to the resource bundle.
*
* @return string[] A list of supported locale codes.
*/
public function getLocales($path);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\Intl\ResourceBundle\Reader;
namespace Symfony\Component\Intl\Data\Bundle\Reader;

use Symfony\Component\Intl\Exception\ResourceBundleNotFoundException;
use Symfony\Component\Intl\ResourceBundle\Util\ArrayAccessibleResourceBundle;
use Symfony\Component\Intl\Data\Util\ArrayAccessibleResourceBundle;

/**
* Reads binary .res resource bundles.
Expand All @@ -21,7 +21,7 @@
*
* @internal
*/
class BinaryBundleReader implements BundleReaderInterface
class IntlBundleReader implements BundleReaderInterface
{
/**
* {@inheritdoc}
Expand Down Expand Up @@ -52,18 +52,4 @@ public function read($path, $locale)
// which are OK for us.
return new ArrayAccessibleResourceBundle($bundle);
}

/**
* {@inheritdoc}
*/
public function getLocales($path)
{
$locales = glob($path.'/*.res');

// Remove file extension and sort
array_walk($locales, function (&$locale) { $locale = basename($locale, '.res'); });
sort($locales);

return $locales;
}
}
89 changes: 89 additions & 0 deletions src/Symfony/Component/Intl/Data/Bundle/Reader/JsonBundleReader.php
F41A
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',
);

$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
Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The 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;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\Intl\ResourceBundle\Writer;
namespace Symfony\Component\Intl\Data\Bundle\Writer;

/**
* Writes resource bundle files.
Expand Down
Loading
0