twig implementation

This commit is contained in:
Nicolas Lœuillet
2013-08-03 19:26:54 +02:00
parent 2b840e0cfb
commit 4f5b44bd3b
1418 changed files with 108207 additions and 1586 deletions

View File

@ -0,0 +1,18 @@
<?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.
*/
$autoload = __DIR__ . '/../../vendor/autoload.php';
if (!file_exists($autoload)) {
bailout('You should run "composer install --dev" in the component before running this script.');
}
require_once realpath($autoload);

View File

@ -0,0 +1,69 @@
<?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.
*/
define('LINE_WIDTH', 75);
define('LINE', str_repeat('-', LINE_WIDTH) . "\n");
function bailout($message)
{
echo wordwrap($message, LINE_WIDTH) . " Aborting.\n";
exit(1);
}
function strip_minor_versions($version)
{
preg_match('/^(?P<version>[0-9]\.[0-9]|[0-9]{2,})/', $version, $matches);
return $matches['version'];
}
function centered($text)
{
$padding = (int) ((LINE_WIDTH - strlen($text))/2);
return str_repeat(' ', $padding) . $text;
}
function cd($dir)
{
if (false === chdir($dir)) {
bailout("Could not switch to directory $dir.");
}
}
function run($command)
{
exec($command, $output, $status);
if (0 !== $status) {
$output = implode("\n", $output);
echo "Error while running:\n " . getcwd() . '$ ' . $command . "\nOutput:\n" . LINE . "$output\n" . LINE;
bailout("\"$command\" failed.");
}
}
function get_icu_version_from_genrb($genrb)
{
exec($genrb . ' --version 2>&1', $output, $status);
if (0 !== $status) {
bailout($genrb . ' failed.');
}
if (!preg_match('/ICU version ([\d\.]+)/', implode('', $output), $matches)) {
return null;
}
return $matches[1];
}

View File

@ -0,0 +1,63 @@
<?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 Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Icu\IcuData;
use Symfony\Component\Intl\Intl;
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/autoload.php';
if (1 !== $GLOBALS['argc']) {
bailout(<<<MESSAGE
Usage: php copy-stubs-to-component.php
Copies stub files created with create-stubs.php to the Icu component.
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 Stub Update") . "\n";
echo LINE;
if (!class_exists('\Symfony\Component\Icu\IcuData')) {
bailout('You must run "composer update --dev" before running this script.');
}
$stubBranch = '1.0.x';
if (!IcuData::isStubbed()) {
bailout("Please switch to the Icu component branch $stubBranch.");
}
$filesystem = new Filesystem();
$sourceDir = sys_get_temp_dir() . '/icu-stubs';
$targetDir = IcuData::getResourceDirectory();
if (!$filesystem->exists($sourceDir)) {
bailout("The directory $sourceDir does not exist. Please run create-stubs.php first.");
}
$filesystem->remove($targetDir);
echo "Copying files from $sourceDir to $targetDir...\n";
$filesystem->mirror($sourceDir, $targetDir);
echo "Done.\n";

View File

@ -0,0 +1,112 @@
<?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 Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Icu\IcuData;
use Symfony\Component\Intl\Intl;
use Symfony\Component\Intl\ResourceBundle\Transformer\BundleTransformer;
use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\CurrencyBundleTransformationRule;
use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\LanguageBundleTransformationRule;
use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\LocaleBundleTransformationRule;
use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\RegionBundleTransformationRule;
use Symfony\Component\Intl\ResourceBundle\Transformer\StubbingContext;
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/autoload.php';
if (1 !== $GLOBALS['argc']) {
bailout(<<<MESSAGE
Usage: php create-stubs.php
Creates resource bundle stubs from the resource bundles in the Icu component.
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 Stub Creation") . "\n";
echo LINE;
if (!Intl::isExtensionLoaded()) {
bailout('The intl extension for PHP is not installed.');
}
if (!class_exists('\Symfony\Component\Icu\IcuData')) {
bailout('You must run "composer update --dev" before running this script.');
}
$stubBranch = '1.0.x';
if (IcuData::isStubbed()) {
bailout("Please switch to a branch of the Icu component that contains .res files (anything but $stubBranch).");
}
$shortIcuVersionInPhp = strip_minor_versions(Intl::getIcuVersion());
$shortIcuVersionInIntlComponent = strip_minor_versions(Intl::getIcuStubVersion());
$shortIcuVersionInIcuComponent = strip_minor_versions(IcuData::getVersion());
if ($shortIcuVersionInPhp !== $shortIcuVersionInIcuComponent) {
bailout("The ICU version of the component ($shortIcuVersionInIcuComponent) does not match the ICU version in the intl extension ($shortIcuVersionInPhp).");
}
if ($shortIcuVersionInIntlComponent !== $shortIcuVersionInIcuComponent) {
bailout("The ICU version of the component ($shortIcuVersionInIcuComponent) does not match the ICU version of the stub classes in the Intl component ($shortIcuVersionInIntlComponent).");
}
echo wordwrap("Make sure that you don't have any ICU development files " .
"installed. If the build fails, try to run:\n", LINE_WIDTH);
echo "\n sudo apt-get remove libicu-dev\n\n";
$icuVersionInIcuComponent = IcuData::getVersion();
echo "Compiling stubs for ICU version $icuVersionInIcuComponent.\n";
echo "Preparing stub creation...\n";
$targetDir = sys_get_temp_dir() . '/icu-stubs';
$context = new StubbingContext(
IcuData::getResourceDirectory(),
$targetDir,
new Filesystem(),
$icuVersionInIcuComponent
);
$transformer = new BundleTransformer();
$transformer->addRule(new LanguageBundleTransformationRule());
$transformer->addRule(new RegionBundleTransformationRule());
$transformer->addRule(new CurrencyBundleTransformationRule());
$transformer->addRule(new LocaleBundleTransformationRule());
echo "Starting stub creation...\n";
$transformer->createStubs($context);
echo "Wrote stubs to $targetDir.\n";
$versionFile = $context->getStubDir() . '/version.txt';
file_put_contents($versionFile, "$icuVersionInIcuComponent\n");
echo "Wrote $versionFile.\n";
echo "Done.\n";
echo wordwrap("Please change the Icu component to branch $stubBranch now and run:\n", LINE_WIDTH);
echo "\n php copy-stubs-to-component.php\n";

View File

@ -0,0 +1,18 @@
<?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 Symfony\Component\Intl\Intl;
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/autoload.php';
echo "ICU version: ";
echo Intl::getIcuVersion() . "\n";

View File

@ -0,0 +1,9 @@
; ICU data source URLs
; We use always the latest release of a major version.
4.0 = http://source.icu-project.org/repos/icu/icu/tags/release-4-0-1/source
4.2 = http://source.icu-project.org/repos/icu/icu/tags/release-4-2-1/source
4.4 = http://source.icu-project.org/repos/icu/icu/tags/release-4-4-2/source
4.6 = http://source.icu-project.org/repos/icu/icu/tags/release-4-6-1/source
4.8 = http://source.icu-project.org/repos/icu/icu/tags/release-4-8-1-1/source
49 = http://source.icu-project.org/repos/icu/icu/tags/release-49-1-2/source
50 = http://source.icu-project.org/repos/icu/icu/tags/release-50-1-2/source

View File

@ -0,0 +1,56 @@
<?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 Symfony\Component\Intl\Intl;
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/autoload.php';
if (1 !== $GLOBALS['argc']) {
bailout(<<<MESSAGE
Usage: php test-compat.php
Tests the compatibility of the current ICU version (bundled in ext/intl) with
different versions of symfony/icu.
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 Compatibility Test") . "\n";
echo LINE;
echo "Your ICU version: " . Intl::getIcuVersion() . "\n";
echo "Compatibility with symfony/icu:\n";
$branches = array(
'1.1.x',
'1.2.x',
);
cd(__DIR__ . '/../../vendor/symfony/icu/Symfony/Component/Icu');
foreach ($branches as $branch) {
run('git checkout ' . $branch . ' 2>&1');
exec('php ' . __DIR__ . '/util/test-compat-helper.php > /dev/null 2> /dev/null', $output, $status);
echo "$branch: " . (0 === $status ? "YES" : "NO") . "\n";
}
echo "Done.\n";

View File

@ -0,0 +1,212 @@
<?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 Symfony\Component\Icu\IcuData;
use Symfony\Component\Intl\Intl;
use Symfony\Component\Intl\ResourceBundle\Compiler\BundleCompiler;
use Symfony\Component\Intl\ResourceBundle\Transformer\BundleTransformer;
use Symfony\Component\Intl\ResourceBundle\Transformer\CompilationContext;
use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\CurrencyBundleTransformationRule;
use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\LanguageBundleTransformationRule;
use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\LocaleBundleTransformationRule;
use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\RegionBundleTransformationRule;
use Symfony\Component\Intl\Util\SvnRepository;
use Symfony\Component\Filesystem\Filesystem;
require_once __DIR__ . '/common.php';
require_once __DIR__ . '/autoload.php';
if ($GLOBALS['argc'] > 3 || 2 === $GLOBALS['argc'] && '-h' === $GLOBALS['argv'][1]) {
bailout(<<<MESSAGE
Usage: php update-icu-component.php <path/to/icu/source> <path/to/icu/build>
Updates the ICU data for Symfony2 to the latest version of the ICU version
included in the intl extension. For example, if your intl extension includes
ICU 4.8, the script will download the latest data available for ICU 4.8.
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.');
}
if (!class_exists('\Symfony\Component\Icu\IcuData')) {
bailout('You must run "composer update --dev" before running this script.');
}
$filesystem = new Filesystem();
$icuVersionInPhp = Intl::getIcuVersion();
echo "Found intl extension with ICU version $icuVersionInPhp.\n";
$shortIcuVersion = strip_minor_versions($icuVersionInPhp);
$urls = parse_ini_file(__DIR__ . '/icu.ini');
if (!isset($urls[$shortIcuVersion])) {
bailout('The version ' . $shortIcuVersion . ' is not available in the icu.ini file.');
}
echo "icu.ini parsed. Available versions:\n";
foreach ($urls as $urlVersion => $url) {
echo " $urlVersion\n";
}
if ($GLOBALS['argc'] >= 2) {
$sourceDir = $GLOBALS['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 ($GLOBALS['argc'] >= 3) {
$buildDir = $GLOBALS['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/5] libicudata.so...";
cd($sourceDir . '/stubdata');
run('make 2>&1 && make install 2>&1');
echo " ok.\n";
echo "[2/5] libicuuc.so...";
cd($sourceDir . '/common');
run('make 2>&1 && make install 2>&1');
echo " ok.\n";
echo "[3/5] libicui18n.so...";
cd($sourceDir . '/i18n');
run('make 2>&1 && make install 2>&1');
echo " ok.\n";
echo "[4/5] libicutu.so...";
cd($sourceDir . '/tools/toolutil');
run('make 2>&1 && make install 2>&1');
echo " ok.\n";
echo "[5/5] 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";
$context = new CompilationContext(
$sourceDir . '/data',
IcuData::getResourceDirectory(),
$filesystem,
new BundleCompiler($genrb, $genrbEnv),
$icuVersionInDownload
);
$transformer = new BundleTransformer();
$transformer->addRule(new LanguageBundleTransformationRule());
$transformer->addRule(new RegionBundleTransformationRule());
$transformer->addRule(new CurrencyBundleTransformationRule());
$transformer->addRule(new LocaleBundleTransformationRule());
echo "Starting resource bundle compilation. This may take a while...\n";
$transformer->compileBundles($context);
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;
$svnInfoFile = $context->getBinaryDir() . '/svn-info.txt';
file_put_contents($svnInfoFile, $svnInfo);
echo "Wrote $svnInfoFile.\n";
$versionFile = $context->getBinaryDir() . '/version.txt';
file_put_contents($versionFile, "$icuVersionInDownload\n");
echo "Wrote $versionFile.\n";
echo "Done.\n";

View File

@ -0,0 +1,23 @@
<?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 Symfony\Component\Icu\IcuData;
use Symfony\Component\Intl\ResourceBundle\Reader\BinaryBundleReader;
require_once __DIR__ . '/../common.php';
require_once __DIR__ . '/../autoload.php';
$reader = new BinaryBundleReader();
$reader->read(IcuData::getResourceDirectory() . '/curr', 'en');
$reader->read(IcuData::getResourceDirectory() . '/lang', 'en');
$reader->read(IcuData::getResourceDirectory() . '/locales', 'en');
$reader->read(IcuData::getResourceDirectory() . '/region', 'en');