From 4f5b44bd3bd490309eb2ba7b44df4769816ba729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 3 Aug 2013 19:26:54 +0200 Subject: twig implementation --- .../Symfony/Component/Intl/Util/IcuVersion.php | 105 +++++++++++++++ .../Symfony/Component/Intl/Util/IntlTestHelper.php | 128 +++++++++++++++++++ .../intl/Symfony/Component/Intl/Util/SvnCommit.php | 66 ++++++++++ .../Symfony/Component/Intl/Util/SvnRepository.php | 141 +++++++++++++++++++++ .../intl/Symfony/Component/Intl/Util/Version.php | 96 ++++++++++++++ 5 files changed, 536 insertions(+) create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Util/IcuVersion.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Util/IntlTestHelper.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Util/SvnCommit.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Util/SvnRepository.php create mode 100644 vendor/symfony/intl/Symfony/Component/Intl/Util/Version.php (limited to 'vendor/symfony/intl/Symfony/Component/Intl/Util') 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 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\Util; + +/** + * Facilitates the comparison of ICU version strings. + * + * @author Bernhard Schussek + */ +class IcuVersion +{ + /** + * Compares two ICU versions with an operator. + * + * This method is identical to {@link version_compare()}, except that you + * can pass the number of regarded version components in the last argument + * $precision. + * + * Also, a single digit release version and a single digit major version + * are contracted to a two digit release version. If no major version + * is given, it is substituted by zero. + * + * Examples: + * + * IcuVersion::compare('1.2.3', '1.2.4', '==') + * // => false + * + * IcuVersion::compare('1.2.3', '1.2.4', '==', 2) + * // => true + * + * IcuVersion::compare('1.2.3', '12.3', '==') + * // => true + * + * IcuVersion::compare('1', '10', '==') + * // => true + * + * @param string $version1 A version string. + * @param string $version2 A version string to compare. + * @param string $operator The comparison operator. + * @param integer|null $precision The number of components to compare. Pass + * NULL to compare the versions unchanged. + * + * @return Boolean Whether the comparison succeeded. + * + * @see normalize() + */ + public static function compare($version1, $version2, $operator, $precision = null) + { + $version1 = self::normalize($version1, $precision); + $version2 = self::normalize($version2, $precision); + + return version_compare($version1, $version2, $operator); + } + + /** + * Normalizes a version string to the number of components given in the + * parameter $precision. + * + * A single digit release version and a single digit major version are + * contracted to a two digit release version. If no major version is given, + * it is substituted by zero. + * + * Examples: + * + * IcuVersion::normalize('1.2.3.4'); + * // => '12.3.4' + * + * IcuVersion::normalize('1.2.3.4', 1); + * // => '12' + * + * IcuVersion::normalize('1.2.3.4', 2); + * // => '12.3' + * + * @param string $version An ICU version string. + * @param integer|null $precision The number of components to include. Pass + * NULL to return the version unchanged. + * + * @return string|null The normalized ICU version or NULL if it couldn't be + * normalized. + */ + public static function normalize($version, $precision) + { + $version = preg_replace('/^(\d)\.(\d)/', '$1$2', $version); + + if (1 === strlen($version)) { + $version .= '0'; + } + + return Version::normalize($version, $precision); + } + + /** + * Must not be instantiated. + */ + private function __construct() {} +} 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 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\Util; + +use Symfony\Component\Intl\Intl; + +/** + * Helper class for preparing test cases that rely on the Intl component. + * + * Any test that tests functionality relying on either the intl classes or + * the resource bundle data should call either of the methods + * {@link requireIntl()} or {@link requireFullIntl()}. Calling + * {@link requireFullIntl()} is only necessary if you use functionality in the + * test that is not provided by the stub intl implementation. + * + * @author Bernhard Schussek + */ +class IntlTestHelper +{ + /** + * Should be called before tests that work fine with the stub implementation. + * + * @param \PhpUnit_Framework_TestCase $testCase + */ + public static function requireIntl(\PhpUnit_Framework_TestCase $testCase) + { + // We only run tests if the version is *one specific version*. + // This condition is satisfied if + // + // * the intl extension is loaded with version Intl::getIcuStubVersion() + // * the intl extension is not loaded + + if (IcuVersion::compare(Intl::getIcuVersion(), Intl::getIcuStubVersion(), '!=', 1)) { + $testCase->markTestSkipped('Please change ICU version to ' . Intl::getIcuStubVersion()); + } + + if (IcuVersion::compare(Intl::getIcuDataVersion(), Intl::getIcuStubVersion(), '!=', 1)) { + $testCase->markTestSkipped('Please change the Icu component to version 1.0.x or 1.' . IcuVersion::normalize(Intl::getIcuStubVersion(), 1) . '.x'); + } + + // Normalize the default locale in case this is not done explicitly + // in the test + \Locale::setDefault('en'); + + // Consequently, tests will + // + // * run only for one ICU version (see Intl::getIcuStubVersion()) + // there is no need to add control structures to your tests that + // change the test depending on the ICU version. + // + // Tests should only rely on functionality that is implemented in the + // stub classes. + } + + /** + * Should be called before tests that require a feature-complete intl + * implementation. + * + * @param \PhpUnit_Framework_TestCase $testCase + */ + public static function requireFullIntl(\PhpUnit_Framework_TestCase $testCase) + { + // We only run tests if the intl extension is loaded... + if (!Intl::isExtensionLoaded()) { + $testCase->markTestSkipped('The intl extension is not available.'); + } + + // ... and only if the version is *one specific version* ... + if (IcuVersion::compare(Intl::getIcuVersion(), Intl::getIcuStubVersion(), '!=', 1)) { + $testCase->markTestSkipped('Please change ICU version to ' . Intl::getIcuStubVersion()); + } + + // ... and only if the data in the Icu component matches that version. + if (IcuVersion::compare(Intl::getIcuDataVersion(), Intl::getIcuStubVersion(), '!=', 1)) { + $testCase->markTestSkipped('Please change the Icu component to version 1.0.x or 1.' . IcuVersion::normalize(Intl::getIcuStubVersion(), 1) . '.x'); + } + + // Normalize the default locale in case this is not done explicitly + // in the test + \Locale::setDefault('en'); + + // Consequently, tests will + // + // * run only for one ICU version (see Intl::getIcuStubVersion()) + // there is no need to add control structures to your tests that + // change the test depending on the ICU version. + // * always use the C intl classes + // * always use the binary resource bundles (any locale is allowed) + } + + /** + * Skips the test unless the current system has a 32bit architecture. + * + * @param \PhpUnit_Framework_TestCase $testCase + */ + public static function require32Bit(\PhpUnit_Framework_TestCase $testCase) + { + if (4 !== PHP_INT_SIZE) { + $testCase->markTestSkipped('PHP must be compiled in 32 bit mode to run this test'); + } + } + + /** + * Skips the test unless the current system has a 64bit architecture. + * + * @param \PhpUnit_Framework_TestCase $testCase + */ + public static function require64Bit(\PhpUnit_Framework_TestCase $testCase) + { + if (8 !== PHP_INT_SIZE) { + $testCase->markTestSkipped('PHP must be compiled in 64 bit mode to run this test'); + } + } + + /** + * Must not be instantiated. + */ + private function __construct() {} +} 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 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\Util; + +/** + * An SVN commit. + * + * @author Bernhard Schussek + */ +class SvnCommit +{ + /** + * @var \SimpleXMLElement + */ + private $svnInfo; + + /** + * Creates a commit from the given "svn info" data. + * + * @param \SimpleXMLElement $svnInfo The XML result from the "svn info" + * command. + */ + public function __construct(\SimpleXMLElement $svnInfo) + { + $this->svnInfo = $svnInfo; + } + + /** + * Returns the revision of the commit. + * + * @return string The revision of the commit. + */ + public function getRevision() + { + return (string) $this->svnInfo['revision']; + } + + /** + * Returns the author of the commit. + * + * @return string The author name. + */ + public function getAuthor() + { + return (string) $this->svnInfo->author; + } + + /** + * Returns the date of the commit. + * + * @return string The commit date. + */ + public function getDate() + { + return (string) $this->svnInfo->date; + } +} 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 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\Util; + +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Intl\Exception\RuntimeException; + +/** + * A SVN repository containing ICU data. + * + * @author Bernhard Schussek + */ +class SvnRepository +{ + /** + * @var string The path to the repository. + */ + private $path; + + /** + * @var \SimpleXMLElement + */ + private $svnInfo; + + /** + * @var SvnCommit + */ + private $lastCommit; + + /** + * Downloads the ICU data for the given version. + * + * @param string $url The URL to download from. + * @param string $targetDir The directory in which to store the repository. + * + * @return SvnRepository The directory where the data is stored. + * + * @throws RuntimeException If an error occurs during the download. + */ + public static function download($url, $targetDir) + { + exec('which svn', $output, $result); + + if ($result !== 0) { + throw new RuntimeException('The command "svn" is not installed.'); + } + + $filesystem = new Filesystem(); + + if (!$filesystem->exists($targetDir . '/.svn')) { + $filesystem->remove($targetDir); + $filesystem->mkdir($targetDir); + + exec('svn checkout ' . $url . ' ' . $targetDir, $output, $result); + + if ($result !== 0) { + throw new RuntimeException('The SVN checkout of ' . $url . 'failed.'); + } + } + + return new static(realpath($targetDir)); + } + + /** + * Reads the SVN repository at the given path. + * + * @param string $path The path to the repository. + */ + public function __construct($path) + { + $this->path = $path; + } + + /** + * Returns the path to the repository. + * + * @return string The path to the repository. + */ + public function getPath() + { + return $this->path; + } + + /** + * Returns the URL of the repository. + * + * @return string The URL of the repository. + */ + public function getUrl() + { + return (string) $this->getSvnInfo()->entry->url; + } + + /** + * Returns the last commit of the repository. + * + * @return SvnCommit The last commit. + */ + public function getLastCommit() + { + if (null === $this->lastCommit) { + $this->lastCommit = new SvnCommit($this->getSvnInfo()->entry->commit); + } + + return $this->lastCommit; + } + + /** + * Returns information about the SVN repository. + * + * @return \SimpleXMLElement The XML result from the "svn info" command. + * + * @throws RuntimeException If the "svn info" command failed. + */ + private function getSvnInfo() + { + if (null === $this->svnInfo) { + exec('svn info --xml '.$this->path, $output, $result); + + $svnInfo = simplexml_load_string(implode("\n", $output)); + + if ($result !== 0) { + throw new RuntimeException('svn info failed'); + } + + $this->svnInfo = $svnInfo; + } + + return $this->svnInfo; + } + +} 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 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\Util; + +/** + * Facilitates the comparison of version strings. + * + * @author Bernhard Schussek + */ +class Version +{ + /** + * Compares two versions with an operator. + * + * This method is identical to {@link version_compare()}, except that you + * can pass the number of regarded version components in the last argument + * $precision. + * + * Examples: + * + * Version::compare('1.2.3', '1.2.4', '==') + * // => false + * + * Version::compare('1.2.3', '1.2.4', '==', 2) + * // => true + * + * @param string $version1 A version string. + * @param string $version2 A version string to compare. + * @param string $operator The comparison operator. + * @param integer|null $precision The number of components to compare. Pass + * NULL to compare the versions unchanged. + * + * @return Boolean Whether the comparison succeeded. + * + * @see normalize() + */ + public static function compare($version1, $version2, $operator, $precision = null) + { + $version1 = self::normalize($version1, $precision); + $version2 = self::normalize($version2, $precision); + + return version_compare($version1, $version2, $operator); + } + + /** + * Normalizes a version string to the number of components given in the + * parameter $precision. + * + * Examples: + * + * Version::normalize('1.2.3', 1); + * // => '1' + * + * Version::normalize('1.2.3', 2); + * // => '1.2' + * + * @param string $version A version string. + * @param integer|null $precision The number of components to include. Pass + * NULL to return the version unchanged. + * + * @return string|null The normalized version or NULL if it couldn't be + * normalized. + */ + public static function normalize($version, $precision) + { + if (null === $precision) { + return $version; + } + + $pattern = '[^\.]+'; + + for ($i = 2; $i <= $precision; ++$i) { + $pattern = sprintf('[^\.]+(\.%s)?', $pattern); + } + + if (!preg_match('/^' . $pattern . '/', $version, $matches)) { + return null; + } + + return $matches[0]; + } + + /** + * Must not be instantiated. + */ + private function __construct() {} +} -- cgit v1.2.3