aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/symfony/intl/Symfony/Component/Intl/Util
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/intl/Symfony/Component/Intl/Util')
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/Util/IcuVersion.php105
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/Util/IntlTestHelper.php128
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/Util/SvnCommit.php66
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/Util/SvnRepository.php141
-rw-r--r--vendor/symfony/intl/Symfony/Component/Intl/Util/Version.php96
5 files changed, 536 insertions, 0 deletions
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Util/IcuVersion.php b/vendor/symfony/intl/Symfony/Component/Intl/Util/IcuVersion.php
new file mode 100644
index 00000000..e305a075
--- /dev/null
+++ b/vendor/symfony/intl/Symfony/Component/Intl/Util/IcuVersion.php
@@ -0,0 +1,105 @@
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
12namespace Symfony\Component\Intl\Util;
13
14/**
15 * Facilitates the comparison of ICU version strings.
16 *
17 * @author Bernhard Schussek <bschussek@gmail.com>
18 */
19class IcuVersion
20{
21 /**
22 * Compares two ICU versions with an operator.
23 *
24 * This method is identical to {@link version_compare()}, except that you
25 * can pass the number of regarded version components in the last argument
26 * $precision.
27 *
28 * Also, a single digit release version and a single digit major version
29 * are contracted to a two digit release version. If no major version
30 * is given, it is substituted by zero.
31 *
32 * Examples:
33 *
34 * IcuVersion::compare('1.2.3', '1.2.4', '==')
35 * // => false
36 *
37 * IcuVersion::compare('1.2.3', '1.2.4', '==', 2)
38 * // => true
39 *
40 * IcuVersion::compare('1.2.3', '12.3', '==')
41 * // => true
42 *
43 * IcuVersion::compare('1', '10', '==')
44 * // => true
45 *
46 * @param string $version1 A version string.
47 * @param string $version2 A version string to compare.
48 * @param string $operator The comparison operator.
49 * @param integer|null $precision The number of components to compare. Pass
50 * NULL to compare the versions unchanged.
51 *
52 * @return Boolean Whether the comparison succeeded.
53 *
54 * @see normalize()
55 */
56 public static function compare($version1, $version2, $operator, $precision = null)
57 {
58 $version1 = self::normalize($version1, $precision);
59 $version2 = self::normalize($version2, $precision);
60
61 return version_compare($version1, $version2, $operator);
62 }
63
64 /**
65 * Normalizes a version string to the number of components given in the
66 * parameter $precision.
67 *
68 * A single digit release version and a single digit major version are
69 * contracted to a two digit release version. If no major version is given,
70 * it is substituted by zero.
71 *
72 * Examples:
73 *
74 * IcuVersion::normalize('1.2.3.4');
75 * // => '12.3.4'
76 *
77 * IcuVersion::normalize('1.2.3.4', 1);
78 * // => '12'
79 *
80 * IcuVersion::normalize('1.2.3.4', 2);
81 * // => '12.3'
82 *
83 * @param string $version An ICU version string.
84 * @param integer|null $precision The number of components to include. Pass
85 * NULL to return the version unchanged.
86 *
87 * @return string|null The normalized ICU version or NULL if it couldn't be
88 * normalized.
89 */
90 public static function normalize($version, $precision)
91 {
92 $version = preg_replace('/^(\d)\.(\d)/', '$1$2', $version);
93
94 if (1 === strlen($version)) {
95 $version .= '0';
96 }
97
98 return Version::normalize($version, $precision);
99 }
100
101 /**
102 * Must not be instantiated.
103 */
104 private function __construct() {}
105}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Util/IntlTestHelper.php b/vendor/symfony/intl/Symfony/Component/Intl/Util/IntlTestHelper.php
new file mode 100644
index 00000000..cace36c6
--- /dev/null
+++ b/vendor/symfony/intl/Symfony/Component/Intl/Util/IntlTestHelper.php
@@ -0,0 +1,128 @@
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
12namespace Symfony\Component\Intl\Util;
13
14use Symfony\Component\Intl\Intl;
15
16/**
17 * Helper class for preparing test cases that rely on the Intl component.
18 *
19 * Any test that tests functionality relying on either the intl classes or
20 * the resource bundle data should call either of the methods
21 * {@link requireIntl()} or {@link requireFullIntl()}. Calling
22 * {@link requireFullIntl()} is only necessary if you use functionality in the
23 * test that is not provided by the stub intl implementation.
24 *
25 * @author Bernhard Schussek <bschussek@gmail.com>
26 */
27class IntlTestHelper
28{
29 /**
30 * Should be called before tests that work fine with the stub implementation.
31 *
32 * @param \PhpUnit_Framework_TestCase $testCase
33 */
34 public static function requireIntl(\PhpUnit_Framework_TestCase $testCase)
35 {
36 // We only run tests if the version is *one specific version*.
37 // This condition is satisfied if
38 //
39 // * the intl extension is loaded with version Intl::getIcuStubVersion()
40 // * the intl extension is not loaded
41
42 if (IcuVersion::compare(Intl::getIcuVersion(), Intl::getIcuStubVersion(), '!=', 1)) {
43 $testCase->markTestSkipped('Please change ICU version to ' . Intl::getIcuStubVersion());
44 }
45
46 if (IcuVersion::compare(Intl::getIcuDataVersion(), Intl::getIcuStubVersion(), '!=', 1)) {
47 $testCase->markTestSkipped('Please change the Icu component to version 1.0.x or 1.' . IcuVersion::normalize(Intl::getIcuStubVersion(), 1) . '.x');
48 }
49
50 // Normalize the default locale in case this is not done explicitly
51 // in the test
52 \Locale::setDefault('en');
53
54 // Consequently, tests will
55 //
56 // * run only for one ICU version (see Intl::getIcuStubVersion())
57 // there is no need to add control structures to your tests that
58 // change the test depending on the ICU version.
59 //
60 // Tests should only rely on functionality that is implemented in the
61 // stub classes.
62 }
63
64 /**
65 * Should be called before tests that require a feature-complete intl
66 * implementation.
67 *
68 * @param \PhpUnit_Framework_TestCase $testCase
69 */
70 public static function requireFullIntl(\PhpUnit_Framework_TestCase $testCase)
71 {
72 // We only run tests if the intl extension is loaded...
73 if (!Intl::isExtensionLoaded()) {
74 $testCase->markTestSkipped('The intl extension is not available.');
75 }
76
77 // ... and only if the version is *one specific version* ...
78 if (IcuVersion::compare(Intl::getIcuVersion(), Intl::getIcuStubVersion(), '!=', 1)) {
79 $testCase->markTestSkipped('Please change ICU version to ' . Intl::getIcuStubVersion());
80 }
81
82 // ... and only if the data in the Icu component matches that version.
83 if (IcuVersion::compare(Intl::getIcuDataVersion(), Intl::getIcuStubVersion(), '!=', 1)) {
84 $testCase->markTestSkipped('Please change the Icu component to version 1.0.x or 1.' . IcuVersion::normalize(Intl::getIcuStubVersion(), 1) . '.x');
85 }
86
87 // Normalize the default locale in case this is not done explicitly
88 // in the test
89 \Locale::setDefault('en');
90
91 // Consequently, tests will
92 //
93 // * run only for one ICU version (see Intl::getIcuStubVersion())
94 // there is no need to add control structures to your tests that
95 // change the test depending on the ICU version.
96 // * always use the C intl classes
97 // * always use the binary resource bundles (any locale is allowed)
98 }
99
100 /**
101 * Skips the test unless the current system has a 32bit architecture.
102 *
103 * @param \PhpUnit_Framework_TestCase $testCase
104 */
105 public static function require32Bit(\PhpUnit_Framework_TestCase $testCase)
106 {
107 if (4 !== PHP_INT_SIZE) {
108 $testCase->markTestSkipped('PHP must be compiled in 32 bit mode to run this test');
109 }
110 }
111
112 /**
113 * Skips the test unless the current system has a 64bit architecture.
114 *
115 * @param \PhpUnit_Framework_TestCase $testCase
116 */
117 public static function require64Bit(\PhpUnit_Framework_TestCase $testCase)
118 {
119 if (8 !== PHP_INT_SIZE) {
120 $testCase->markTestSkipped('PHP must be compiled in 64 bit mode to run this test');
121 }
122 }
123
124 /**
125 * Must not be instantiated.
126 */
127 private function __construct() {}
128}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Util/SvnCommit.php b/vendor/symfony/intl/Symfony/Component/Intl/Util/SvnCommit.php
new file mode 100644
index 00000000..483d92bc
--- /dev/null
+++ b/vendor/symfony/intl/Symfony/Component/Intl/Util/SvnCommit.php
@@ -0,0 +1,66 @@
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
12namespace Symfony\Component\Intl\Util;
13
14/**
15 * An SVN commit.
16 *
17 * @author Bernhard Schussek <bschussek@gmail.com>
18 */
19class SvnCommit
20{
21 /**
22 * @var \SimpleXMLElement
23 */
24 private $svnInfo;
25
26 /**
27 * Creates a commit from the given "svn info" data.
28 *
29 * @param \SimpleXMLElement $svnInfo The XML result from the "svn info"
30 * command.
31 */
32 public function __construct(\SimpleXMLElement $svnInfo)
33 {
34 $this->svnInfo = $svnInfo;
35 }
36
37 /**
38 * Returns the revision of the commit.
39 *
40 * @return string The revision of the commit.
41 */
42 public function getRevision()
43 {
44 return (string) $this->svnInfo['revision'];
45 }
46
47 /**
48 * Returns the author of the commit.
49 *
50 * @return string The author name.
51 */
52 public function getAuthor()
53 {
54 return (string) $this->svnInfo->author;
55 }
56
57 /**
58 * Returns the date of the commit.
59 *
60 * @return string The commit date.
61 */
62 public function getDate()
63 {
64 return (string) $this->svnInfo->date;
65 }
66}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Util/SvnRepository.php b/vendor/symfony/intl/Symfony/Component/Intl/Util/SvnRepository.php
new file mode 100644
index 00000000..fb44e3c6
--- /dev/null
+++ b/vendor/symfony/intl/Symfony/Component/Intl/Util/SvnRepository.php
@@ -0,0 +1,141 @@
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
12namespace Symfony\Component\Intl\Util;
13
14use Symfony\Component\Filesystem\Filesystem;
15use Symfony\Component\Intl\Exception\RuntimeException;
16
17/**
18 * A SVN repository containing ICU data.
19 *
20 * @author Bernhard Schussek <bschussek@gmail.com>
21 */
22class SvnRepository
23{
24 /**
25 * @var string The path to the repository.
26 */
27 private $path;
28
29 /**
30 * @var \SimpleXMLElement
31 */
32 private $svnInfo;
33
34 /**
35 * @var SvnCommit
36 */
37 private $lastCommit;
38
39 /**
40 * Downloads the ICU data for the given version.
41 *
42 * @param string $url The URL to download from.
43 * @param string $targetDir The directory in which to store the repository.
44 *
45 * @return SvnRepository The directory where the data is stored.
46 *
47 * @throws RuntimeException If an error occurs during the download.
48 */
49 public static function download($url, $targetDir)
50 {
51 exec('which svn', $output, $result);
52
53 if ($result !== 0) {
54 throw new RuntimeException('The command "svn" is not installed.');
55 }
56
57 $filesystem = new Filesystem();
58
59 if (!$filesystem->exists($targetDir . '/.svn')) {
60 $filesystem->remove($targetDir);
61 $filesystem->mkdir($targetDir);
62
63 exec('svn checkout ' . $url . ' ' . $targetDir, $output, $result);
64
65 if ($result !== 0) {
66 throw new RuntimeException('The SVN checkout of ' . $url . 'failed.');
67 }
68 }
69
70 return new static(realpath($targetDir));
71 }
72
73 /**
74 * Reads the SVN repository at the given path.
75 *
76 * @param string $path The path to the repository.
77 */
78 public function __construct($path)
79 {
80 $this->path = $path;
81 }
82
83 /**
84 * Returns the path to the repository.
85 *
86 * @return string The path to the repository.
87 */
88 public function getPath()
89 {
90 return $this->path;
91 }
92
93 /**
94 * Returns the URL of the repository.
95 *
96 * @return string The URL of the repository.
97 */
98 public function getUrl()
99 {
100 return (string) $this->getSvnInfo()->entry->url;
101 }
102
103 /**
104 * Returns the last commit of the repository.
105 *
106 * @return SvnCommit The last commit.
107 */
108 public function getLastCommit()
109 {
110 if (null === $this->lastCommit) {
111 $this->lastCommit = new SvnCommit($this->getSvnInfo()->entry->commit);
112 }
113
114 return $this->lastCommit;
115 }
116
117 /**
118 * Returns information about the SVN repository.
119 *
120 * @return \SimpleXMLElement The XML result from the "svn info" command.
121 *
122 * @throws RuntimeException If the "svn info" command failed.
123 */
124 private function getSvnInfo()
125 {
126 if (null === $this->svnInfo) {
127 exec('svn info --xml '.$this->path, $output, $result);
128
129 $svnInfo = simplexml_load_string(implode("\n", $output));
130
131 if ($result !== 0) {
132 throw new RuntimeException('svn info failed');
133 }
134
135 $this->svnInfo = $svnInfo;
136 }
137
138 return $this->svnInfo;
139 }
140
141}
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/Util/Version.php b/vendor/symfony/intl/Symfony/Component/Intl/Util/Version.php
new file mode 100644
index 00000000..5f6a4337
--- /dev/null
+++ b/vendor/symfony/intl/Symfony/Component/Intl/Util/Version.php
@@ -0,0 +1,96 @@
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
12namespace Symfony\Component\Intl\Util;
13
14/**
15 * Facilitates the comparison of version strings.
16 *
17 * @author Bernhard Schussek <bschussek@gmail.com>
18 */
19class Version
20{
21 /**
22 * Compares two versions with an operator.
23 *
24 * This method is identical to {@link version_compare()}, except that you
25 * can pass the number of regarded version components in the last argument
26 * $precision.
27 *
28 * Examples:
29 *
30 * Version::compare('1.2.3', '1.2.4', '==')
31 * // => false
32 *
33 * Version::compare('1.2.3', '1.2.4', '==', 2)
34 * // => true
35 *
36 * @param string $version1 A version string.
37 * @param string $version2 A version string to compare.
38 * @param string $operator The comparison operator.
39 * @param integer|null $precision The number of components to compare. Pass
40 * NULL to compare the versions unchanged.
41 *
42 * @return Boolean Whether the comparison succeeded.
43 *
44 * @see normalize()
45 */
46 public static function compare($version1, $version2, $operator, $precision = null)
47 {
48 $version1 = self::normalize($version1, $precision);
49 $version2 = self::normalize($version2, $precision);
50
51 return version_compare($version1, $version2, $operator);
52 }
53
54 /**
55 * Normalizes a version string to the number of components given in the
56 * parameter $precision.
57 *
58 * Examples:
59 *
60 * Version::normalize('1.2.3', 1);
61 * // => '1'
62 *
63 * Version::normalize('1.2.3', 2);
64 * // => '1.2'
65 *
66 * @param string $version A version string.
67 * @param integer|null $precision The number of components to include. Pass
68 * NULL to return the version unchanged.
69 *
70 * @return string|null The normalized version or NULL if it couldn't be
71 * normalized.
72 */
73 public static function normalize($version, $precision)
74 {
75 if (null === $precision) {
76 return $version;
77 }
78
79 $pattern = '[^\.]+';
80
81 for ($i = 2; $i <= $precision; ++$i) {
82 $pattern = sprintf('[^\.]+(\.%s)?', $pattern);
83 }
84
85 if (!preg_match('/^' . $pattern . '/', $version, $matches)) {
86 return null;
87 }
88
89 return $matches[0];
90 }
91
92 /**
93 * Must not be instantiated.
94 */
95 private function __construct() {}
96}