1
|
|
|
<?php |
2
|
|
|
namespace Composer\Installers; |
3
|
|
|
|
4
|
|
|
class PxcmsInstaller extends BaseInstaller |
5
|
|
|
{ |
6
|
|
|
protected $locations = array( |
7
|
|
|
'module' => 'app/Modules/{$name}/', |
8
|
|
|
'theme' => 'themes/{$name}/', |
9
|
|
|
); |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Format package name. |
13
|
|
|
* |
14
|
|
|
* @param array $vars |
15
|
|
|
* |
16
|
|
|
* @return array |
17
|
|
|
*/ |
18
|
|
|
public function inflectPackageVars($vars) |
19
|
|
|
{ |
20
|
|
|
if ($vars['type'] === 'pxcms-module') { |
21
|
|
|
return $this->inflectModuleVars($vars); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
if ($vars['type'] === 'pxcms-theme') { |
25
|
|
|
return $this->inflectThemeVars($vars); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
return $vars; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* For package type pxcms-module, cut off a trailing '-plugin' if present. |
33
|
|
|
* |
34
|
|
|
* return string |
35
|
|
|
*/ |
36
|
|
View Code Duplication |
protected function inflectModuleVars($vars) |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$vars['name'] = str_replace('pxcms-', '', $vars['name']); // strip out pxcms- just incase (legacy) |
39
|
|
|
$vars['name'] = str_replace('module-', '', $vars['name']); // strip out module- |
40
|
|
|
$vars['name'] = preg_replace('/-module$/', '', $vars['name']); // strip out -module |
41
|
|
|
$vars['name'] = str_replace('-', '_', $vars['name']); // make -'s be _'s |
42
|
|
|
$vars['name'] = ucwords($vars['name']); // make module name camelcased |
43
|
|
|
|
44
|
|
|
return $vars; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* For package type pxcms-module, cut off a trailing '-plugin' if present. |
50
|
|
|
* |
51
|
|
|
* return string |
52
|
|
|
*/ |
53
|
|
View Code Duplication |
protected function inflectThemeVars($vars) |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
$vars['name'] = str_replace('pxcms-', '', $vars['name']); // strip out pxcms- just incase (legacy) |
56
|
|
|
$vars['name'] = str_replace('theme-', '', $vars['name']); // strip out theme- |
57
|
|
|
$vars['name'] = preg_replace('/-theme$/', '', $vars['name']); // strip out -theme |
58
|
|
|
$vars['name'] = str_replace('-', '_', $vars['name']); // make -'s be _'s |
59
|
|
|
$vars['name'] = ucwords($vars['name']); // make module name camelcased |
60
|
|
|
|
61
|
|
|
return $vars; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.