Skip to content

Commit dc80dca

Browse files
Merge pull request #352 from VGMCP/vgmcp
Added support of 'vgmcp-bundle' and 'vgmcp-theme'
2 parents fda8fe5 + f0bf797 commit dc80dca

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ is not needed to install packages with these frameworks:
9999
| TYPO3 Flow | `typo3-flow-package`<br>`typo3-flow-framework`<br>`typo3-flow-plugin`<br>`typo3-flow-site`<br>`typo3-flow-boilerplate`<br>`typo3-flow-build`
100100
| TYPO3 CMS | `typo3-cms-extension` (Deprecated in this package, use the [TYPO3 CMS Installers](https://packagist.org/packages/typo3/cms-composer-installers) instead)
101101
| Vanilla | `vanilla-plugin`<br>`vanilla-theme`
102+
| Vgmcp | `vgmcp-bundle`<br>`vgmcp-theme`
102103
| Wolf CMS | `wolfcms-plugin`
103104
| WordPress | <b>`wordpress-plugin`<br>`wordpress-theme`</b><br>`wordpress-muplugin`
104105
| YAWIK | `yawik-module`
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
namespace Composer\Installers;
3+
4+
class VgmcpInstaller extends BaseInstaller
5+
{
6+
protected $locations = array(
7+
'bundle' => 'src/{$vendor}/{$name}/',
8+
'theme' => 'themes/{$name}/'
9+
);
10+
11+
/**
12+
* Format package name.
13+
*
14+
* For package type vgmcp-bundle, cut off a trailing '-bundle' if present.
15+
*
16+
* For package type vgmcp-theme, cut off a trailing '-theme' if present.
17+
*
18+
*/
19+
public function inflectPackageVars($vars)
20+
{
21+
if ($vars['type'] === 'vgmcp-bundle') {
22+
return $this->inflectPluginVars($vars);
23+
}
24+
25+
if ($vars['type'] === 'vgmcp-theme') {
26+
return $this->inflectThemeVars($vars);
27+
}
28+
29+
return $vars;
30+
}
31+
32+
protected function inflectPluginVars($vars)
33+
{
34+
$vars['name'] = preg_replace('/-bundle$/', '', $vars['name']);
35+
$vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']);
36+
$vars['name'] = str_replace(' ', '', ucwords($vars['name']));
37+
38+
return $vars;
39+
}
40+
41+
protected function inflectThemeVars($vars)
42+
{
43+
$vars['name'] = preg_replace('/-theme$/', '', $vars['name']);
44+
$vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']);
45+
$vars['name'] = str_replace(' ', '', ucwords($vars['name']));
46+
47+
return $vars;
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
namespace Composer\Installers\Test;
3+
4+
use Composer\Installers\VgmcpInstaller;
5+
use Composer\Package\Package;
6+
use Composer\Composer;
7+
8+
class VgmcpInstallerTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var VgmcpInstaller
12+
*/
13+
private $installer;
14+
15+
public function setUp()
16+
{
17+
$this->installer = new VgmcpInstaller(
18+
new Package('NyanCat', '4.2', '4.2'),
19+
new Composer()
20+
);
21+
}
22+
23+
/**
24+
* @dataProvider packageNameInflectionProvider
25+
*/
26+
public function testInflectPackageVars($type, $name, $expected)
27+
{
28+
$this->assertEquals(
29+
array('name' => $expected, 'type' => $type),
30+
$this->installer->inflectPackageVars(array('name' => $name, 'type' => $type))
31+
);
32+
}
33+
34+
public function packageNameInflectionProvider()
35+
{
36+
return array(
37+
// Should keep bundle name StudlyCase
38+
array(
39+
'vgmcp-bundle',
40+
'user-profile',
41+
'UserProfile'
42+
),
43+
array(
44+
'vgmcp-bundle',
45+
'vgmcp-bundle',
46+
'Vgmcp'
47+
),
48+
array(
49+
'vgmcp-bundle',
50+
'blog',
51+
'Blog'
52+
),
53+
// tests that exactly one '-bundle' is cut off
54+
array(
55+
'vgmcp-bundle',
56+
'some-bundle-bundle',
57+
'SomeBundle',
58+
),
59+
// tests that exactly one '-theme' is cut off
60+
array(
61+
'vgmcp-theme',
62+
'some-theme-theme',
63+
'SomeTheme',
64+
),
65+
// tests that names without '-theme' suffix stay valid
66+
array(
67+
'vgmcp-theme',
68+
'someothertheme',
69+
'Someothertheme',
70+
),
71+
// Should keep theme name StudlyCase
72+
array(
73+
'vgmcp-theme',
74+
'adminlte-advanced',
75+
'AdminlteAdvanced'
76+
),
77+
);
78+
}
79+
}

0 commit comments

Comments
 (0)