aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public
diff options
context:
space:
mode:
Diffstat (limited to 'lib/public')
-rw-r--r--lib/public/ServerVersion.php102
-rw-r--r--lib/public/Util.php10
2 files changed, 108 insertions, 4 deletions
diff --git a/lib/public/ServerVersion.php b/lib/public/ServerVersion.php
new file mode 100644
index 00000000000..637c34d3619
--- /dev/null
+++ b/lib/public/ServerVersion.php
@@ -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;
+
+ }
+}
diff --git a/lib/public/Util.php b/lib/public/Util.php
index 520e4616de5..28da91c9a0f 100644
--- a/lib/public/Util.php
+++ b/lib/public/Util.php
@@ -35,9 +35,10 @@ class Util {
* get the current installed version of Nextcloud
* @return array
* @since 4.0.0
+ * @deprecated 31.0.0 Use \OCP\ServerVersion::getVersion
*/
public static function getVersion() {
- return \OC_Util::getVersion();
+ return Server::get(ServerVersion::class)->getVersion();
}
/**
@@ -46,7 +47,7 @@ class Util {
public static function hasExtendedSupport(): bool {
try {
/** @var \OCP\Support\Subscription\IRegistry */
- $subscriptionRegistry = \OCP\Server::get(\OCP\Support\Subscription\IRegistry::class);
+ $subscriptionRegistry = Server::get(\OCP\Support\Subscription\IRegistry::class);
return $subscriptionRegistry->delegateHasExtendedSupport();
} catch (ContainerExceptionInterface $e) {
}
@@ -66,9 +67,10 @@ class Util {
* Get current update channel
* @return string
* @since 8.1.0
+ * @deprecated 31.0.0 Use \OCP\ServerVersion::getChannel
*/
public static function getChannel() {
- return \OC_Util::getChannel();
+ return \OCP\Server::get(ServerVersion::class)->getChannel();
}
/**
@@ -567,7 +569,7 @@ class Util {
if (!function_exists($functionName)) {
return false;
}
- $ini = \OCP\Server::get(IniGetWrapper::class);
+ $ini = Server::get(IniGetWrapper::class);
$disabled = explode(',', $ini->get('disable_functions') ?: '');
$disabled = array_map('trim', $disabled);
if (in_array($functionName, $disabled)) {