1
|
|
|
<?php namespace Packedge\Workbench\Generators; |
2
|
|
|
|
3
|
|
|
use Illuminate\Filesystem\Filesystem; |
4
|
|
|
use Mustache_Engine; |
5
|
|
|
|
6
|
|
|
class LicenceGenerator extends BaseGenerator implements GeneratorInterface |
7
|
|
|
{ |
8
|
|
|
/* |
9
|
|
|
* Composer Ids |
10
|
|
|
* https://github.com/composer/composer/blob/master/res/spdx-identifier.json |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var array |
16
|
|
|
*/ |
17
|
|
|
protected static $licences = [ |
18
|
|
|
'MIT' => [ 'file' => 'MIT.txt', 'human' => 'MIT'], |
19
|
|
|
'Apache-2.0' => [ 'file' => 'Apache-2-0.txt', 'human' => 'Apache 2.0'], |
20
|
|
|
'GPL-3' => [ 'file' => 'GPL-3.txt', 'human' => 'GNU GPL v3.0'], |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $type = 'MIT'; |
28
|
|
|
|
29
|
21 |
|
public function __construct(Filesystem $filesystem = null, Mustache_Engine $mustache = null) |
30
|
|
|
{ |
31
|
21 |
|
parent::__construct($filesystem, $mustache); |
32
|
21 |
|
$this->outputPath = 'LICENSE'; |
33
|
21 |
|
} |
34
|
|
|
|
35
|
|
|
public static function showList() |
36
|
|
|
{ |
37
|
3 |
|
$data = array_map(function($item){ |
38
|
3 |
|
return $item['human']; |
39
|
3 |
|
}, static::$licences); |
40
|
|
|
|
41
|
3 |
|
return array_flip($data); |
42
|
|
|
} |
43
|
|
|
|
44
|
6 |
|
public static function getLicenceName($key) |
45
|
|
|
{ |
46
|
6 |
|
if(!array_key_exists($key, static::$licences)) throw new \InvalidArgumentException("Licence $key not found."); |
47
|
3 |
|
return static::$licences[$key]['human']; |
48
|
|
|
} |
49
|
|
|
|
50
|
6 |
|
public function setType($name) |
51
|
|
|
{ |
52
|
6 |
|
if(!array_key_exists($name, static::$licences)) throw new \InvalidArgumentException("Licence $name not found."); |
53
|
3 |
|
$this->type = $name; |
54
|
3 |
|
} |
55
|
|
|
|
56
|
3 |
|
public function create($packagePath) |
57
|
|
|
{ |
58
|
3 |
|
$this->templatePath = 'licences/' . static::$licences[$this->type]['file']; |
59
|
3 |
|
parent::create($packagePath); |
60
|
|
|
} |
61
|
|
|
} |