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 namespace Symfony\Component\Intl\Util
;
14 use Symfony\Component\Filesystem\Filesystem
;
15 use Symfony\Component\Intl\Exception\RuntimeException
;
18 * A SVN repository containing ICU data.
20 * @author Bernhard Schussek <bschussek@gmail.com>
25 * @var string The path to the repository.
30 * @var \SimpleXMLElement
40 * Downloads the ICU data for the given version.
42 * @param string $url The URL to download from.
43 * @param string $targetDir The directory in which to store the repository.
45 * @return SvnRepository The directory where the data is stored.
47 * @throws RuntimeException If an error occurs during the download.
49 public static function download($url, $targetDir)
51 exec('which svn', $output, $result);
54 throw new RuntimeException('The command "svn" is not installed.');
57 $filesystem = new Filesystem();
59 if (!$filesystem->exists($targetDir . '/.svn')) {
60 $filesystem->remove($targetDir);
61 $filesystem->mkdir($targetDir);
63 exec('svn checkout ' . $url . ' ' . $targetDir, $output, $result);
66 throw new RuntimeException('The SVN checkout of ' . $url . 'failed.');
70 return new static(realpath($targetDir));
74 * Reads the SVN repository at the given path.
76 * @param string $path The path to the repository.
78 public function __construct($path)
84 * Returns the path to the repository.
86 * @return string The path to the repository.
88 public function getPath()
94 * Returns the URL of the repository.
96 * @return string The URL of the repository.
98 public function getUrl()
100 return (string) $this->getSvnInfo()->entry
->url
;
104 * Returns the last commit of the repository.
106 * @return SvnCommit The last commit.
108 public function getLastCommit()
110 if (null === $this->lastCommit
) {
111 $this->lastCommit
= new SvnCommit($this->getSvnInfo()->entry
->commit
);
114 return $this->lastCommit
;
118 * Returns information about the SVN repository.
120 * @return \SimpleXMLElement The XML result from the "svn info" command.
122 * @throws RuntimeException If the "svn info" command failed.
124 private function getSvnInfo()
126 if (null === $this->svnInfo
) {
127 exec('svn info --xml '.$this->path
, $output, $result);
129 $svnInfo = simplexml_load_string(implode("\n", $output));
132 throw new RuntimeException('svn info failed');
135 $this->svnInfo
= $svnInfo;
138 return $this->svnInfo
;