-
-
Notifications
You must be signed in to change notification settings - Fork 404
Expand file tree
/
Copy pathMicroweberInstaller.php
More file actions
72 lines (62 loc) · 2.08 KB
/
MicroweberInstaller.php
File metadata and controls
72 lines (62 loc) · 2.08 KB
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
<?php
namespace Composer\Installers;
class MicroweberInstaller extends BaseInstaller
{
/** @var array<string, string> */
/** @var array<string, string> */
protected $locations = array(
'module' => 'Modules/{$target_dir}/',
'template' => 'Templates/{$target_dir}/'
);
/**
* Format package name.
*
* For package type microweber-module, cut off a trailing '-plugin' if present.
*
* For package type microweber-template, cut off a trailing '-template' if present.
*/
public function inflectPackageVars(array $vars): array
{
$target_dir = $this->package->getTargetDir();
if ($target_dir) {
$vars['target_dir'] = $target_dir;
}
if ($vars['type'] === 'microweber-module') {
return $this->inflectModuleVars($vars);
}
if ($vars['type'] === 'microweber-template') {
return $this->inflectThemeVars($vars);
}
return $vars;
}
/**
* @param array<string, string> $vars
* @return array<string, string>
*/
protected function inflectModuleVars(array $vars): array
{
if(isset($vars['target_dir']) and !empty($vars['target_dir'])){
return $vars;
}
$vars['name'] = $this->pregReplace('/-module$/', '', $vars['name']);
$vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']);
$vars['name'] = str_replace(' ', '', ucwords($vars['name']));
$vars['target_dir'] = $vars['name'];
return $vars;
}
/**
* @param array<string, string> $vars
* @return array<string, string>
*/
protected function inflectThemeVars(array $vars): array
{
if(isset($vars['target_dir']) and !empty($vars['target_dir'])){
return $vars;
}
$vars['name'] = $this->pregReplace('/-template$/', '', $vars['name']);
$vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']);
$vars['name'] = str_replace(' ', '', ucwords($vars['name']));
$vars['target_dir'] = $vars['name'];
return $vars;
}
}