4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 use Symfony\Component\Filesystem\Filesystem
;
13 use Symfony\Component\Icu\IcuData
;
14 use Symfony\Component\Intl\Intl
;
15 use Symfony\Component\Intl\ResourceBundle\Transformer\BundleTransformer
;
16 use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\CurrencyBundleTransformationRule
;
17 use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\LanguageBundleTransformationRule
;
18 use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\LocaleBundleTransformationRule
;
19 use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\RegionBundleTransformationRule
;
20 use Symfony\Component\Intl\ResourceBundle\Transformer\StubbingContext
;
22 require_once __DIR__
. '/common.php';
23 require_once __DIR__
. '/autoload.php';
25 if (1 !== $GLOBALS['argc']) {
27 Usage: php create-stubs.php
29 Creates resource bundle stubs from the resource bundles in the Icu component.
31 For running this script, the intl extension must be loaded and all vendors
32 must have been installed through composer:
34 composer install --dev
41 echo centered("ICU Resource Bundle Stub Creation") . "\n";
44 if (!Intl
::isExtensionLoaded()) {
45 bailout('The intl extension for PHP is not installed.');
48 if (!class_exists('\Symfony\Component\Icu\IcuData')) {
49 bailout('You must run "composer update --dev" before running this script.');
52 $stubBranch = '1.0.x';
54 if (IcuData
::isStubbed()) {
55 bailout("Please switch to a branch of the Icu component that contains .res files (anything but $stubBranch).");
58 $shortIcuVersionInPhp = strip_minor_versions(Intl
::getIcuVersion());
59 $shortIcuVersionInIntlComponent = strip_minor_versions(Intl
::getIcuStubVersion());
60 $shortIcuVersionInIcuComponent = strip_minor_versions(IcuData
::getVersion());
62 if ($shortIcuVersionInPhp !== $shortIcuVersionInIcuComponent) {
63 bailout("The ICU version of the component ($shortIcuVersionInIcuComponent) does not match the ICU version in the intl extension ($shortIcuVersionInPhp).");
66 if ($shortIcuVersionInIntlComponent !== $shortIcuVersionInIcuComponent) {
67 bailout("The ICU version of the component ($shortIcuVersionInIcuComponent) does not match the ICU version of the stub classes in the Intl component ($shortIcuVersionInIntlComponent).");
70 echo wordwrap("Make sure that you don't have any ICU development files " .
71 "installed. If the build fails, try to run:\n", LINE_WIDTH
);
73 echo "\n sudo apt-get remove libicu-dev\n\n";
75 $icuVersionInIcuComponent = IcuData
::getVersion();
77 echo "Compiling stubs for ICU version $icuVersionInIcuComponent.\n";
79 echo "Preparing stub creation...\n";
81 $targetDir = sys_get_temp_dir() . '/icu-stubs';
83 $context = new StubbingContext(
84 IcuData
::getResourceDirectory(),
87 $icuVersionInIcuComponent
90 $transformer = new BundleTransformer();
91 $transformer->addRule(new LanguageBundleTransformationRule());
92 $transformer->addRule(new RegionBundleTransformationRule());
93 $transformer->addRule(new CurrencyBundleTransformationRule());
94 $transformer->addRule(new LocaleBundleTransformationRule());
96 echo "Starting stub creation...\n";
98 $transformer->createStubs($context);
100 echo "Wrote stubs to $targetDir.\n";
102 $versionFile = $context->getStubDir() . '/version.txt';
104 file_put_contents($versionFile, "$icuVersionInIcuComponent\n");
106 echo "Wrote $versionFile.\n";
110 echo wordwrap("Please change the Icu component to branch $stubBranch now and run:\n", LINE_WIDTH
);
112 echo "\n php copy-stubs-to-component.php\n";