2
0
forked from Wavyzz/dolibarr

SwissQR: add Sprain\SwissQrBill and dependencies

This commit is contained in:
Didier 'OdyX' Raboud
2023-03-16 06:47:59 +01:00
parent 55ab3d2c56
commit f53120c915
2192 changed files with 971358 additions and 0 deletions

View File

@@ -0,0 +1,108 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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;
/**
* @internal
*/
final class GitRepository
{
private string $path;
public function __construct(string $path)
{
$this->path = $path;
$this->getUrl();
}
public static function download(string $remote, string $targetDir): self
{
self::exec('which git', 'The command "git" is not installed.');
$filesystem = new Filesystem();
if (!$filesystem->exists($targetDir.'/.git')) {
$filesystem->remove($targetDir);
$filesystem->mkdir($targetDir);
self::exec(sprintf('git clone %s %s', escapeshellarg($remote), escapeshellarg($targetDir)));
}
return new self(realpath($targetDir));
}
public function getPath(): string
{
return $this->path;
}
public function getUrl(): string
{
return $this->getLastLine($this->execInPath('git config --get remote.origin.url'));
}
public function getLastCommitHash(): string
{
return $this->getLastLine($this->execInPath('git log -1 --format="%H"'));
}
public function getLastAuthor(): string
{
return $this->getLastLine($this->execInPath('git log -1 --format="%an"'));
}
public function getLastAuthoredDate(): \DateTimeImmutable
{
return new \DateTimeImmutable($this->getLastLine($this->execInPath('git log -1 --format="%ai"')));
}
public function getLastTag(callable $filter = null): string
{
$tags = $this->execInPath('git tag -l --sort=v:refname');
if (null !== $filter) {
$tags = array_filter($tags, $filter);
}
return $this->getLastLine($tags);
}
public function checkout(string $branch)
{
$this->execInPath(sprintf('git checkout %s', escapeshellarg($branch)));
}
private function execInPath(string $command): array
{
return self::exec(sprintf('cd %s && %s', escapeshellarg($this->path), $command));
}
private static function exec(string $command, string $customErrorMessage = null): array
{
exec(sprintf('%s 2>&1', $command), $output, $result);
if (0 !== $result) {
throw new RuntimeException($customErrorMessage ?? sprintf('The "%s" command failed.', $command));
}
return $output;
}
private function getLastLine(array $output): string
{
return array_pop($output);
}
}

View File

@@ -0,0 +1,98 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <bschussek@gmail.com>
*/
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 int|null $precision The number of components to compare. Pass
* NULL to compare the versions unchanged.
*
* @see normalize()
*/
public static function compare(string $version1, string $version2, string $operator, int $precision = null): bool
{
$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 int|null $precision The number of components to include. Pass
* NULL to return the version unchanged.
*/
public static function normalize(string $version, ?int $precision): ?string
{
$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()
{
}
}

View File

@@ -0,0 +1,108 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 PHPUnit\Framework\TestCase;
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 <bschussek@gmail.com>
*/
class IntlTestHelper
{
/**
* Should be called before tests that work fine with the stub implementation.
*/
public static function requireIntl(TestCase $testCase, string $minimumIcuVersion = null)
{
$minimumIcuVersion ??= Intl::getIcuStubVersion();
// 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 ($minimumIcuVersion && IcuVersion::compare(Intl::getIcuVersion(), $minimumIcuVersion, '<', 1)) {
$testCase->markTestSkipped('ICU version '.$minimumIcuVersion.' is required.');
}
// 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.
*/
public static function requireFullIntl(TestCase $testCase, string $minimumIcuVersion = null)
{
// We only run tests if the intl extension is loaded...
if (!Intl::isExtensionLoaded()) {
$testCase->markTestSkipped('Extension intl is required.');
}
self::requireIntl($testCase, $minimumIcuVersion);
// 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
}
/**
* Skips the test unless the current system has a 32bit architecture.
*/
public static function require32Bit(TestCase $testCase)
{
if (4 !== \PHP_INT_SIZE) {
$testCase->markTestSkipped('PHP 32 bit is required.');
}
}
/**
* Skips the test unless the current system has a 64bit architecture.
*/
public static function require64Bit(TestCase $testCase)
{
if (8 !== \PHP_INT_SIZE) {
$testCase->markTestSkipped('PHP 64 bit is required.');
}
}
/**
* Must not be instantiated.
*/
private function __construct()
{
}
}

View File

@@ -0,0 +1,89 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <bschussek@gmail.com>
*/
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 int|null $precision The number of components to compare. Pass
* NULL to compare the versions unchanged.
*
* @see normalize()
*/
public static function compare(string $version1, string $version2, string $operator, int $precision = null): bool
{
$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 int|null $precision The number of components to include. Pass
* NULL to return the version unchanged.
*/
public static function normalize(string $version, ?int $precision): ?string
{
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()
{
}
}