aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public/ServerVersion.php
blob: 637c34d3619ae18f5c8add6d6e7520fd59b14665 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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;

	}
}