44
55class MicroweberInstaller extends BaseInstaller
66{
7+ /** @var array<string, string> */
78 /** @var array<string, string> */
89 protected $ locations = array (
9- 'module ' => 'userfiles/modules/{$install_item_dir}/ ' ,
10- 'module-skin ' => 'userfiles/modules/{$install_item_dir}/templates/ ' ,
11- 'template ' => 'userfiles/templates/{$install_item_dir}/ ' ,
12- 'element ' => 'userfiles/elements/{$install_item_dir}/ ' ,
13- 'vendor ' => 'vendor/{$install_item_dir}/ ' ,
14- 'components ' => 'components/{$install_item_dir}/ '
10+ 'module ' => 'Modules/{$target_dir}/ ' ,
11+ 'template ' => 'Templates/{$target_dir}/ '
1512 );
1613
1714 /**
1815 * Format package name.
1916 *
20- * For package type microweber-module, cut off a trailing '-module ' if present
17+ * For package type microweber-module, cut off a trailing '-plugin ' if present.
2118 *
2219 * For package type microweber-template, cut off a trailing '-template' if present.
2320 */
2421 public function inflectPackageVars (array $ vars ): array
2522 {
26- if ($ this ->package ->getTargetDir () !== null && $ this ->package ->getTargetDir () !== '' ) {
27- $ vars ['install_item_dir ' ] = $ this ->package ->getTargetDir ();
28- } else {
29- $ vars ['install_item_dir ' ] = $ vars ['name ' ];
30- if ($ vars ['type ' ] === 'microweber-template ' ) {
31- return $ this ->inflectTemplateVars ($ vars );
32- }
33- if ($ vars ['type ' ] === 'microweber-templates ' ) {
34- return $ this ->inflectTemplatesVars ($ vars );
35- }
36- if ($ vars ['type ' ] === 'microweber-core ' ) {
37- return $ this ->inflectCoreVars ($ vars );
38- }
39- if ($ vars ['type ' ] === 'microweber-adapter ' ) {
40- return $ this ->inflectCoreVars ($ vars );
41- }
42- if ($ vars ['type ' ] === 'microweber-module ' ) {
43- return $ this ->inflectModuleVars ($ vars );
44- }
45- if ($ vars ['type ' ] === 'microweber-modules ' ) {
46- return $ this ->inflectModulesVars ($ vars );
47- }
48- if ($ vars ['type ' ] === 'microweber-skin ' ) {
49- return $ this ->inflectSkinVars ($ vars );
50- }
51- if ($ vars ['type ' ] === 'microweber-element ' or $ vars ['type ' ] === 'microweber-elements ' ) {
52- return $ this ->inflectElementVars ($ vars );
53- }
54- }
5523
56- return $ vars ;
57- }
58-
59- /**
60- * @param array<string, string> $vars
61- * @return array<string, string>
62- */
63- protected function inflectTemplateVars (array $ vars ): array
64- {
65- $ vars ['install_item_dir ' ] = $ this ->pregReplace ('/-template$/ ' , '' , $ vars ['install_item_dir ' ]);
66- $ vars ['install_item_dir ' ] = $ this ->pregReplace ('/template-$/ ' , '' , $ vars ['install_item_dir ' ]);
67-
68- return $ vars ;
69- }
70-
71- /**
72- * @param array<string, string> $vars
73- * @return array<string, string>
74- */
75- protected function inflectTemplatesVars (array $ vars ): array
76- {
77- $ vars ['install_item_dir ' ] = $ this ->pregReplace ('/-templates$/ ' , '' , $ vars ['install_item_dir ' ]);
78- $ vars ['install_item_dir ' ] = $ this ->pregReplace ('/templates-$/ ' , '' , $ vars ['install_item_dir ' ]);
79-
80- return $ vars ;
81- }
82-
83- /**
84- * @param array<string, string> $vars
85- * @return array<string, string>
86- */
87- protected function inflectCoreVars (array $ vars ): array
88- {
89- $ vars ['install_item_dir ' ] = $ this ->pregReplace ('/-providers$/ ' , '' , $ vars ['install_item_dir ' ]);
90- $ vars ['install_item_dir ' ] = $ this ->pregReplace ('/-provider$/ ' , '' , $ vars ['install_item_dir ' ]);
91- $ vars ['install_item_dir ' ] = $ this ->pregReplace ('/-adapter$/ ' , '' , $ vars ['install_item_dir ' ]);
24+ $ target_dir = $ this ->package ->getTargetDir ();
25+ if ($ target_dir ) {
26+ $ vars ['target_dir ' ] = $ target_dir ;
27+ }
28+ if ($ vars ['type ' ] === 'microweber-module ' ) {
29+ return $ this ->inflectModuleVars ($ vars );
30+ }
31+ if ($ vars ['type ' ] === 'microweber-template ' ) {
32+ return $ this ->inflectThemeVars ($ vars );
33+ }
9234
9335 return $ vars ;
9436 }
@@ -99,46 +41,31 @@ protected function inflectCoreVars(array $vars): array
9941 */
10042 protected function inflectModuleVars (array $ vars ): array
10143 {
102- $ vars ['install_item_dir ' ] = $ this ->pregReplace ('/-module$/ ' , '' , $ vars ['install_item_dir ' ]);
103- $ vars ['install_item_dir ' ] = $ this ->pregReplace ('/module-$/ ' , '' , $ vars ['install_item_dir ' ]);
104-
105- return $ vars ;
106- }
107-
108- /**
109- * @param array<string, string> $vars
110- * @return array<string, string>
111- */
112- protected function inflectModulesVars (array $ vars ): array
113- {
114- $ vars ['install_item_dir ' ] = $ this ->pregReplace ('/-modules$/ ' , '' , $ vars ['install_item_dir ' ]);
115- $ vars ['install_item_dir ' ] = $ this ->pregReplace ('/modules-$/ ' , '' , $ vars ['install_item_dir ' ]);
116-
44+ if (isset ($ vars ['target_dir ' ]) and !empty ($ vars ['target_dir ' ])){
45+ return $ vars ;
46+ }
47+ $ vars ['name ' ] = $ this ->pregReplace ('/-module$/ ' , '' , $ vars ['name ' ]);
48+ $ vars ['name ' ] = str_replace (array ('- ' , '_ ' ), ' ' , $ vars ['name ' ]);
49+ $ vars ['name ' ] = str_replace (' ' , '' , ucwords ($ vars ['name ' ]));
50+ $ vars ['target_dir ' ] = $ vars ['name ' ];
11751 return $ vars ;
11852 }
11953
12054 /**
12155 * @param array<string, string> $vars
12256 * @return array<string, string>
12357 */
124- protected function inflectSkinVars (array $ vars ): array
58+ protected function inflectThemeVars (array $ vars ): array
12559 {
126- $ vars ['install_item_dir ' ] = $ this ->pregReplace ('/-skin$/ ' , '' , $ vars ['install_item_dir ' ]);
127- $ vars ['install_item_dir ' ] = $ this ->pregReplace ('/skin-$/ ' , '' , $ vars ['install_item_dir ' ]);
60+ if (isset ($ vars ['target_dir ' ]) and !empty ($ vars ['target_dir ' ])){
61+ return $ vars ;
62+ }
12863
129- return $ vars ;
130- }
13164
132- /**
133- * @param array<string, string> $vars
134- * @return array<string, string>
135- */
136- protected function inflectElementVars (array $ vars ): array
137- {
138- $ vars ['install_item_dir ' ] = $ this ->pregReplace ('/-elements$/ ' , '' , $ vars ['install_item_dir ' ]);
139- $ vars ['install_item_dir ' ] = $ this ->pregReplace ('/elements-$/ ' , '' , $ vars ['install_item_dir ' ]);
140- $ vars ['install_item_dir ' ] = $ this ->pregReplace ('/-element$/ ' , '' , $ vars ['install_item_dir ' ]);
141- $ vars ['install_item_dir ' ] = $ this ->pregReplace ('/element-$/ ' , '' , $ vars ['install_item_dir ' ]);
65+ $ vars ['name ' ] = $ this ->pregReplace ('/-template$/ ' , '' , $ vars ['name ' ]);
66+ $ vars ['name ' ] = str_replace (array ('- ' , '_ ' ), ' ' , $ vars ['name ' ]);
67+ $ vars ['name ' ] = str_replace (' ' , '' , ucwords ($ vars ['name ' ]));
68+ $ vars ['target_dir ' ] = $ vars ['name ' ];
14269
14370 return $ vars ;
14471 }
0 commit comments