Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 950e273

Browse filesBrowse files
committed
[Intl] Integrated ICU data into Intl component
1 parent d853c0d commit 950e273
Copy full SHA for 950e273

File tree

2,710 files changed

+448777
-2222
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner

2,710 files changed

+448777
-2222
lines changed

‎.travis.yml

Copy file name to clipboardExpand all lines: .travis.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ install:
2828
- COMPOSER_ROOT_VERSION=dev-master composer --prefer-source install
2929

3030
script:
31-
- ls -d src/Symfony/*/* | parallel --gnu --keep-order 'echo "Running {} tests"; phpunit --exclude-group tty,benchmark {};'
31+
- ls -d src/Symfony/*/* | parallel --gnu --keep-order 'echo "Running {} tests"; phpunit --exclude-group tty,benchmark,intl-data {};'
3232
- echo "Running tests requiring tty"; phpunit --group tty

‎composer.json

Copy file name to clipboardExpand all lines: composer.json
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
],
1818
"require": {
1919
"php": ">=5.3.3",
20-
"symfony/icu": "~1.0",
2120
"doctrine/common": "~2.2",
2221
"twig/twig": "~1.12",
2322
"psr/log": "~1.0"

‎phpunit.xml.dist

Copy file name to clipboardExpand all lines: phpunit.xml.dist
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<groups>
2424
<exclude>
2525
<group>benchmark</group>
26+
<group>intl-data</group>
2627
</exclude>
2728
</groups>
2829

‎src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testCountriesAreSelectable()
3131

3232
$this->assertContains(new ChoiceView('en', 'en', 'English'), $choices, '', false, false);
3333
$this->assertContains(new ChoiceView('en_GB', 'en_GB', 'British English'), $choices, '', false, false);
34-
$this->assertContains(new ChoiceView('en_US', 'en_US', 'U.S. English'), $choices, '', false, false);
34+
$this->assertContains(new ChoiceView('en_US', 'en_US', 'American English'), $choices, '', false, false);
3535
$this->assertContains(new ChoiceView('fr', 'fr', 'French'), $choices, '', false, false);
3636
$this->assertContains(new ChoiceView('my', 'my', 'Burmese'), $choices, '', false, false);
3737
}
+151Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Intl\Composer;
13+
14+
use Symfony\Component\Filesystem\Filesystem;
15+
use Symfony\Component\Intl\Exception\RuntimeException;
16+
use Symfony\Component\Intl\Intl;
17+
18+
/**
19+
* Decompresses the resource data.
20+
*
21+
* The method {@link decompressData()} should be called after installing the
22+
* component.
23+
*
24+
* @author Bernhard Schussek <bschussek@gmail.com>
25+
*/
26+
class ScriptHandler
27+
{
28+
/**
29+
* Decompresses the ICU data.
30+
*/
31+
public static function decompressData()
32+
{
33+
self::decompressDataForFormat(Intl::JSON);
34+
self::decompressDataForFormat(Intl::RB_V2);
35+
}
36+
37+
/**
38+
* Decompresses the ICU data in a given format.
39+
*
40+
* @param string $format
41+
*
42+
* @throws RuntimeException
43+
*/
44+
private static function decompressDataForFormat($format)
45+
{
46+
$filesystem = new Filesystem();
47+
$archive = Intl::getDataDirectory().'/'.$format.'.zip';
48+
$targetDir = Intl::getResourceDirectory($format);
49+
50+
if (!file_exists($archive)) {
51+
throw new RuntimeException(sprintf(
52+
'The zip file "%s" could not be found.',
53+
$archive
54+
));
55+
}
56+
57+
if (file_exists($targetDir)) {
58+
$filesystem->remove($targetDir);
59+
$filesystem->mkdir($targetDir);
60+
}
61+
62+
if (class_exists('ZipArchive')) {
63+
$zip = new \ZipArchive();
64+
65+
if (true !== ($status = $zip->open($archive))) {
66+
throw new RuntimeException(self::getReadableZipArchiveStatus($status));
67+
}
68+
69+
if (!$zip->extractTo($targetDir)) {
70+
throw new RuntimeException(sprintf(
71+
'The extraction of the file "%s" failed.',
72+
$archive
73+
));
74+
}
75+
76+
return;
77+
}
78+
79+
// Test whether "unzip" exists on the shell
80+
exec('unzip -h', $output, $status);
81+
82+
if (0 === $status) {
83+
$command = sprintf('unzip -d %s %s', escapeshellarg($targetDir), escapeshellarg($archive));
84+
85+
exec($command, $output, $status);
86+
87+
if (0 !== $status) {
88+
throw new RuntimeException(sprintf(
89+
'The extraction of the file "%s" failed. Output:%s',
90+
$archive,
91+
"\n".implode("\n", $output)
92+
));
93+
}
94+
95+
return;
96+
}
97+
98+
throw new RuntimeException(sprintf(
99+
'Could not find a mechanism to decompress the archive "%s".',
100+
$archive
101+
));
102+
}
103+
104+
/**
105+
* Returns a readable version of the given {@link \ZipArchive} status.
106+
*
107+
* @param int $status The status code
108+
*
109+
* @return string The status message
110+
*
111+
* @see http://de2.php.net/manual/en/class.ziparchive.php#108601
112+
*/
113+
private static function getReadableZipArchiveStatus($status)
114+
{
115+
switch ((int) $status) {
116+
case \ZipArchive::ER_OK : return 'No error';
117+
case \ZipArchive::ER_MULTIDISK : return 'Multi-disk zip archives not supported';
118+
case \ZipArchive::ER_RENAME : return 'Renaming temporary file failed';
119+
case \ZipArchive::ER_CLOSE : return 'Closing zip archive failed';
120+
case \ZipArchive::ER_SEEK : return 'Seek error';
121+
case \ZipArchive::ER_READ : return 'Read error';
122+
case \ZipArchive::ER_WRITE : return 'Write error';
123+
case \ZipArchive::ER_CRC : return 'CRC error';
124+
case \ZipArchive::ER_ZIPCLOSED : return 'Containing zip archive was closed';
125+
case \ZipArchive::ER_NOENT : return 'No such file';
126+
case \ZipArchive::ER_EXISTS : return 'File already exists';
127+
case \ZipArchive::ER_OPEN : return 'Can\'t open file';
128+
case \ZipArchive::ER_TMPOPEN : return 'Failure to create temporary file';
129+
case \ZipArchive::ER_ZLIB : return 'Zlib error';
130+
case \ZipArchive::ER_MEMORY : return 'Malloc failure';
131+
case \ZipArchive::ER_CHANGED : return 'Entry has been changed';
132+
case \ZipArchive::ER_COMPNOTSUPP : return 'Compression method not supported';
133+
case \ZipArchive::ER_EOF : return 'Premature EOF';
134+
case \ZipArchive::ER_INVAL : return 'Invalid argument';
135+
case \ZipArchive::ER_NOZIP : return 'Not a zip archive';
136+
case \ZipArchive::ER_INTERNAL : return 'Internal error';
137+
case \ZipArchive::ER_INCONS : return 'Zip archive inconsistent';
138+
case \ZipArchive::ER_REMOVE : return 'Can\'t remove file';
139+
case \ZipArchive::ER_DELETED : return 'Entry has been deleted';
140+
141+
default: return sprintf('Unknown status %s', $status );
142+
}
143+
}
144+
145+
/**
146+
* Should not be instantiated.
147+
*/
148+
private function __construct()
149+
{
150+
}
151+
}

‎src/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompilerInterface.php renamed to ‎src/Symfony/Component/Intl/Data/Bundle/Compiler/BundleCompilerInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Intl/Data/Bundle/Compiler/BundleCompilerInterface.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Intl\ResourceBundle\Compiler;
12+
namespace Symfony\Component\Intl\Data\Bundle\Compiler;
1313

1414
/**
1515
* Compiles a resource bundle.

‎src/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompiler.php renamed to ‎src/Symfony/Component/Intl/Data/Bundle/Compiler/GenrbCompiler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Intl/Data/Bundle/Compiler/GenrbCompiler.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Intl\ResourceBundle\Compiler;
12+
namespace Symfony\Component\Intl\Data\Bundle\Compiler;
1313

1414
use Symfony\Component\Intl\Exception\RuntimeException;
1515

@@ -20,7 +20,7 @@
2020
*
2121
* @internal
2222
*/
23-
class BundleCompiler implements BundleCompilerInterface
23+
class GenrbCompiler implements BundleCompilerInterface
2424
{
2525
/**
2626
* @var string The path to the "genrb" executable.
@@ -38,7 +38,7 @@ class BundleCompiler implements BundleCompilerInterface
3838
*/
3939
public function __construct($genrb = 'genrb', $envVars = '')
4040
{
41-
exec('which ' . $genrb, $output, $status);
41+
exec('which '.$genrb, $output, $status);
4242

4343
if (0 !== $status) {
4444
throw new RuntimeException(sprintf(
@@ -47,7 +47,7 @@ public function __construct($genrb = 'genrb', $envVars = '')
4747
));
4848
}
4949

50-
$this->genrb = ($envVars ? $envVars . ' ' : '') . $genrb;
50+
$this->genrb = ($envVars ? $envVars.' ' : '').$genrb;
5151
}
5252

5353
/**

‎src/Symfony/Component/Intl/ResourceBundle/Reader/BufferedBundleReader.php renamed to ‎src/Symfony/Component/Intl/Data/Bundle/Reader/BufferedBundleReader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Intl/Data/Bundle/Reader/BufferedBundleReader.php
+3-11Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Intl\ResourceBundle\Reader;
12+
namespace Symfony\Component\Intl\Data\Bundle\Reader;
1313

14-
use Symfony\Component\Intl\ResourceBundle\Util\RingBuffer;
14+
use Symfony\Component\Intl\Data\Util\RingBuffer;
1515

1616
/**
1717
* @author Bernhard Schussek <bschussek@gmail.com>
@@ -45,20 +45,12 @@ public function __construct(BundleReaderInterface $reader, $bufferSize)
4545
*/
4646
public function read($path, $locale)
4747
{
48-
$hash = $path . '//' . $locale;
48+
$hash = $path.'//'.$locale;
4949

5050
if (!isset($this->buffer[$hash])) {
5151
$this->buffer[$hash] = $this->reader->read($path, $locale);
5252
}
5353

5454
return $this->buffer[$hash];
5555
}
56-
57-
/**
58-
* {@inheritdoc}
59-
*/
60-
public function getLocales($path)
61-
{
62-
return $this->reader->getLocales($path);
63-
}
6456
}

‎src/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReader.php renamed to ‎src/Symfony/Component/Intl/Data/Bundle/Reader/BundleEntryReader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Intl/Data/Bundle/Reader/BundleEntryReader.php
+10-18Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Intl\ResourceBundle\Reader;
12+
namespace Symfony\Component\Intl\Data\Bundle\Reader;
1313

1414
use Symfony\Component\Intl\Exception\MissingResourceException;
1515
use Symfony\Component\Intl\Exception\OutOfBoundsException;
1616
use Symfony\Component\Intl\Exception\ResourceBundleNotFoundException;
1717
use Symfony\Component\Intl\Locale;
18-
use Symfony\Component\Intl\ResourceBundle\Util\RecursiveArrayAccess;
18+
use Symfony\Component\Intl\Data\Util\RecursiveArrayAccess;
1919

2020
/**
21-
* Default implementation of {@link StructuredBundleReaderInterface}.
21+
* Default implementation of {@link BundleEntryReaderInterface}.
2222
*
2323
* @author Bernhard Schussek <bschussek@gmail.com>
2424
*
25-
* @see StructuredResourceBundleBundleReaderInterface
25+
* @see BundleEntryReaderInterface
2626
*
2727
* @internal
2828
*/
29-
class StructuredBundleReader implements StructuredBundleReaderInterface
29+
class BundleEntryReader implements BundleEntryReaderInterface
3030
{
3131
/**
3232
* @var BundleReaderInterface
@@ -138,7 +138,7 @@ public function readEntry($path, $locale, array $indices, $fallback = true)
138138
}
139139

140140
// Remember which locales we tried
141-
$testedLocales[] = $currentLocale.'.res';
141+
$testedLocales[] = $currentLocale;
142142

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

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

176176
$errorMessage .= sprintf(
177-
' The indices also couldn\'t be found in the fallback locale(s) "%s".',
177+
' The indices also couldn\'t be found for the fallback locale(s) "%s".',
178178
implode('", "', $testedLocales)
179179
);
180180
}
181181

182182
throw new MissingResourceException($errorMessage, 0, $exception);
183183
}
184-
185-
/**
186-
* {@inheritdoc}
187-
*/
188-
public function getLocales($path)
189-
{
190-
return $this->reader->getLocales($path);
191-
}
192184
}

‎src/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReaderInterface.php renamed to ‎src/Symfony/Component/Intl/Data/Bundle/Reader/BundleEntryReaderInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Intl/Data/Bundle/Reader/BundleEntryReaderInterface.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Intl\ResourceBundle\Reader;
12+
namespace Symfony\Component\Intl\Data\Bundle\Reader;
1313

1414
use Symfony\Component\Intl\Exception\MissingResourceException;
1515

@@ -20,7 +20,7 @@
2020
*
2121
* @internal
2222
*/
23-
interface StructuredBundleReaderInterface extends BundleReaderInterface
23+
interface BundleEntryReaderInterface extends BundleReaderInterface
2424
{
2525
/**
2626
* Reads an entry from a resource bundle.

‎src/Symfony/Component/Intl/ResourceBundle/Reader/BundleReaderInterface.php renamed to ‎src/Symfony/Component/Intl/Data/Bundle/Reader/BundleReaderInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Intl/Data/Bundle/Reader/BundleReaderInterface.php
+1-10Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Intl\ResourceBundle\Reader;
12+
namespace Symfony\Component\Intl\Data\Bundle\Reader;
1313

1414
/**
1515
* Reads resource bundle files.
@@ -30,13 +30,4 @@ interface BundleReaderInterface
3030
* complex data, a scalar value otherwise.
3131
*/
3232
public function read($path, $locale);
33-
34-
/**
35-
* Reads the available locales of a resource bundle.
36-
*
37-
* @param string $path The path to the resource bundle.
38-
*
39-
* @return string[] A list of supported locale codes.
40-
*/
41-
public function getLocales($path);
4233
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.