Skip to content

Commit 844fcbc

Browse files
authored
Update MauticInstaller to allow plugins & themes (#484)
* Update MauticInstaller to allow plugins & themes with custom directory names Update MauticInstaller to allow plugins & themes with custom directory names - Please do not merge yet * Update MauticInstaller.php * Update README.md * Update MauticInstaller.php * Adding mautic composer installer tests * Fixing tests and making it compatible with PHP 5.3
1 parent 0f4a400 commit 844fcbc

File tree

3 files changed

+146
-7
lines changed

3 files changed

+146
-7
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ is not needed to install packages with these frameworks:
7878
| majima | `majima-plugin`
7979
| Mako | `mako-package`
8080
| MantisBT | `mantisbt-plugin`
81-
| Mautic | `mautic-plugin`<br>`mautic-theme`
81+
| Mautic | `mautic-core`<br>`mautic-plugin`<br>`mautic-theme`
8282
| Maya | `maya-module`
8383
| MODX | `modx-extra`
8484
| MODX Evo | `modxevo-snippet`<br>`modxevo-plugin`<br>`modxevo-module`<br>`modxevo-template`<br>`modxevo-lib`

src/Composer/Installers/MauticInstaller.php

+29-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,45 @@
11
<?php
22
namespace Composer\Installers;
33

4+
use Composer\Package\PackageInterface;
5+
46
class MauticInstaller extends BaseInstaller
57
{
68
protected $locations = array(
7-
'plugin' => 'plugins/{$name}/',
8-
'theme' => 'themes/{$name}/',
9+
'plugin' => 'plugins/{$name}/',
10+
'theme' => 'themes/{$name}/',
11+
'core' => 'app/',
912
);
1013

14+
private function getDirectoryName()
15+
{
16+
$extra = $this->package->getExtra();
17+
if (!empty($extra['install-directory-name'])) {
18+
return $extra['install-directory-name'];
19+
}
20+
21+
return $this->toCamelCase($this->package->getPrettyName());
22+
}
23+
24+
/**
25+
* @param string $packageName
26+
*
27+
* @return string
28+
*/
29+
private function toCamelCase($packageName)
30+
{
31+
return str_replace(' ', '', ucwords(str_replace('-', ' ', basename($packageName))));
32+
}
33+
1134
/**
1235
* Format package name of mautic-plugins to CamelCase
1336
*/
1437
public function inflectPackageVars($vars)
1538
{
16-
if ($vars['type'] == 'mautic-plugin') {
17-
$vars['name'] = preg_replace_callback('/(-[a-z])/', function ($matches) {
18-
return strtoupper($matches[0][1]);
19-
}, ucfirst($vars['name']));
39+
40+
if ($vars['type'] == 'mautic-plugin' || $vars['type'] == 'mautic-theme') {
41+
$directoryName = $this->getDirectoryName();
42+
$vars['name'] = $directoryName;
2043
}
2144

2245
return $vars;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
namespace Composer\Installers\Test;
3+
4+
use Composer\Installers\MauticInstaller;
5+
use Composer\Package\Package;
6+
use Composer\Composer;
7+
8+
class MauticInstallerTest extends TestCase
9+
{
10+
/**
11+
* @var MauticInstaller
12+
*/
13+
private $installer;
14+
15+
/**
16+
* @var \Composer\Composer
17+
*/
18+
protected $composer;
19+
20+
public function setUp()
21+
{
22+
$this->composer = new Composer();
23+
}
24+
25+
/**
26+
* @param string[] $vars
27+
* @param string[] $expectedVars
28+
*
29+
* @covers ::inflectPackageVars
30+
*
31+
* @dataProvider provideExpectedInflectionResults
32+
*/
33+
final public function testInflectPackageVars($vars, $expectedVars)
34+
{
35+
$package = new Package($vars['name'], '1.0.0', '1.0.0');
36+
$package->setType($vars['type']);
37+
if (isset($vars['extra'])) {
38+
$package->setExtra((array) $vars['extra']);
39+
}
40+
41+
$installer = new MauticInstaller(
42+
$package,
43+
$this->composer
44+
);
45+
46+
$actual = $installer->inflectPackageVars($vars);
47+
$this->assertEquals($actual, $expectedVars);
48+
}
49+
50+
/**
51+
* Provides various parameters for packages and the expected result after
52+
* inflection
53+
*
54+
* @return array
55+
*/
56+
final public function provideExpectedInflectionResults()
57+
{
58+
return array(
59+
//check bitrix-dir is correct
60+
array(
61+
array(
62+
'name' => 'mautic/grapes-js-builder-bundle',
63+
'type' => 'mautic-plugin'
64+
),
65+
array(
66+
'name' => 'GrapesJsBuilderBundle',
67+
'type' => 'mautic-plugin'
68+
)
69+
),
70+
// Check if composer renames the name based on the given
71+
// installation directory
72+
array(
73+
array(
74+
'name' => 'mautic/grapes-js-builder-bundle',
75+
'type' => 'mautic-plugin',
76+
'extra' => array(
77+
'install-directory-name' => 'GrapesJsBuilderPlugin'
78+
)
79+
),
80+
array(
81+
'name' => 'GrapesJsBuilderPlugin',
82+
'type' => 'mautic-plugin',
83+
'extra' => array(
84+
'install-directory-name' => 'GrapesJsBuilderPlugin'
85+
)
86+
)
87+
),
88+
array(
89+
array(
90+
'name' => 'mautic/theme-blank-grapejs',
91+
'type' => 'mautic-theme'
92+
),
93+
array(
94+
'name' => 'ThemeBlankGrapejs',
95+
'type' => 'mautic-theme'
96+
)
97+
),
98+
array(
99+
array(
100+
'name' => 'mautic/theme-blank-grapejs',
101+
'type' => 'mautic-theme',
102+
'extra' => array(
103+
'install-directory-name' => 'blank-grapejs'
104+
)
105+
),
106+
array(
107+
'name' => 'blank-grapejs',
108+
'type' => 'mautic-theme',
109+
'extra' => array(
110+
'install-directory-name' => 'blank-grapejs'
111+
)
112+
)
113+
)
114+
);
115+
}
116+
}

0 commit comments

Comments
 (0)