Вход Регистрация
Файл: symfony-2.7/src/Symfony/Component/Intl/Resources/bin/update-data.php
Строк: 463
<?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.
 */

use SymfonyComponentIntlDataBundleReaderJsonBundleReader;
use 
SymfonyComponentIntlDataBundleWriterJsonBundleWriter;
use 
SymfonyComponentIntlDataGeneratorCurrencyDataGenerator;
use 
SymfonyComponentIntlDataGeneratorGeneratorConfig;
use 
SymfonyComponentIntlDataGeneratorLanguageDataGenerator;
use 
SymfonyComponentIntlDataGeneratorLocaleDataGenerator;
use 
SymfonyComponentIntlDataGeneratorRegionDataGenerator;
use 
SymfonyComponentIntlDataGeneratorScriptDataGenerator;
use 
SymfonyComponentIntlDataProviderLanguageDataProvider;
use 
SymfonyComponentIntlDataProviderRegionDataProvider;
use 
SymfonyComponentIntlDataProviderScriptDataProvider;
use 
SymfonyComponentIntlIntl;
use 
SymfonyComponentIntlDataBundleCompilerGenrbCompiler;
use 
SymfonyComponentIntlDataBundleReaderBundleEntryReader;
use 
SymfonyComponentIntlLocale;
use 
SymfonyComponentIntlUtilIcuVersion;
use 
SymfonyComponentIntlUtilSvnRepository;
use 
SymfonyComponentFilesystemFilesystem;

require_once 
__DIR__.'/common.php';
require_once 
__DIR__.'/autoload.php';

$argc $_SERVER['argc'];
$argv $_SERVER['argv'];

if (
$argc || === $argc && '-h' === $argv[1]) {
    
bailout(<<<MESSAGE
Usage: php update-icu-component.php <path/to/icu/source> <path/to/icu/build>

Updates the ICU data for Symfony to the latest version of ICU.

If you downloaded the SVN repository before, you can pass the path to the
repository source in the first optional argument.

If you also built the repository before, you can pass the directory where that
build is stored in the second parameter. The build directory needs to contain
the subdirectories bin/ and lib/.

For running this script, the intl extension must be loaded and all vendors
must have been installed through composer:

composer install --dev

MESSAGE
    );
}

echo 
LINE;
echo 
centered("ICU Resource Bundle Compilation")."n";
echo 
LINE;

if (!
Intl::isExtensionLoaded()) {
    
bailout('The intl extension for PHP is not installed.');
}

$filesystem = new Filesystem();
$urls parse_ini_file(__DIR__.'/icu.ini');

echo 
"icu.ini parsed. Available versions:n";

$maxVersion 0;

foreach (
$urls as $urlVersion => $url) {
    
$maxVersion IcuVersion::compare($maxVersion$urlVersion'<')
        ? 
$urlVersion
        
$maxVersion;

    echo 
"  $urlVersionn";
}

$shortIcuVersion strip_minor_versions($maxVersion);

if (
$argc >= 2) {
    
$sourceDir $argv[1];
    
$svn = new SvnRepository($sourceDir);

    echo 
"Using existing SVN repository at {$sourceDir}.n";
} else {
    echo 
"Starting SVN checkout for version $shortIcuVersion. This may take a while...n";

    
$sourceDir sys_get_temp_dir().'/icu-data/'.$shortIcuVersion.'/source';
    
$svn SvnRepository::download($urls[$shortIcuVersion], $sourceDir);

    echo 
"SVN checkout to {$sourceDir} complete.n";
}

if (
$argc >= 3) {
    
$buildDir $argv[2];
} else {
    
// Always build genrb so that we can determine the ICU version of the
    // download by running genrb --version
    
echo "Building genrb.n";

    
cd($sourceDir);

    echo 
"Running configure...n";

    
$buildDir sys_get_temp_dir().'/icu-data/'.$shortIcuVersion.'/build';

    
$filesystem->remove($buildDir);
    
$filesystem->mkdir($buildDir);

    
run('./configure --prefix='.$buildDir.' 2>&1');

    echo 
"Running make...n";

    
// If the directory "lib" does not exist in the download, create it or we
    // will run into problems when building libicuuc.so.
    
$filesystem->mkdir($sourceDir.'/lib');

    
// If the directory "bin" does not exist in the download, create it or we
    // will run into problems when building genrb.
    
$filesystem->mkdir($sourceDir.'/bin');

    echo 
"[1/6] libicudata.so...";

    
cd($sourceDir.'/stubdata');
    
run('make 2>&1 && make install 2>&1');

    echo 
" ok.n";

    echo 
"[2/6] libicuuc.so...";

    
cd($sourceDir.'/common');
    
run('make 2>&1 && make install 2>&1');

    echo 
" ok.n";

    echo 
"[3/6] libicui18n.so...";

    
cd($sourceDir.'/i18n');
    
run('make 2>&1 && make install 2>&1');

    echo 
" ok.n";

    echo 
"[4/6] libicutu.so...";

    
cd($sourceDir.'/tools/toolutil');
    
run('make 2>&1 && make install 2>&1');

    echo 
" ok.n";

    echo 
"[5/6] libicuio.so...";

    
cd($sourceDir.'/io');
    
run('make 2>&1 && make install 2>&1');

    echo 
" ok.n";

    echo 
"[6/6] genrb...";

    
cd($sourceDir.'/tools/genrb');
    
run('make 2>&1 && make install 2>&1');

    echo 
" ok.n";
}

$genrb $buildDir.'/bin/genrb';
$genrbEnv 'LD_LIBRARY_PATH='.$buildDir.'/lib ';

echo 
"Using $genrb.n";

$icuVersionInDownload get_icu_version_from_genrb($genrbEnv.' '.$genrb);

echo 
"Preparing resource bundle compilation (version $icuVersionInDownload)...n";

$compiler = new GenrbCompiler($genrb$genrbEnv);
$config = new GeneratorConfig($sourceDir.'/data'$icuVersionInDownload);

// Don't wrap "/data" in realpath(), in case the directory does not exist
$baseDir realpath(__DIR__.'/..').'/data';

//$txtDir = $baseDir.'/txt';
$jsonDir $baseDir;
//$phpDir = $baseDir.'/'.Intl::PHP;
//$resDir = $baseDir.'/'.Intl::RB_V2;

$targetDirs = array($jsonDir/*, $resDir*/);
$workingDirs = array($jsonDir/*, $txtDir, $resDir*/);

//$config->addBundleWriter($txtDir, new TextBundleWriter());
$config->addBundleWriter($jsonDir, new JsonBundleWriter());

echo 
"Starting resource bundle compilation. This may take a while...n";

$filesystem->remove($workingDirs);

foreach (
$workingDirs as $targetDir) {
    
$filesystem->mkdir(array(
        
$targetDir.'/'.Intl::CURRENCY_DIR,
        
$targetDir.'/'.Intl::LANGUAGE_DIR,
        
$targetDir.'/'.Intl::LOCALE_DIR,
        
$targetDir.'/'.Intl::REGION_DIR,
        
$targetDir.'/'.Intl::SCRIPT_DIR,
    ));
}

// We don't want to use fallback to English during generation
Locale::setDefaultFallback(null);

echo 
"Generating language data...n";

$generator = new LanguageDataGenerator($compilerIntl::LANGUAGE_DIR);
$generator->generateData($config);

//echo "Compiling...n";
//
//$compiler->compile($txtDir.'/'.Intl::LANGUAGE_DIR, $resDir.'/'.Intl::LANGUAGE_DIR);

echo "Generating script data...n";

$generator = new ScriptDataGenerator($compilerIntl::SCRIPT_DIR);
$generator->generateData($config);

//echo "Compiling...n";
//
//$compiler->compile($txtDir.'/'.Intl::SCRIPT_DIR, $resDir.'/'.Intl::SCRIPT_DIR);

echo "Generating region data...n";

$generator = new RegionDataGenerator($compilerIntl::REGION_DIR);
$generator->generateData($config);

//echo "Compiling...n";
//
//$compiler->compile($txtDir.'/'.Intl::REGION_DIR, $resDir.'/'.Intl::REGION_DIR);

echo "Generating currency data...n";

$generator = new CurrencyDataGenerator($compilerIntl::CURRENCY_DIR);
$generator->generateData($config);

//echo "Compiling...n";
//
//$compiler->compile($txtDir.'/'.Intl::CURRENCY_DIR, $resDir.'/'.Intl::CURRENCY_DIR);

echo "Generating locale data...n";

$reader = new BundleEntryReader(new JsonBundleReader());

$generator = new LocaleDataGenerator(
    
Intl::LOCALE_DIR,
    new 
LanguageDataProvider($jsonDir.'/'.Intl::LANGUAGE_DIR$reader),
    new 
ScriptDataProvider($jsonDir.'/'.Intl::SCRIPT_DIR$reader),
    new 
RegionDataProvider($jsonDir.'/'.Intl::REGION_DIR$reader)
);

$generator->generateData($config);

//echo "Compiling...n";
//
//$compiler->compile($txtDir.'/'.Intl::LOCALE_DIR, $resDir.'/'.Intl::LOCALE_DIR);
//
//$filesystem->remove($txtDir);

echo "Resource bundle compilation complete.n";

$svnInfo = <<<SVN_INFO
SVN information
===============

URL: 
{$svn->getUrl()}
Revision: 
{$svn->getLastCommit()->getRevision()}
Author: 
{$svn->getLastCommit()->getAuthor()}
Date: 
{$svn->getLastCommit()->getDate()}

SVN_INFO;

foreach (
$targetDirs as $targetDir) {
    
$svnInfoFile $targetDir.'/svn-info.txt';

    
file_put_contents($svnInfoFile$svnInfo);

    echo 
"Wrote $svnInfoFile.n";

    
$versionFile $targetDir.'/version.txt';

    
file_put_contents($versionFile"$icuVersionInDownloadn");

    echo 
"Wrote $versionFile.n";
}

echo 
"Done.n";
Онлайн: 0
Реклама