Signed-off-by: Julius Knorr <jus@bitgrid.net>pull/48152/head
parent
7ff911665e
commit
606241caeb
@ -0,0 +1,102 @@ |
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
/** |
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
||||
* SPDX-License-Identifier: AGPL-3.0-or-later |
||||
*/ |
||||
|
||||
namespace OCP; |
||||
|
||||
/** |
||||
* @since 31.0.0 |
||||
*/ |
||||
class ServerVersion { |
||||
|
||||
private array $version; |
||||
private string $versionString; |
||||
private string $build; |
||||
/** @var 'beta'|'stable'|'enterprise'|'git' */ |
||||
private string $channel; |
||||
|
||||
/** |
||||
* @since 31.0.0 |
||||
*/ |
||||
public function __construct() { |
||||
$versionFile = __DIR__ . '/../../version.php'; |
||||
require $versionFile; |
||||
|
||||
/** @var int[] $OC_Version */ |
||||
$this->version = $OC_Version; |
||||
/** @var string $OC_VersionString */ |
||||
$this->versionString = $OC_VersionString; |
||||
/** @var string $OC_Build */ |
||||
$this->build = $OC_Build; |
||||
/** @var string $OC_Channel */ |
||||
$this->channel = $OC_Channel; |
||||
} |
||||
|
||||
/** |
||||
* @since 31.0.0 |
||||
*/ |
||||
public function getMajorVersion(): int { |
||||
return $this->version[0]; |
||||
} |
||||
|
||||
/** |
||||
* @since 31.0.0 |
||||
*/ |
||||
public function getMinorVersion(): int { |
||||
return $this->version[1]; |
||||
} |
||||
|
||||
/** |
||||
* @since 31.0.0 |
||||
*/ |
||||
public function getPatchVersion(): int { |
||||
return $this->version[2]; |
||||
} |
||||
|
||||
/** |
||||
* @since 31.0.0 |
||||
*/ |
||||
public function getVersion(): array { |
||||
return $this->version; |
||||
} |
||||
|
||||
/** |
||||
* @since 31.0.0 |
||||
*/ |
||||
public function getVersionString(): string { |
||||
return $this->versionString; |
||||
} |
||||
|
||||
/** |
||||
* @psalm-return 'beta'|'stable'|'enterprise'|'git' |
||||
* @since 31.0.0 |
||||
*/ |
||||
public function getChannel(): string { |
||||
return $this->channel; |
||||
} |
||||
|
||||
/** |
||||
* @since 31.0.0 |
||||
*/ |
||||
public function getBuild(): string { |
||||
return $this->build; |
||||
} |
||||
|
||||
/** |
||||
* @since 31.0.0 |
||||
*/ |
||||
public function getHumanVersion(): string { |
||||
$version = $this->getVersionString(); |
||||
$build = $this->getBuild(); |
||||
if (!empty($build) && $this->getChannel() === 'daily') { |
||||
$version .= ' Build:' . $build; |
||||
} |
||||
return $version; |
||||
|
||||
} |
||||
} |
@ -1,30 +0,0 @@ |
||||
<?php |
||||
/** |
||||
* SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors |
||||
* SPDX-FileCopyrightText: 2016 ownCloud, Inc. |
||||
* SPDX-License-Identifier: AGPL-3.0-or-later |
||||
*/ |
||||
|
||||
namespace Test\PublicNamespace; |
||||
|
||||
class UtilTest extends \Test\TestCase { |
||||
/** |
||||
* @dataProvider channelProvider |
||||
* |
||||
* @param string $channel |
||||
*/ |
||||
public function testOverrideChannel($channel): void { |
||||
\OCP\Util::setChannel($channel); |
||||
$actual = \OCP\Util::getChannel($channel); |
||||
$this->assertEquals($channel, $actual); |
||||
} |
||||
|
||||
public function channelProvider() { |
||||
return [ |
||||
['daily'], |
||||
['beta'], |
||||
['stable'], |
||||
['production'] |
||||
]; |
||||
} |
||||
} |
Loading…
Reference in new issue