1
0

ServerVersion.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP;
  8. /**
  9. * @since 31.0.0
  10. */
  11. class ServerVersion {
  12. private array $version;
  13. private string $versionString;
  14. private string $build;
  15. /** @var 'beta'|'stable'|'enterprise'|'git' */
  16. private string $channel;
  17. /**
  18. * @since 31.0.0
  19. */
  20. public function __construct() {
  21. $versionFile = __DIR__ . '/../../version.php';
  22. require $versionFile;
  23. /** @var int[] $OC_Version */
  24. $this->version = $OC_Version;
  25. /** @var string $OC_VersionString */
  26. $this->versionString = $OC_VersionString;
  27. /** @var string $OC_Build */
  28. $this->build = $OC_Build;
  29. /** @var string $OC_Channel */
  30. $this->channel = $OC_Channel;
  31. }
  32. /**
  33. * @since 31.0.0
  34. */
  35. public function getMajorVersion(): int {
  36. return $this->version[0];
  37. }
  38. /**
  39. * @since 31.0.0
  40. */
  41. public function getMinorVersion(): int {
  42. return $this->version[1];
  43. }
  44. /**
  45. * @since 31.0.0
  46. */
  47. public function getPatchVersion(): int {
  48. return $this->version[2];
  49. }
  50. /**
  51. * @since 31.0.0
  52. */
  53. public function getVersion(): array {
  54. return $this->version;
  55. }
  56. /**
  57. * @since 31.0.0
  58. */
  59. public function getVersionString(): string {
  60. return $this->versionString;
  61. }
  62. /**
  63. * @psalm-return 'beta'|'stable'|'enterprise'|'git'
  64. * @since 31.0.0
  65. */
  66. public function getChannel(): string {
  67. return $this->channel;
  68. }
  69. /**
  70. * @since 31.0.0
  71. */
  72. public function getBuild(): string {
  73. return $this->build;
  74. }
  75. /**
  76. * @since 31.0.0
  77. */
  78. public function getHumanVersion(): string {
  79. $version = $this->getVersionString();
  80. $build = $this->getBuild();
  81. if (!empty($build) && $this->getChannel() === 'daily') {
  82. $version .= ' Build:' . $build;
  83. }
  84. return $version;
  85. }
  86. }