8000 [Intl] Integrated ICU data into Intl component · symfony/symfony@7cc9011 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7cc9011

Browse files
committed
[Intl] Integrated ICU data into Intl component
1 parent f776e0c commit 7cc9011

File tree

2,363 files changed

+7604
-2192
lines changed
  • Some content is hidden

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

    2,363 files changed

    +7604
    -2192
    lines changed

    composer.json

    Lines 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

    Lines changed: 6 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -17,6 +17,12 @@
    1717
    <directory>./src/Symfony/Bridge/*/Tests/</directory>
    1818
    <directory>./src/Symfony/Component/*/Tests/</directory>
    1919
    <directory>./src/Symfony/Bundle/*/Tests/</directory>
    20+
    <!--
    21+
    A LOT (~20,000) of tests that only need to be run after updating
    22+
    the resource data or changing the classes under the
    23+
    Symfony\Component\Intl\Data namespace.
    24+
    -->
    25+
    <exclude>./src/Symfony/Component/Intl/Tests/Data/Provider/</exclude>
    2026
    </testsuite>
    2127
    </testsuites>
    2228

    Lines 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

    Lines 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

    Lines 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

    Lines 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

    Lines changed: 5 additions & 13 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
    @@ -181,12 +181,4 @@ public function readEntry($path, $locale, array $indices, $fallback = true)
    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

    Lines 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

    Lines 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
    }

    src/Symfony/Component/Intl/ResourceBundle/Reader/BinaryBundleReader.php renamed to src/Symfony/Component/Intl/Data/Bundle/Reader/IntlBundleReader.php

    Lines changed: 3 additions & 17 deletions
    Original file line numberDiff line numberDiff line change
    @@ -9,10 +9,10 @@
    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\ResourceBundleNotFoundException;
    15-
    use Symfony\Component\Intl\ResourceBundle\Util\ArrayAccessibleResourceBundle;
    15+
    use Symfony\Component\Intl\Data\Util\ArrayAccessibleResourceBundle;
    1616

    1717
    /**
    1818
    * Reads binary .res resource bundles.
    @@ -21,7 +21,7 @@
    2121
    *
    2222
    * @internal
    2323
    */
    24-
    class BinaryBundleReader implements BundleReaderInterface
    24+
    class IntlBundleReader implements BundleReaderInterface
    2525
    {
    2626
    /**
    2727
    * {@inheritdoc}
    @@ -52,18 +52,4 @@ public function read($path, $locale)
    5252
    // which are OK for us.
    5353
    return new ArrayAccessibleResourceBundle($bundle);
    5454
    }
    55-
    56-
    /**
    57-
    * {@inheritdoc}
    58-
    */
    59-
    public function getLocales($path)
    60-
    {
    61-
    $locales = glob($path.'/*.res');
    62-
    63-
    // Remove file extension and sort
    64-
    array_walk($locales, function (&$locale) { $locale = basename($locale, '.res'); });
    65-
    sort($locales);
    66-
    67-
    return $locales;
    68-
    }
    6955
    }

    0 commit comments

    Comments
     (0)
    0