Skip to content

Commit 38d2f8d

Browse files
Merge branch '4.1'
* 4.1: [HttpKernel] Fixed invalid REMOTE_ADDR in inline subrequest when configuring trusted proxy with subnet [FrameworkBundle] fixed guard event names for transitions [DI] Improve class named servics error message remove unnecessary instanceof in MongoDbSessionHandler [HttpFoundation] fixed using _method parameter with invalid type Renaming internal test class to help auto-completion [Intl] Replace svn with git in the icu data update script [Messenger] Fix error message on undefined message class for non-subscriber handler [HttpFoundation] Fix Cookie::isCleared
2 parents 2021b24 + ab0fba1 commit 38d2f8d

File tree

8 files changed

+217
-265
lines changed

8 files changed

+217
-265
lines changed

Resources/bin/icu.ini

Lines changed: 0 additions & 20 deletions
This file was deleted.

Resources/bin/update-data.php

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
use Symfony\Component\Intl\Data\Provider\ScriptDataProvider;
2626
use Symfony\Component\Intl\Intl;
2727
use Symfony\Component\Intl\Locale;
28-
use Symfony\Component\Intl\Util\IcuVersion;
29-
use Symfony\Component\Intl\Util\SvnRepository;
28+
use Symfony\Component\Intl\Util\GitRepository;
3029

3130
require_once __DIR__.'/common.php';
3231
require_once __DIR__.'/autoload.php';
@@ -40,7 +39,7 @@
4039
4140
Updates the ICU data for Symfony to the latest version of ICU.
4241
43-
If you downloaded the SVN repository before, you can pass the path to the
42+
If you downloaded the git repository before, you can pass the path to the
4443
repository source in the first optional argument.
4544
4645
If you also built the repository before, you can pass the directory where that
@@ -64,36 +63,30 @@
6463
bailout('The intl extension for PHP is not installed.');
6564
}
6665

67-
$filesystem = new Filesystem();
68-
$urls = parse_ini_file(__DIR__.'/icu.ini');
69-
70-
echo "icu.ini parsed. Available versions:\n";
66+
if ($argc >= 2) {
67+
$repoDir = $argv[1];
68+
$git = new GitRepository($repoDir);
7169

72-
$maxVersion = 0;
70+
echo "Using the existing git repository at {$repoDir}.\n";
71+
} else {
72+
echo "Starting git clone. This may take a while...\n";
7373

74-
foreach ($urls as $urlVersion => $url) {
75-
$maxVersion = IcuVersion::compare($maxVersion, $urlVersion, '<')
76-
? $urlVersion
77-
: $maxVersion;
74+
$repoDir = sys_get_temp_dir().'/icu-data';
75+
$git = GitRepository::download('https://github.com/unicode-org/icu.git', $repoDir);
7876

79-
echo " $urlVersion\n";
77+
echo "Git clone to {$repoDir} complete.\n";
8078
}
8179

82-
$shortIcuVersion = strip_minor_versions($maxVersion);
83-
84-
if ($argc >= 2) {
85-
$sourceDir = $argv[1];
86-
$svn = new SvnRepository($sourceDir);
87-
88-
echo "Using existing SVN repository at {$sourceDir}.\n";
89-
} else {
90-
echo "Starting SVN checkout for version $shortIcuVersion. This may take a while...\n";
80+
$gitTag = $git->getLastTag(function ($tag) {
81+
return preg_match('#^release-[0-9]{1,}-[0-9]{1}$#', $tag);
82+
});
83+
$shortIcuVersion = strip_minor_versions(preg_replace('#release-([0-9]{1,})-([0-9]{1,})#', '$1.$2', $gitTag));
9184

92-
$sourceDir = sys_get_temp_dir().'/icu-data/'.$shortIcuVersion.'/source';
93-
$svn = SvnRepository::download($urls[$shortIcuVersion], $sourceDir);
85+
echo "Checking out `{$gitTag}` for version `{$shortIcuVersion}`...\n";
86+
$git->checkout('tags/'.$gitTag);
9487

95-
echo "SVN checkout to {$sourceDir} complete.\n";
96-
}
88+
$filesystem = new Filesystem();
89+
$sourceDir = $repoDir.'/icu4c/source';
9790

9891
if ($argc >= 3) {
9992
$buildDir = $argv[2];
@@ -265,23 +258,23 @@
265258

266259
echo "Resource bundle compilation complete.\n";
267260

268-
$svnInfo = <<<SVN_INFO
269-
SVN information
261+
$gitInfo = <<<GIT_INFO
262+
Git information
270263
===============
271264
272-
URL: {$svn->getUrl()}
273-
Revision: {$svn->getLastCommit()->getRevision()}
274-
Author: {$svn->getLastCommit()->getAuthor()}
275-
Date: {$svn->getLastCommit()->getDate()}
265+
URL: {$git->getUrl()}
266+
Revision: {$git->getLastCommitHash()}
267+
Author: {$git->getLastAuthor()}
268+
Date: {$git->getLastAuthoredDate()->format('c')}
276269
277-
SVN_INFO;
270+
GIT_INFO;
278271

279272
foreach ($targetDirs as $targetDir) {
280-
$svnInfoFile = $targetDir.'/svn-info.txt';
273+
$gitInfoFile = $targetDir.'/git-info.txt';
281274

282-
file_put_contents($svnInfoFile, $svnInfo);
275+
file_put_contents($gitInfoFile, $gitInfo);
283276

284-
echo "Wrote $svnInfoFile.\n";
277+
echo "Wrote $gitInfoFile.\n";
285278

286279
$versionFile = $targetDir.'/version.txt';
287280

Resources/data/git-info.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Git information
2+
===============
3+
4+
URL: https://github.com/unicode-org/icu.git
5+
Revision: 4a3ba8eee90ea1414d4f7ee36563e6c9b28fda96
6+
Author: Yoshito Umaoka
7+
Date: 2018-06-20T05:34:56+00:00

Resources/data/svn-info.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

Tests/Util/GitRepositoryTest.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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\Tests\Util;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Filesystem\Filesystem;
16+
use Symfony\Component\Intl\Util\GitRepository;
17+
18+
/**
19+
* @group intl-data
20+
*/
21+
class GitRepositoryTest extends TestCase
22+
{
23+
private $targetDir;
24+
25+
const REPO_URL = 'https://github.com/symfony/intl.git';
26+
27+
/**
28+
* @before
29+
* @after
30+
*/
31+
protected function cleanup()
32+
{
33+
$this->targetDir = sys_get_temp_dir().'/GitRepositoryTest/source';
34+
35+
$fs = new Filesystem();
36+
$fs->remove($this->targetDir);
37+
}
38+
39+
public function testItThrowsAnExceptionIfInitialisedWithNonGitDirectory()
40+
{
41+
$this->expectException('Symfony\Component\Intl\Exception\RuntimeException');
42+
43+
@mkdir($this->targetDir, '0777', true);
44+
45+
new GitRepository($this->targetDir);
46+
}
47+
48+
public function testItClonesTheRepository()
49+
{
50+
$git = GitRepository::download(self::REPO_URL, $this->targetDir);
51+
52+
$this->assertInstanceOf('Symfony\Component\Intl\Util\GitRepository', $git);
53+
$this->assertDirectoryExists($this->targetDir.'/.git');
54+
$this->assertSame($this->targetDir, $git->getPath());
55+
$this->assertSame(self::REPO_URL, $git->getUrl());
56+
$this->assertRegExp('#^[0-9a-z]{40}$#', $git->getLastCommitHash());
57+
$this->assertNotEmpty($git->getLastAuthor());
58+
$this->assertInstanceOf('DateTime', $git->getLastAuthoredDate());
59+
$this->assertStringMatchesFormat('v%s', $git->getLastTag());
60+
$this->assertStringMatchesFormat('v3%s', $git->getLastTag(function ($tag) { return 0 === strpos($tag, 'v3'); }));
61+
}
62+
63+
public function testItCheckoutsToTheLastTag()
64+
{
65+
$git = GitRepository::download(self::REPO_URL, $this->targetDir);
66+
$lastCommitHash = $git->getLastCommitHash();
67+
$lastV3Tag = $git->getLastTag(function ($tag) { return 0 === strpos($tag, 'v3'); });
68+
69+
$git->checkout($lastV3Tag);
70+
71+
$this->assertNotEquals($lastCommitHash, $git->getLastCommitHash());
72+
}
73+
}

Util/GitRepository.php

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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\Util;
13+
14+
use Symfony\Component\Filesystem\Filesystem;
15+
use Symfony\Component\Intl\Exception\RuntimeException;
16+
17+
/**
18+
* @internal
19+
*/
20+
final class GitRepository
21+
{
22+
private $path;
23+
24+
public function __construct(string $path)
25+
{
26+
$this->path = $path;
27+
28+
$this->getUrl();
29+
}
30+
31+
public static function download(string $remote, string $targetDir): self
32+
{
33+
self::exec('which git', 'The command "git" is not installed.');
34+
35+
$filesystem = new Filesystem();
36+
37+
if (!$filesystem->exists($targetDir.'/.git')) {
38+
$filesystem->remove($targetDir);
39+
$filesystem->mkdir($targetDir);
40+
41+
self::exec(sprintf('git clone %s %s', escapeshellarg($remote), escapeshellarg($targetDir)));
42+
}
43+
44+
return new self(realpath($targetDir));
45+
}
46+
47+
public function getPath()
48+
{
49+
return $this->path;
50+
}
51+
52+
public function getUrl()
53+
{
54+
return $this->getLastLine($this->execInPath('git config --get remote.origin.url'));
55+
}
56+
57+
public function getLastCommitHash()
58+
{
59+
return $this->getLastLine($this->execInPath('git log -1 --format="%H"'));
60+
}
61+
62+
public function getLastAuthor()
63+
{
64+
return $this->getLastLine($this->execInPath('git log -1 --format="%an"'));
65+
}
66+
67+
public function getLastAuthoredDate()
68+
{
69+
return new \DateTime($this->getLastLine($this->execInPath('git log -1 --format="%ai"')));
70+
}
71+
72+
public function getLastTag(callable $filter = null)
73+
{
74+
$tags = $this->execInPath('git tag -l --sort=v:refname');
75+
76+
if (null !== $filter) {
77+
$tags = array_filter($tags, $filter);
78+
}
79+
80+
return $this->getLastLine($tags);
81+
}
82+
83+
public function checkout($branch)
84+
{
85+
$this->execInPath(sprintf('git checkout %s', escapeshellarg($branch)));
86+
}
87+
88+
private function execInPath($command)
89+
{
90+
return self::exec(sprintf('cd %s && %s', escapeshellarg($this->path), $command));
91+
}
92+
93+
private static function exec($command, $customErrorMessage = null)
94+
{
95+
exec(sprintf('%s 2>&1', $command), $output, $result);
96+
97+
if (0 !== $result) {
98+
throw new RuntimeException(null !== $customErrorMessage ? $customErrorMessage : sprintf('The `%s` command failed.', $command));
99+
}
100+
101+
return $output;
102+
}
103+
104+
private function getLastLine(array $output)
105+
{
106+
return array_pop($output);
107+
}
108+
}

Util/SvnCommit.php

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)