FOSSology  4.5.1
Open Source License Compliance by Open Source Software
ApiVersion.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2023 Samuel Dushimimana <dushsam100@gmail.com>
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
11 namespace Fossology\UI\Api\Models;
12 
13 use Psr\Http\Message\ServerRequestInterface;
14 
20 {
21  const V1 = 1;
22  const V2 = 2;
23  const ATTRIBUTE_NAME = 'apiVersion';
24 
29  public static function getVersion(ServerRequestInterface $request): int
30  {
31  return $request->getAttribute(self::ATTRIBUTE_NAME, self::V1);
32  }
33 
34  public static function getVersionFromUri(): int
35  {
36  $uri = $_SERVER['REQUEST_URI'];
37  $apiVersion = ApiVersion::V1;
38 
39  if (strpos($uri, '/api/v2/') !== false) {
40  $apiVersion = ApiVersion::V2;
41  }
42 
43  return $apiVersion;
44  }
45 }
static getVersion(ServerRequestInterface $request)
Definition: ApiVersion.php:29