-
-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #480 from wintercms/main
Add installers for Winter CMS (https://github.com/wintercms/)
- Loading branch information
Showing
4 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
), | ||
); | ||
} | ||
} |