Skip to content

Update for Microweber v3 #548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 29 additions & 102 deletions src/Composer/Installers/MicroweberInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,91 +4,33 @@

class MicroweberInstaller extends BaseInstaller
{
/** @var array<string, string> */
/** @var array<string, string> */
protected $locations = array(
'module' => 'userfiles/modules/{$install_item_dir}/',
'module-skin' => 'userfiles/modules/{$install_item_dir}/templates/',
'template' => 'userfiles/templates/{$install_item_dir}/',
'element' => 'userfiles/elements/{$install_item_dir}/',
'vendor' => 'vendor/{$install_item_dir}/',
'components' => 'components/{$install_item_dir}/'
'module' => 'Modules/{$target_dir}/',
'template' => 'Templates/{$target_dir}/'
);

/**
* Format package name.
*
* For package type microweber-module, cut off a trailing '-module' if present
* 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
{
if ($this->package->getTargetDir() !== null && $this->package->getTargetDir() !== '') {
$vars['install_item_dir'] = $this->package->getTargetDir();
} else {
$vars['install_item_dir'] = $vars['name'];
if ($vars['type'] === 'microweber-template') {
return $this->inflectTemplateVars($vars);
}
if ($vars['type'] === 'microweber-templates') {
return $this->inflectTemplatesVars($vars);
}
if ($vars['type'] === 'microweber-core') {
return $this->inflectCoreVars($vars);
}
if ($vars['type'] === 'microweber-adapter') {
return $this->inflectCoreVars($vars);
}
if ($vars['type'] === 'microweber-module') {
return $this->inflectModuleVars($vars);
}
if ($vars['type'] === 'microweber-modules') {
return $this->inflectModulesVars($vars);
}
if ($vars['type'] === 'microweber-skin') {
return $this->inflectSkinVars($vars);
}
if ($vars['type'] === 'microweber-element' or $vars['type'] === 'microweber-elements') {
return $this->inflectElementVars($vars);
}
}

return $vars;
}

/**
* @param array<string, string> $vars
* @return array<string, string>
*/
protected function inflectTemplateVars(array $vars): array
{
$vars['install_item_dir'] = $this->pregReplace('/-template$/', '', $vars['install_item_dir']);
$vars['install_item_dir'] = $this->pregReplace('/template-$/', '', $vars['install_item_dir']);

return $vars;
}

/**
* @param array<string, string> $vars
* @return array<string, string>
*/
protected function inflectTemplatesVars(array $vars): array
{
$vars['install_item_dir'] = $this->pregReplace('/-templates$/', '', $vars['install_item_dir']);
$vars['install_item_dir'] = $this->pregReplace('/templates-$/', '', $vars['install_item_dir']);

return $vars;
}

/**
* @param array<string, string> $vars
* @return array<string, string>
*/
protected function inflectCoreVars(array $vars): array
{
$vars['install_item_dir'] = $this->pregReplace('/-providers$/', '', $vars['install_item_dir']);
$vars['install_item_dir'] = $this->pregReplace('/-provider$/', '', $vars['install_item_dir']);
$vars['install_item_dir'] = $this->pregReplace('/-adapter$/', '', $vars['install_item_dir']);
$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;
}
Expand All @@ -99,46 +41,31 @@ protected function inflectCoreVars(array $vars): array
*/
protected function inflectModuleVars(array $vars): array
{
$vars['install_item_dir'] = $this->pregReplace('/-module$/', '', $vars['install_item_dir']);
$vars['install_item_dir'] = $this->pregReplace('/module-$/', '', $vars['install_item_dir']);

return $vars;
}

/**
* @param array<string, string> $vars
* @return array<string, string>
*/
protected function inflectModulesVars(array $vars): array
{
$vars['install_item_dir'] = $this->pregReplace('/-modules$/', '', $vars['install_item_dir']);
$vars['install_item_dir'] = $this->pregReplace('/modules-$/', '', $vars['install_item_dir']);

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 inflectSkinVars(array $vars): array
protected function inflectThemeVars(array $vars): array
{
$vars['install_item_dir'] = $this->pregReplace('/-skin$/', '', $vars['install_item_dir']);
$vars['install_item_dir'] = $this->pregReplace('/skin-$/', '', $vars['install_item_dir']);
if(isset($vars['target_dir']) and !empty($vars['target_dir'])){
return $vars;
}

return $vars;
}

/**
* @param array<string, string> $vars
* @return array<string, string>
*/
protected function inflectElementVars(array $vars): array
{
$vars['install_item_dir'] = $this->pregReplace('/-elements$/', '', $vars['install_item_dir']);
$vars['install_item_dir'] = $this->pregReplace('/elements-$/', '', $vars['install_item_dir']);
$vars['install_item_dir'] = $this->pregReplace('/-element$/', '', $vars['install_item_dir']);
$vars['install_item_dir'] = $this->pregReplace('/element-$/', '', $vars['install_item_dir']);
$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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Composer/Installers/Test/InstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public function installPathProvider(): array
array('miaoxing-plugin', 'plugins/my-plugin/', 'shama/my-plugin'),
array('miaoxing-plugin', 'plugins/MyPlugin/', 'shama/MyPlugin'),
array('miaoxing-plugin', 'plugins/my_plugin/', 'shama/my_plugin'),
array('microweber-module', 'userfiles/modules/my-thing/', 'author/my-thing-module'),
array('microweber-module', 'Modules/MyThing/', 'author/my-thing-module'),
array('modulework-module', 'modules/my_package/', 'shama/my_package'),
array('moodle-mod', 'mod/my_package/', 'shama/my_package'),
array('october-module', 'modules/my_plugin/', 'shama/my_plugin'),
Expand Down