FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
Reuser.php
Go to the documentation of this file.
1 <?php
2 /***************************************************************
3  * Copyright (C) 2018 Siemens AG
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * version 2 as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  ***************************************************************/
22 namespace Fossology\UI\Api\Models;
23 
28 class Reuser
29 {
34  private $reuseUpload;
39  private $reuseGroup;
44  private $reuseMain;
49  private $reuseEnhanced;
50 
61  public function __construct($reuseUpload, $reuseGroup, $reuseMain = false,
62  $reuseEnhanced = false)
63  {
64  if (is_numeric($reuseUpload) && is_numeric($reuseGroup)) {
65  $this->reuseUpload = $reuseUpload;
66  $this->reuseGroup = $reuseGroup;
67  $this->reuseMain = $reuseMain;
68  $this->reuseEnhanced = $reuseEnhanced;
69  } else {
70  throw new \UnexpectedValueException(
71  "reuse_upload and reuse_group should be integers", 400);
72  }
73  }
74 
83  public function setUsingArray($reuserArray)
84  {
85  if (array_key_exists("reuse_upload", $reuserArray)) {
86  $this->reuseUpload = filter_var($reuserArray["reuse_upload"],
87  FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
88  }
89  if (array_key_exists("reuse_group", $reuserArray)) {
90  $this->reuseGroup = filter_var($reuserArray["reuse_group"],
91  FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
92  }
93  if (array_key_exists("reuse_main", $reuserArray)) {
94  $this->reuseMain = filter_var($reuserArray["reuse_main"],
95  FILTER_VALIDATE_BOOLEAN);
96  }
97  if (array_key_exists("reuse_enhanced", $reuserArray)) {
98  $this->reuseEnhanced = filter_var($reuserArray["reuse_enhanced"],
99  FILTER_VALIDATE_BOOLEAN);
100  }
101  if ($this->reuseUpload === null || $this->reuseGroup === null) {
102  throw new \UnexpectedValueException(
103  "reuse_upload and reuse_group should be integers", 400);
104  }
105  return $this;
106  }
107 
109 
112  public function getReuseUpload()
113  {
114  return $this->reuseUpload;
115  }
116 
120  public function getReuseGroup()
121  {
122  return $this->reuseGroup;
123  }
124 
128  public function getReuseMain()
129  {
130  return $this->reuseMain;
131  }
132 
136  public function getReuseEnhanced()
137  {
138  return $this->reuseEnhanced;
139  }
140 
142 
145  public function setReuseUpload($reuseUpload)
146  {
147  $this->reuseUpload = filter_var($reuseUpload,
148  FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
149  if ($this->reuseUpload === null) {
150  throw new \UnexpectedValueException("Reuse upload should be an integer!", 400);
151  }
152  }
153 
157  public function setReuseGroup($reuseGroup)
158  {
159  $this->reuseGroup = filter_var($reuseGroup,
160  FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
161  if ($this->reuseGroup === null) {
162  throw new \UnexpectedValueException("Reuse group should be an integer!", 400);
163  }
164  }
165 
169  public function setReuseMain($reuseMain)
170  {
171  $this->reuseMain = filter_var($reuseMain,
172  FILTER_VALIDATE_BOOLEAN);
173  }
174 
179  {
180  $this->reuseEnhanced = filter_var($reuseEnhanced,
181  FILTER_VALIDATE_BOOLEAN);
182  }
183 
188  public function getArray()
189  {
190  return [
191  "reuse_upload" => $this->reuseUpload,
192  "reuse_group" => $this->reuseGroup,
193  "reuse_main" => $this->reuseMain,
194  "reuse_enhanced" => $this->reuseEnhanced
195  ];
196  }
197 }
setUsingArray($reuserArray)
Definition: Reuser.php:83
setReuseUpload($reuseUpload)
Definition: Reuser.php:145
Model to hold info required by Reuser agent.
Definition: Reuser.php:28
setReuseEnhanced($reuseEnhanced)
Definition: Reuser.php:178
__construct($reuseUpload, $reuseGroup, $reuseMain=false, $reuseEnhanced=false)
Definition: Reuser.php:61