9 namespace Fossology\Lib\Data\Report;
22 const SUPPORTED_VERSIONS = [
'1.4',
'1.5',
'1.6',
'1.7'];
23 const DEFAULT_VERSION =
'1.7';
24 const DEFAULT_NAMESPACE =
'fossology:';
25 const MAX_NAMESPACE_LENGTH = 64;
30 private $licenseComment;
32 private $ignoreFilesWithoutInfo;
34 private $osselotExport;
36 private $tagNamespace;
44 bool $ignoreFilesWithoutInfo =
false,
bool $osselotExport =
false,
45 ?
string $tagNamespace =
null, ?
string $specVersion =
null)
47 $this->licenseComment = $licenseComment;
48 $this->ignoreFilesWithoutInfo = $ignoreFilesWithoutInfo;
49 $this->osselotExport = $osselotExport;
60 $namespace =
trim((
string) $namespace);
61 if ($namespace ===
'') {
64 if (substr($namespace, -1) !==
':') {
67 if (strlen($namespace) > self::MAX_NAMESPACE_LENGTH ||
68 !preg_match(self::NAMESPACE_PATTERN, $namespace)) {
80 return in_array($version, self::SUPPORTED_VERSIONS,
true) ? $version :
null;
89 $fields = array_pad(explode(
',', (
string) $csv), 5,
null);
90 return new self($fields[1] ===
'checked', $fields[2] ===
'checked',
91 $fields[0] ===
'checked', $fields[3], $fields[4]);
99 return implode(
',', [self::flag($this->osselotExport),
100 self::flag($this->licenseComment), self::flag($this->ignoreFilesWithoutInfo),
101 $this->tagNamespace, $this->specVersion]);
110 $data = json_decode((
string) $json,
true);
111 if (!is_array($data)) {
114 return new self(!empty($data[
'licenseComment']),
115 !empty($data[
'ignoreFilesWithoutInfo']), !empty($data[
'osselotExport']),
116 isset($data[
'tagNamespace']) ? (string) $data[
'tagNamespace'] :
null,
117 isset($data[
'specVersion']) ? (string) $data[
'specVersion'] :
null);
126 'licenseComment' => $this->licenseComment,
127 'ignoreFilesWithoutInfo' => $this->ignoreFilesWithoutInfo,
128 'osselotExport' => $this->osselotExport,
129 'tagNamespace' => $this->tagNamespace,
130 'specVersion' => $this->specVersion
140 return $this->licenseComment || $this->osselotExport;
148 return $this->licenseComment;
151 public function isIgnoreFilesWithoutInfo(): bool
153 return $this->ignoreFilesWithoutInfo;
156 public function isOsselotExport(): bool
158 return $this->osselotExport;
161 public function getTagNamespace(): string
163 return $this->tagNamespace;
166 public function getSpecVersion(): string
168 return $this->specVersion;
171 private static function flag(
bool $value): string
173 return $value ?
'checked' :
'unchecked';
CycloneDX export settings of a user (defaults) or of an upload.
isLicenseCommentEnabled()
static fromUserSettings(?string $csv)
static normaliseSpecVersion(?string $version)
isLicenseCommentChecked()
static fromReportInfo(?string $json)
static normaliseNamespace(?string $namespace)
__construct(bool $licenseComment=false, bool $ignoreFilesWithoutInfo=false, bool $osselotExport=false, ?string $tagNamespace=null, ?string $specVersion=null)
char * trim(char *ptext)
Trimming whitespace.