YaWK  24.1
Yet another WebKit
YAWK\licenses Class Reference

License Generator Class. More...

Public Member Functions

 __construct ($license, $description, $year, $holder, $target)
 Licenses constructor create requested license for holder. More...
 
 checkFolder ()
 Check if target folder exists and is writeable. More...
 
 createLicenseText ()
 Create license text and save string as obj property. More...
 
 getLicenseText ()
 Create license text and return it as string (or false) More...
 
 writeLicenseFile ()
 Create license text and write it as LICENSE file to $this->target folder. More...
 

Public Attributes

 $description = ''
 
 $holder = ''
 
 $license = ''
 
 $licenseFilename = 'LICENSE'
 
 $licenseText = ''
 
 $target = ''
 
 $year = ''
 

Detailed Description

License Generator Class.

Class licenses This class serves methods to get any license returned as text or write it as LICENSE to given target folder. This is mainly used by the template system to add the correct license file if a .zip gets made from any template.

Author
Daniel Retzl danie.nosp@m.lret.nosp@m.zl@gm.nosp@m.ail..nosp@m.com
Version
1.0.0

Definition at line 16 of file licenses.php.

Constructor & Destructor Documentation

◆ __construct()

YAWK\licenses::__construct (   $license,
  $description,
  $year,
  $holder,
  $target 
)

Licenses constructor create requested license for holder.

Parameters
$licensestring the license that should be generated
$descriptionstring one line to give the program's name and a brief idea of what it does.
$yearstring year when it was licensed
$holderstring copyright holder this license belongs to
$targetstring folder where to write te template

Definition at line 41 of file licenses.php.

43  {
44  // check if license is set
45  if (isset($license) && (!empty($license) && (is_string($license))))
46  {
47  $this->license = $license;
48  }
49 
50  // check if license description (software description) is set
51  if (isset($description) && (!empty($description) && (is_string($description))))
52  {
53  $this->description = $description;
54  }
55 
56  // check if license year is set
57  if (isset($year) && (!empty($year) && (is_string($year))))
58  {
59  $this->year = $year;
60  }
61 
62  // check if license holder is set
63  if (isset($holder) && (!empty($holder) && (is_string($holder))))
64  {
65  $this->holder = $holder;
66  }
67 
68  // check if target is set
69  if (isset($target) && (!empty($target) && (is_string($target))))
70  {
71  $this->target = $target;
72  }
$blog description
Definition: blog-setup.php:49

References YAWK\licenses\$description, YAWK\licenses\$holder, YAWK\licenses\$license, YAWK\licenses\$target, YAWK\licenses\$year, and description.

Member Function Documentation

◆ checkFolder()

YAWK\licenses::checkFolder ( )

Check if target folder exists and is writeable.

Returns
bool true|false

Definition at line 327 of file licenses.php.

329  {
330  // check if target directory exists
331  if (is_dir(dirname($this->target)))
332  { // ok, check if target folder is writeable
333  if (is_writeable(dirname($this->target)))
334  { // all good,
335  return true;
336  }
337  else
338  { // todo: add syslog entry - target folder not writeable
339  return false;
340  }
341  }
342  else
343  { // target directory does not exist, try to create it
344  if (!mkdir(dirname($this->target)))
345  {
346  // todo: add syslog - failed to create license target folder
347  return false;
348  }
349  else
350  {
351  // target folder created
352  return true;
353  }
354  }

Referenced by YAWK\licenses\writeLicenseFile().

◆ createLicenseText()

YAWK\licenses::createLicenseText ( )

Create license text and save string as obj property.

Returns
bool

Definition at line 131 of file licenses.php.

133  {
134  // check if required obj properties are set
135  if (!isset($this->license) || (!isset($this->holder) || (!isset($this->year) ||(!isset($this->description)))
136  || (empty($this->license) || (empty($this->holder) || (empty($this->year) || (empty($this->description)))))))
137  { // if not
138  return false;
139  }
140 
141  // ok, check which license should be generated
142  switch ($this->license)
143  {
144  // MIT
145  case "MIT":
146  {
147  $this->licenseText = "
148  ".$this->description."
149  Copyright (C) ".$this->year." copyright ".$this->holder."
150  Permission is hereby granted, free of charge, to any person
151  obtaining a copy of this software and associated documentation
152  files (the \"Software\"), to deal in the Software without
153  restriction, including without limitation the rights to use,
154  copy, modify, merge, publish, distribute, sublicense, and/or
155  sell copies of the software, and to permit persons to whom
156  the software is furnished to do so, subject to the following
157  conditions:
158 
159  The above copyright notice and this permission notice shall
160  be included in all copies or substantial portions of the software.
161 
162  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,
163  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
164  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
165  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
166  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
167  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
168  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
169  OR OTHER DEALINGS IN THE SOFTWARE.";
170  return true;
171  }
172  break;
173 
174  // APACHE
175  case "APACHE2":
176  {
177  $this->licenseText = "
178  ".$this->description."
179  Copyright ".$this->year." ".$this->holder."
180 
181  Licensed under the Apache License, Version 2.0 (the \"License\");
182  you may not use this file except in compliance with the License.
183  You may obtain a copy of the License at
184 
185  http://www.apache.org/licenses/LICENSE-2.0
186 
187  Unless required by applicable law or agreed to in writing, software
188  distributed under the License is distributed on an \"AS IS\" BASIS,
189  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190  See the License for the specific language governing permissions and
191  limitations under the License.";
192  return true;
193  }
194  break;
195 
196  // GPL 2
197  case "GPL2":
198  {
199  $this->licenseText = "
200  ".$this->description."
201  Copyright (C) ".$this->year." ".$this->holder."
202 
203  This program is free software; you can redistribute it and/or
204  modify it under the terms of the GNU General Public License
205  as published by the Free Software Foundation; either version 2
206  of the License, or (at your option) any later version.
207 
208  This program is distributed in the hope that it will be useful,
209  but WITHOUT ANY WARRANTY; without even the implied warranty of
210  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
211  GNU General Public License for more details.
212 
213  You should have received a copy of the GNU General Public License
214  along with this program; if not, write to the Free Software
215  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.";
216  return true;
217  }
218  break;
219 
220  // GPL 3
221  case "GPL3":
222  {
223  $this->licenseText = "
224  ".$this->description."
225  Copyright (C) ".$this->year." ".$this->holder."
226  This program is free software: you can redistribute it and/or modify
227  it under the terms of the GNU General Public License as published by
228  the Free Software Foundation, either version 3 of the License, or
229  (at your option) any later version.
230 
231  This program is distributed in the hope that it will be useful,
232  but WITHOUT ANY WARRANTY; without even the implied warranty of
233  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
234  GNU General Public License for more details.
235 
236  You should have received a copy of the GNU General Public License
237  along with this program. If not, see <https://www.gnu.org/licenses/>.
238  ";
239  return true;
240  }
241  break;
242 
243  // LGPL 2
244  case "Lesser GPL 2.0":
245  {
246  $this->licenseText = "
247  ".$this->description."
248  Copyright (C) ".$this->year." ".$this->holder."
249 
250  This library is free software; you can redistribute it and/or
251  modify it under the terms of the GNU Library General Public
252  License as published by the Free Software Foundation; either
253  version 2 of the License, or (at your option) any later version.
254 
255  This library is distributed in the hope that it will be useful,
256  but WITHOUT ANY WARRANTY; without even the implied warranty of
257  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
258  Library General Public License for more details.
259 
260  You should have received a copy of the GNU Library General Public
261  License along with this library; if not, write to the
262  Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
263  Boston, MA 02110-1301, USA.";
264  return true;
265  }
266  break;
267 
268  // LGPL 2.1
269  case "Lesser GPL 2.1":
270  {
271  $this->licenseText = "
272  ".$this->description."
273  Copyright (C) ".$this->year." ".$this->holder."
274 
275  This library is free software; you can redistribute it and/or
276  modify it under the terms of the GNU Lesser General Public
277  License as published by the Free Software Foundation; either
278  version 2.1 of the License, or (at your option) any later version.
279 
280  This library is distributed in the hope that it will be useful,
281  but WITHOUT ANY WARRANTY; without even the implied warranty of
282  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
283  Lesser General Public License for more details.
284 
285  You should have received a copy of the GNU Lesser General Public
286  License along with this library; if not, write to the Free Software
287  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA";
288  return true;
289  }
290  break;
291 
292  // DEFAULT: MIT
293  default:
294  {
295  $this->licenseText = "
296  ".$this->description."
297  Copyright (C) ".$this->year." copyright ".$this->holder."
298  Permission is hereby granted, free of charge, to any person
299  obtaining a copy of this software and associated documentation
300  files (the \"Software\"), to deal in the Software without
301  restriction, including without limitation the rights to use,
302  copy, modify, merge, publish, distribute, sublicense, and/or
303  sell copies of the software, and to permit persons to whom
304  the software is furnished to do so, subject to the following
305  conditions:
306 
307  The above copyright notice and this permission notice shall
308  be included in all copies or substantial portions of the software.
309 
310  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,
311  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
312  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
313  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
314  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
315  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
316  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
317  OR OTHER DEALINGS IN THE SOFTWARE.";
318  return true;
319  }
320  break;
321  }

References description.

Referenced by YAWK\licenses\getLicenseText(), and YAWK\licenses\writeLicenseFile().

◆ getLicenseText()

YAWK\licenses::getLicenseText ( )

Create license text and return it as string (or false)

Returns
string|false

Definition at line 78 of file licenses.php.

80  {
81  // create and return license
82  if ($this->createLicenseText() === false)
83  { // license text creation failed (this should be unable to happen...)
84  return false;
85  }
86 
87  // check if license text is set and not empty
88  if (isset($this->licenseText) && (!empty($this->licenseText)))
89  { // license set, return as string
90  return $this->licenseText;
91  }
92  else
93  { // license text not set or empty
94  return false;
95  }
createLicenseText()
Create license text and save string as obj property.
Definition: licenses.php:131

References YAWK\licenses\$licenseText, and YAWK\licenses\createLicenseText().

◆ writeLicenseFile()

YAWK\licenses::writeLicenseFile ( )

Create license text and write it as LICENSE file to $this->target folder.

Returns
bool

Definition at line 101 of file licenses.php.

103  {
104  // create and return license
105  if ($this->createLicenseText() === false)
106  { // license text creation failed (this should be unable to happen...)
107  return false;
108  }
109 
110  if ($this->checkFolder() === false)
111  { // check folder not writeable!
112  return false;
113  }
114  else
115  { // write license file to target
116  if (!file_put_contents($this->target.$this->licenseFilename, $this->licenseText))
117  { // failed to write license file to target folder
118  // todo: add syslog - failed to write LICENSE to target folder
119  return false;
120  }
121  else
122  { // LICENSE file successfully written to target folder
123  return true;
124  }
125  }
checkFolder()
Check if target folder exists and is writeable.
Definition: licenses.php:327

References YAWK\licenses\checkFolder(), and YAWK\licenses\createLicenseText().

Member Data Documentation

◆ $description

YAWK\licenses::$description = ''
Parameters
stringpackage description

Definition at line 21 of file licenses.php.

Referenced by YAWK\licenses\__construct().

◆ $holder

YAWK\licenses::$holder = ''
Parameters
stringlicense holder (name)

Definition at line 25 of file licenses.php.

Referenced by YAWK\licenses\__construct().

◆ $license

YAWK\licenses::$license = ''
Parameters
stringcurrent license to work with

Definition at line 19 of file licenses.php.

Referenced by YAWK\licenses\__construct().

◆ $licenseFilename

YAWK\licenses::$licenseFilename = 'LICENSE'
Parameters
stringLICENSE filename (used by $this->writeLicenseFile)

Definition at line 31 of file licenses.php.

◆ $licenseText

YAWK\licenses::$licenseText = ''
Parameters
stringcurrent license text

Definition at line 29 of file licenses.php.

Referenced by YAWK\licenses\getLicenseText().

◆ $target

YAWK\licenses::$target = ''
Parameters
stringtarget folder to write the LICENSE file

Definition at line 27 of file licenses.php.

Referenced by YAWK\licenses\__construct().

◆ $year

YAWK\licenses::$year = ''
Parameters
stringcopyright year

Definition at line 23 of file licenses.php.

Referenced by YAWK\licenses\__construct().


The documentation for this class was generated from the following file: