FOSSology  4.4.0
Open Source License Compliance by Open Source Software
File.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2017, 2020 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
12 namespace Fossology\UI\Api\Models;
13 
18 class File
19 {
20 
25  const NOT_FOUND = "Not found";
30  const INVALID = "Invalid keys";
31 
36  private $hash;
41  private $findings;
46  private $uploads;
51  private $message;
52 
57  public function __construct($hash)
58  {
59  $this->hash = $hash;
60  $this->findings = null;
61  $this->uploads = null;
62  $this->message = "";
63  }
64 
68  public function getHash()
69  {
70  return $this->hash;
71  }
72 
77  public function getFindings()
78  {
79  if ($this->message == self::NOT_FOUND || $this->message == self::INVALID) {
80  return null;
81  }
82  return $this->findings;
83  }
84 
88  public function getUploads()
89  {
90  if (count($this->uploads) == 1 && $this->uploads[0] == 0) {
91  return null;
92  }
93  return $this->uploads;
94  }
95 
99  public function getMessage()
100  {
101  return $this->message;
102  }
103 
107  public function setHash($hash)
108  {
109  $this->hash = $hash;
110  }
111 
115  public function setFindings($findings)
116  {
117  $this->findings = $findings;
118  }
119 
123  public function setUploads($uploads)
124  {
125  if (is_array($uploads)) {
126  $this->uploads = $uploads;
127  } else {
128  if ($this->uploads === null) {
129  $this->uploads = array();
130  }
131  $this->uploads[] = intval($uploads);
132  }
133  }
134 
138  public function setMessage($message)
139  {
140  $this->message = $message;
141  }
142 
149  public function getArray()
150  {
151  $returnArray = [];
152  $returnArray['hash'] = $this->hash->getArray();
153  if ($this->message != self::NOT_FOUND && $this->message != self::INVALID) {
154  $returnArray['findings'] = $this->getFindings()->getArray();
155  $returnArray['uploads'] = $this->getUploads();
156  } else {
157  $returnArray['message'] = $this->getMessage();
158  }
159  return $returnArray;
160  }
161 
169  public static function parseFromArray($inputList)
170  {
171  $fileList = [];
172  foreach ($inputList as $fileJson) {
173  $hash = Hash::createFromArray($fileJson);
174  if ($hash === null) {
175  $hash = new Hash();
176  $file = new File($hash);
177  $file->setMessage(self::INVALID);
178  } else {
179  $file = new File($hash);
180  }
181  $fileList[] = $file;
182  }
183  return $fileList;
184  }
185 }
File model holding information about a single file.
Definition: File.php:19
static parseFromArray($inputList)
Definition: File.php:169
Hash model holding information about file like checksums and size.
Definition: Hash.php:18
static createFromArray($inputArray)
Definition: Hash.php:125