Skip to content

Commit

Permalink
Merge pull request #480 from wintercms/main
Browse files Browse the repository at this point in the history
Add installers for Winter CMS (https://github.com/wintercms/)
  • Loading branch information
Seldaek authored Mar 8, 2021
2 parents 98b34f8 + aaea2ec commit 1b94b41
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ is not needed to install packages with these frameworks:
| Vanilla | `vanilla-plugin`<br>`vanilla-theme`
| Vgmcp | `vgmcp-bundle`<br>`vgmcp-theme`
| WHMCS | `whmcs-addons`<br>`whmcs-fraud`<br>`whmcs-gateways`<br>`whmcs-notifications`<br>`whmcs-registrars`<br>`whmcs-reports`<br>`whmcs-security`<br>`whmcs-servers`<br>`whmcs-social`<br>`whmcs-support`<br>`whmcs-templates`<br>`whmcs-includes`
| Winter CMS | **`winter-module`<br>`winter-plugin`<br>`winter-theme`**
| Wolf CMS | `wolfcms-plugin`
| WordPress | <b>`wordpress-plugin`<br>`wordpress-theme`</b><br>`wordpress-muplugin`<br>`wordpress-dropin`
| YAWIK | `yawik-module`
Expand Down
3 changes: 2 additions & 1 deletion src/Composer/Installers/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Installer extends LibraryInstaller
'october' => 'OctoberInstaller',
'ontowiki' => 'OntoWikiInstaller',
'oxid' => 'OxidInstaller',
'osclass' => 'OsclassInstaller',
'osclass' => 'OsclassInstaller',
'pxcms' => 'PxcmsInstaller',
'phpbb' => 'PhpBBInstaller',
'pimcore' => 'PimcoreInstaller',
Expand Down Expand Up @@ -110,6 +110,7 @@ class Installer extends LibraryInstaller
'userfrosting' => 'UserFrostingInstaller',
'vanilla' => 'VanillaInstaller',
'whmcs' => 'WHMCSInstaller',
'winter' => 'WinterInstaller',
'wolfcms' => 'WolfCMSInstaller',
'wordpress' => 'WordPressInstaller',
'yawik' => 'YawikInstaller',
Expand Down
47 changes: 47 additions & 0 deletions src/Composer/Installers/WinterInstaller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
namespace Composer\Installers;

class WinterInstaller extends BaseInstaller
{
protected $locations = array(
'module' => 'modules/{$name}/',
'plugin' => 'plugins/{$vendor}/{$name}/',
'theme' => 'themes/{$name}/'
);

/**
* Format package name.
*
* For package type winter-plugin, cut off a trailing '-plugin' if present.
*
* For package type winter-theme, cut off a trailing '-theme' if present.
*
*/
public function inflectPackageVars($vars)
{
if ($vars['type'] === 'winter-plugin') {
return $this->inflectPluginVars($vars);
}

if ($vars['type'] === 'winter-theme') {
return $this->inflectThemeVars($vars);
}

return $vars;
}

protected function inflectPluginVars($vars)
{
$vars['name'] = preg_replace('/^oc-|-plugin$/', '', $vars['name']);
$vars['vendor'] = preg_replace('/[^a-z0-9_]/i', '', $vars['vendor']);

return $vars;
}

protected function inflectThemeVars($vars)
{
$vars['name'] = preg_replace('/^oc-|-theme$/', '', $vars['name']);

return $vars;
}
}
89 changes: 89 additions & 0 deletions tests/Composer/Installers/Test/WinterInstallerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
namespace Composer\Installers\Test;

use Composer\Installers\WinterInstaller;
use Composer\Package\Package;
use Composer\Composer;
use PHPUnit\Framework\TestCase as BaseTestCase;

class WinterInstallerTest extends BaseTestCase
{
/**
* @var WinterInstaller
*/
private $installer;

public function setUp()
{
$this->installer = new WinterInstaller(
new Package('NyanCat', '4.2', '4.2'),
new Composer()
);
}

/**
* @dataProvider packageNameInflectionProvider
*/
public function testInflectPackageVars($type, $vendor, $name, $expectedVendor, $expectedName)
{
$this->assertEquals(
$this->installer->inflectPackageVars(array(
'vendor' => $vendor,
'name' => $name,
'type' => $type
)),
array('vendor' => $expectedVendor, 'name' => $expectedName, 'type' => $type)
);
}

public function packageNameInflectionProvider()
{
return array(
array(
'winter-plugin',
'acme',
'subpagelist',
'acme',
'subpagelist',
),
array(
'winter-plugin',
'acme',
'subpagelist-plugin',
'acme',
'subpagelist',
),
array(
'winter-plugin',
'acme',
'semanticwinter',
'acme',
'semanticwinter',
),
// tests vendor name containing a hyphen
array(
'winter-plugin',
'foo-bar-co',
'blog',
'foobarco',
'blog'
),
// tests that exactly one '-theme' is cut off
array(
'winter-theme',
'acme',
'some-theme-theme',
'acme',
'some-theme',
),
// tests that names without '-theme' suffix stay valid
array(
'winter-theme',
'acme',
'someothertheme',
'acme',
'someothertheme',
),
);
}
}

0 comments on commit 1b94b41

Please sign in to comment.