FOSSology  4.4.0
Open Source License Compliance by Open Source Software
LicenseCompatibilityRulesYamlExport.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2024 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
9 
12 
23 {
26  private $dbManager;
35  public function __construct(DbManager $dbManager,
37  {
38  $this->dbManager = $dbManager;
39  $this->compatibilityDao = $compatibilityDao;
40  }
46  public function createYaml($lr=0)
47  {
48  $sql = "SELECT lrm.rf_shortname AS firstname, lrs.rf_shortname AS secondname,
49  first_type AS firsttype, second_type AS secondtype,
50  CASE compatibility WHEN 't' THEN 'true' ELSE 'false' END AS compatibility,
51  comment
52  FROM license_rules r
53  LEFT JOIN license_ref lrm ON lrm.rf_pk = r.first_rf_fk
54  LEFT JOIN license_ref lrs ON lrs.rf_pk = r.second_rf_fk";
55  $param = [];
56  if ($lr > 0) {
57  $stmt = __METHOD__ . '.lr';
58  $param[] = $lr;
59  $sql .= ' WHERE lr_pk = $'.count($param);
60  $row = $this->dbManager->getSingleRow($sql, $param, $stmt);
61  $vars = $row ?: [];
62  } else {
63  $stmt = __METHOD__;
64  $sql .= ' ORDER BY lr_pk';
65  $vars = $this->dbManager->getRows($sql, $param, $stmt);
66  }
67  $rules = [];
68  $rules["default"] = $this->compatibilityDao->getDefaultCompatibility();
69  $rules["rules"] = $vars;
70  return yaml_emit($rules);
71  }
72 }
Helper class to export license list as a YAML from the DB.
__construct(DbManager $dbManager, CompatibilityDao $compatibilityDao)
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16
Utility functions for specific applications.