FOSSology  4.4.0
Open Source License Compliance by Open Source Software
PurlOperations.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2022 Siemens AG
4  Author: Gaurav Mishra <mishra.gaurav@siemens.com>
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
9 namespace Fossology\Lib\Util;
10 
12 {
19  public static function fromString($input)
20  {
21  $scheme = null;
22  $type = null;
23  $namespace = null;
24  $name = null;
25  $version = null;
26  $qualifiers = null;
27  $subpath = null;
28  $split = explode("#", $input);
29  if (count($split) > 1) {
30  $subpath = trim($split[1], " /");
31  $subpaths = explode("/", $subpath);
32  $subpath = [];
33  foreach ($subpaths as $sp) {
34  if ($sp != "." || $sp != "..") {
35  $subpath[] = urldecode($sp);
36  }
37  }
38  $subpath = implode("/", $subpath);
39  }
40  $split = explode("?", $split[0]);
41  if (count($split) > 1) {
42  $qualifiers = [];
43  $parts = explode("&", $split[1]);
44  foreach ($parts as $part) {
45  $pair = explode("=", $part);
46  if (empty($pair[1])) {
47  continue;
48  }
49  $qualifiers[$pair[0]] = urldecode($pair[1]);
50  }
51  }
52  $split = explode(":", $split[0]);
53  $scheme = strtolower($split[0]);
54  $split = explode("/", trim($split[1], " /"));
55  $type = strtolower($split[0]);
56  $split = explode("@", implode("/", array_slice($split, 1)));
57  if (count($split) > 1) {
58  $version = urldecode($split[1]);
59  }
60  $split = explode("/", $split[0]);
61  $splitClone = array_values($split);
62  $name = end($splitClone);
63  $name = urldecode($name);
64  $namespace = [];
65  for ($i = 0; $i < count($split) - 1; $i++) {
66  $namespace[] = urldecode($split[$i]);
67  }
68  $namespace = implode("/", $namespace);
69  if (empty($namespace)) {
70  $namespace = null;
71  }
72  return [
73  "scheme" => $scheme,
74  "type" => $type,
75  "namespace" => $namespace,
76  "name" => $name,
77  "version" => $version,
78  "qualifiers" => $qualifiers,
79  "subpath" => $subpath
80  ];
81  }
82 }
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:690