forked from composer/installers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TastyIgniterInstaller.php
85 lines (70 loc) · 2.37 KB
/
TastyIgniterInstaller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
namespace Composer\Installers;
class TastyIgniterInstaller extends BaseInstaller
{
/** @var array<string, string> */
protected $locations = [
'module' => 'app/{$name}/',
'extension' => 'extensions/{$vendor}/{$name}/',
'theme' => 'themes/{$name}/',
];
/**
* Format package name.
*
* Cut off leading 'ti-ext-' or 'ti-theme-' if present.
* Strip vendor name of characters that is not alphanumeric or an underscore
*
*/
public function inflectPackageVars(array $vars): array
{
$extra = $this->composer->getPackage()->getExtra();
if ($vars['type'] === 'tastyigniter-module') {
return $this->inflectModuleVars($vars);
}
if ($vars['type'] === 'tastyigniter-extension') {
return $this->inflectExtensionVars($vars, $extra);
}
if ($vars['type'] === 'tastyigniter-theme') {
return $this->inflectThemeVars($vars, $extra);
}
return $vars;
}
/**
* @param array<string, string> $vars
* @return array<string, string>
*/
protected function inflectModuleVars(array $vars): array
{
$vars['name'] = $this->pregReplace('/^ti-module-/', '', $vars['name']);
return $vars;
}
/**
* @param array<string, string> $vars
* @param array<string, mixed> $extra
* @return array<string, string>
*/
protected function inflectExtensionVars(array $vars, array $extra): array
{
if (!empty($extra['tastyigniter-extension']['code'])) {
$parts = explode('.', $extra['tastyigniter-extension']['code']);
$vars['vendor'] = (string)$parts[0];
$vars['name'] = (string)($parts[1] ?? '');
}
$vars['vendor'] = $this->pregReplace('/[^a-z0-9_]/i', '', $vars['vendor']);
$vars['name'] = $this->pregReplace('/^ti-ext-/', '', $vars['name']);
return $vars;
}
/**
* @param array<string, string> $vars
* @param array<string, mixed> $extra
* @return array<string, string>
*/
protected function inflectThemeVars(array $vars, array $extra): array
{
if (!empty($extra['tastyigniter-theme']['code'])) {
$vars['name'] = $extra['tastyigniter-theme']['code'];
}
$vars['name'] = $this->pregReplace('/^ti-theme-/', '', $vars['name']);
return $vars;
}
}