|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace generators\Readme; |
|
4
|
|
|
|
|
5
|
|
|
use Config; |
|
6
|
|
|
use mediators\AbstractMediator; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @property string FILENAME |
|
10
|
|
|
* @property string $content |
|
11
|
|
|
* @property Config $config |
|
12
|
|
|
*/ |
|
13
|
|
|
final class ReadmeGenerator extends \generators\AbstractGenerator |
|
14
|
|
|
{ |
|
15
|
|
|
const FILENAME = 'app/addons/${addon}/README.md'; |
|
16
|
|
|
private $templatePath = ROOT_DIR . '/resources/README.md'; |
|
17
|
|
|
private $content = ''; |
|
18
|
|
|
private $config; |
|
19
|
|
|
private $mediator; |
|
20
|
|
|
|
|
21
|
|
|
function __construct(Config $config) |
|
22
|
|
|
{ |
|
23
|
|
|
$this->config = $config; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @inheritdoc |
|
28
|
|
|
*/ |
|
29
|
|
|
public function getTemplateFilename(): string |
|
30
|
|
|
{ |
|
31
|
|
|
return sanitize_filename($this->templatePath); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function setMediator(AbstractMediator $mediator): void |
|
35
|
|
|
{ |
|
36
|
|
|
$this->mediator = $mediator; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @inheritdoc |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getPath(): string |
|
43
|
|
|
{ |
|
44
|
|
|
$addon_id = $this->config->get('addon.id'); |
|
45
|
|
|
|
|
46
|
|
|
if (!$addon_id) { |
|
47
|
|
|
throw new \InvalidArgumentException('Addon id (name) not specified'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$path = $this->config->get('filesystem.output_path') |
|
51
|
|
|
. str_replace('${addon}', $addon_id, static::FILENAME); |
|
52
|
|
|
|
|
53
|
|
|
return sanitize_filename($path); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @inheritdoc |
|
58
|
|
|
* |
|
59
|
|
|
* @return LanguageGenerator |
|
|
|
|
|
|
60
|
|
|
*/ |
|
61
|
|
|
public function setContent(string $content) |
|
62
|
|
|
{ |
|
63
|
|
|
$this->content = $content; |
|
64
|
|
|
|
|
65
|
|
|
return $this; |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Replace placeholders by real data |
|
70
|
|
|
* @param string $content |
|
71
|
|
|
* |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
|
|
public static function substituteData(string $content, array $data): string |
|
75
|
|
|
{ |
|
76
|
|
|
return str_replace( |
|
77
|
|
|
[ |
|
78
|
|
|
'${addon.id}', |
|
79
|
|
|
'${developer.company}', |
|
80
|
|
|
'${developer.name}', |
|
81
|
|
|
], |
|
82
|
|
|
$data, |
|
83
|
|
|
$content |
|
84
|
|
|
); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @inheritdoc |
|
89
|
|
|
*/ |
|
90
|
|
|
public function toString(): string |
|
91
|
|
|
{ |
|
92
|
|
|
return self::substituteData($this->content, [ |
|
93
|
|
|
parse_to_readable($this->config->get('addon.id')), |
|
94
|
|
|
$this->config->get('developer.company'), |
|
95
|
|
|
$this->config->get('developer.name') |
|
96
|
|
|
]); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths