]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/intl/Symfony/Component/Intl/Resources/bin/create-stubs.php
d330d6b5fb5cf96033b7285aee5104b760312dec
[github/wallabag/wallabag.git] / vendor / symfony / intl / Symfony / Component / Intl / Resources / bin / create-stubs.php
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 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;
21
22 require_once __DIR__ . '/common.php';
23 require_once __DIR__ . '/autoload.php';
24
25 if (1 !== $GLOBALS['argc']) {
26 bailout(<<<MESSAGE
27 Usage: php create-stubs.php
28
29 Creates resource bundle stubs from the resource bundles in the Icu component.
30
31 For running this script, the intl extension must be loaded and all vendors
32 must have been installed through composer:
33
34 composer install --dev
35
36 MESSAGE
37 );
38 }
39
40 echo LINE;
41 echo centered("ICU Resource Bundle Stub Creation") . "\n";
42 echo LINE;
43
44 if (!Intl::isExtensionLoaded()) {
45 bailout('The intl extension for PHP is not installed.');
46 }
47
48 if (!class_exists('\Symfony\Component\Icu\IcuData')) {
49 bailout('You must run "composer update --dev" before running this script.');
50 }
51
52 $stubBranch = '1.0.x';
53
54 if (IcuData::isStubbed()) {
55 bailout("Please switch to a branch of the Icu component that contains .res files (anything but $stubBranch).");
56 }
57
58 $shortIcuVersionInPhp = strip_minor_versions(Intl::getIcuVersion());
59 $shortIcuVersionInIntlComponent = strip_minor_versions(Intl::getIcuStubVersion());
60 $shortIcuVersionInIcuComponent = strip_minor_versions(IcuData::getVersion());
61
62 if ($shortIcuVersionInPhp !== $shortIcuVersionInIcuComponent) {
63 bailout("The ICU version of the component ($shortIcuVersionInIcuComponent) does not match the ICU version in the intl extension ($shortIcuVersionInPhp).");
64 }
65
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).");
68 }
69
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);
72
73 echo "\n sudo apt-get remove libicu-dev\n\n";
74
75 $icuVersionInIcuComponent = IcuData::getVersion();
76
77 echo "Compiling stubs for ICU version $icuVersionInIcuComponent.\n";
78
79 echo "Preparing stub creation...\n";
80
81 $targetDir = sys_get_temp_dir() . '/icu-stubs';
82
83 $context = new StubbingContext(
84 IcuData::getResourceDirectory(),
85 $targetDir,
86 new Filesystem(),
87 $icuVersionInIcuComponent
88 );
89
90 $transformer = new BundleTransformer();
91 $transformer->addRule(new LanguageBundleTransformationRule());
92 $transformer->addRule(new RegionBundleTransformationRule());
93 $transformer->addRule(new CurrencyBundleTransformationRule());
94 $transformer->addRule(new LocaleBundleTransformationRule());
95
96 echo "Starting stub creation...\n";
97
98 $transformer->createStubs($context);
99
100 echo "Wrote stubs to $targetDir.\n";
101
102 $versionFile = $context->getStubDir() . '/version.txt';
103
104 file_put_contents($versionFile, "$icuVersionInIcuComponent\n");
105
106 echo "Wrote $versionFile.\n";
107
108 echo "Done.\n";
109
110 echo wordwrap("Please change the Icu component to branch $stubBranch now and run:\n", LINE_WIDTH);
111
112 echo "\n php copy-stubs-to-component.php\n";