Skip to content

Commit 06b3ec1

Browse files
authoredJun 24, 2024
Merge pull request #529 from carakas/main
Add support for Fork CMS ^6
2 parents 86d774d + 012de40 commit 06b3ec1

File tree

4 files changed

+360
-0
lines changed

4 files changed

+360
-0
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ all vendor code in the vendor directory, and not requiring custom installer code
6363
| Eliasis | `eliasis-component`<br>`eliasis-module`<br>`eliasis-plugin`<br>`eliasis-template`
6464
| ExpressionEngine 3 | `ee3-addon`<br>`ee3-theme`
6565
| eZ Platform | `ezplatform-assets`<br>`ezplatform-meta-assets`
66+
| ForkCMS ^v6.x| `fork-cms-module`<br>`fork-cms-theme`
6667
| FuelPHP v1.x | `fuel-module`<br>`fuel-package`<br/>`fuel-theme`
6768
| FuelPHP v2.x | `fuelphp-component`
6869
| Grav | `grav-plugin`<br>`grav-theme`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace Composer\Installers;
4+
5+
class ForkCMSInstaller extends BaseInstaller
6+
{
7+
/** @var array<string, string> */
8+
protected $locations = [
9+
'module' => 'src/Modules/{$name}/',
10+
'theme' => 'src/Themes/{$name}/'
11+
];
12+
13+
/**
14+
* Format package name.
15+
*
16+
* For package type fork-cms-module, cut off a trailing '-plugin' if present.
17+
*
18+
* For package type fork-cms-theme, cut off a trailing '-theme' if present.
19+
*/
20+
public function inflectPackageVars(array $vars): array
21+
{
22+
if ($vars['type'] === 'fork-cms-module') {
23+
return $this->inflectModuleVars($vars);
24+
}
25+
26+
if ($vars['type'] === 'fork-cms-theme') {
27+
return $this->inflectThemeVars($vars);
28+
}
29+
30+
return $vars;
31+
}
32+
33+
/**
34+
* @param array<string, string> $vars
35+
* @return array<string, string>
36+
*/
37+
protected function inflectModuleVars(array $vars): array
38+
{
39+
$vars['name'] = $this->pregReplace('/^fork-cms-|-module|ForkCMS|ForkCms|Forkcms|forkcms|Module$/', '', $vars['name']);
40+
$vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']); // replace hyphens with spaces
41+
$vars['name'] = str_replace(' ', '', ucwords($vars['name'])); // make module name camelcased
42+
43+
return $vars;
44+
}
45+
46+
/**
47+
* @param array<string, string> $vars
48+
* @return array<string, string>
49+
*/
50+
protected function inflectThemeVars(array $vars): array
51+
{
52+
$vars['name'] = $this->pregReplace('/^fork-cms-|-theme|ForkCMS|ForkCms|Forkcms|forkcms|Theme$/', '', $vars['name']);
53+
$vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']); // replace hyphens with spaces
54+
$vars['name'] = str_replace(' ', '', ucwords($vars['name'])); // make theme name camelcased
55+
56+
return $vars;
57+
}
58+
}

‎src/Composer/Installers/Installer.php

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class Installer extends LibraryInstaller
4646
'ee3' => 'ExpressionEngineInstaller',
4747
'ee2' => 'ExpressionEngineInstaller',
4848
'ezplatform' => 'EzPlatformInstaller',
49+
'fork' => 'ForkCMSInstaller',
4950
'fuel' => 'FuelInstaller',
5051
'fuelphp' => 'FuelphpInstaller',
5152
'grav' => 'GravInstaller',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
<?php
2+
3+
namespace Composer\Installers\Test;
4+
5+
use Composer\Installers\ForkCMSInstaller;
6+
use Composer\Package\Package;
7+
8+
class ForkCMSInstallerTest extends TestCase
9+
{
10+
/**
11+
* @var ForkCMSInstaller
12+
*/
13+
private $installer;
14+
15+
public function setUp(): void
16+
{
17+
$this->installer = new ForkCMSInstaller(
18+
new Package('Knife', '4.2', '4.2'),
19+
$this->getComposer(),
20+
$this->getMockIO()
21+
);
22+
}
23+
24+
/**
25+
* @dataProvider packageNameInflectionProvider
26+
*/
27+
public function testInflectPackageVars(string $type, string $vendor, string $name, string $expectedVendor, string $expectedName): void
28+
{
29+
$this->assertEquals(
30+
$this->installer->inflectPackageVars([
31+
'vendor' => $vendor,
32+
'name' => $name,
33+
'type' => $type
34+
]),
35+
['vendor' => $expectedVendor, 'name' => $expectedName, 'type' => $type]
36+
);
37+
}
38+
39+
public function packageNameInflectionProvider(): array
40+
{
41+
return [
42+
// module with lowercase name
43+
[
44+
'fork-cms-module',
45+
'pageon',
46+
'knife',
47+
'pageon',
48+
'Knife',
49+
],
50+
// theme with lowercase name
51+
[
52+
'fork-cms-theme',
53+
'pageon',
54+
'knife',
55+
'pageon',
56+
'Knife',
57+
],
58+
// module with lowercase name and module affix
59+
[
60+
'fork-cms-module',
61+
'pageon',
62+
'knife-module',
63+
'pageon',
64+
'Knife',
65+
],
66+
// theme with lowercase name and theme affix
67+
[
68+
'fork-cms-theme',
69+
'pageon',
70+
'knife-theme',
71+
'pageon',
72+
'Knife',
73+
],
74+
// module with lowercase name and module affix and fork-cms prefix
75+
[
76+
'fork-cms-module',
77+
'pageon',
78+
'fork-cms-knife-module',
79+
'pageon',
80+
'Knife',
81+
],
82+
// theme with lowercase name and theme affix and fork-cms prefix
83+
[
84+
'fork-cms-theme',
85+
'pageon',
86+
'fork-cms-knife-theme',
87+
'pageon',
88+
'Knife',
89+
],
90+
// module with lowercase name and fork-cms prefix
91+
[
92+
'fork-cms-module',
93+
'pageon',
94+
'fork-cms-knife',
95+
'pageon',
96+
'Knife',
97+
],
98+
// theme with lowercase name and fork-cms prefix
99+
[
100+
'fork-cms-theme',
101+
'pageon',
102+
'fork-cms-knife',
103+
'pageon',
104+
'Knife',
105+
],
106+
// module with hyphenated name
107+
[
108+
'fork-cms-module',
109+
'pageon',
110+
'knife-and-spoon',
111+
'pageon',
112+
'KnifeAndSpoon',
113+
],
114+
// theme with hyphenated name
115+
[
116+
'fork-cms-theme',
117+
'pageon',
118+
'knife-and-spoon',
119+
'pageon',
120+
'KnifeAndSpoon',
121+
],
122+
// module with hyphenated name and module affix
123+
[
124+
'fork-cms-module',
125+
'pageon',
126+
'knife-and-spoon-module',
127+
'pageon',
128+
'KnifeAndSpoon',
129+
],
130+
// theme with hyphenated name and theme affix
131+
[
132+
'fork-cms-theme',
133+
'pageon',
134+
'knife-and-spoon-theme',
135+
'pageon',
136+
'KnifeAndSpoon',
137+
],
138+
// module with hyphenated name and module affix and fork-cms prefix
139+
[
140+
'fork-cms-module',
141+
'pageon',
142+
'fork-cms-knife-and-spoon-module',
143+
'pageon',
144+
'KnifeAndSpoon',
145+
],
146+
// theme with hyphenated name and theme affix and fork-cms prefix
147+
[
148+
'fork-cms-theme',
149+
'pageon',
150+
'fork-cms-knife-and-spoon-theme',
151+
'pageon',
152+
'KnifeAndSpoon',
153+
],
154+
// module with hyphenated name and fork-cms prefix
155+
[
156+
'fork-cms-module',
157+
'pageon',
158+
'fork-cms-knife-and-spoon',
159+
'pageon',
160+
'KnifeAndSpoon',
161+
],
162+
// theme with hyphenated name and fork-cms prefix
163+
[
164+
'fork-cms-theme',
165+
'pageon',
166+
'fork-cms-knife-and-spoon',
167+
'pageon',
168+
'KnifeAndSpoon',
169+
],
170+
// module with underscored name
171+
[
172+
'fork-cms-module',
173+
'pageon',
174+
'knife_and_spoon',
175+
'pageon',
176+
'KnifeAndSpoon',
177+
],
178+
// theme with underscored name
179+
[
180+
'fork-cms-theme',
181+
'pageon',
182+
'knife_and_spoon',
183+
'pageon',
184+
'KnifeAndSpoon',
185+
],
186+
// module with underscored name and module affix
187+
[
188+
'fork-cms-module',
189+
'pageon',
190+
'knife_and_spoon-module',
191+
'pageon',
192+
'KnifeAndSpoon',
193+
],
194+
// theme with underscored name and theme affix
195+
[
196+
'fork-cms-theme',
197+
'pageon',
198+
'knife_and_spoon-theme',
199+
'pageon',
200+
'KnifeAndSpoon',
201+
],
202+
// module with underscored name and module affix and fork-cms prefix
203+
[
204+
'fork-cms-module',
205+
'pageon',
206+
'fork-cms-knife_and_spoon-module',
207+
'pageon',
208+
'KnifeAndSpoon',
209+
],
210+
// theme with underscored name and theme affix and fork-cms prefix
211+
[
212+
'fork-cms-theme',
213+
'pageon',
214+
'fork-cms-knife_and_spoon-theme',
215+
'pageon',
216+
'KnifeAndSpoon',
217+
],
218+
// module with underscored name and fork-cms prefix
219+
[
220+
'fork-cms-module',
221+
'pageon',
222+
'fork-cms-knife_and_spoon',
223+
'pageon',
224+
'KnifeAndSpoon',
225+
],
226+
// theme with underscored name and fork-cms prefix
227+
[
228+
'fork-cms-theme',
229+
'pageon',
230+
'fork-cms-knife_and_spoon',
231+
'pageon',
232+
'KnifeAndSpoon',
233+
],
234+
// module with camelcased name
235+
[
236+
'fork-cms-module',
237+
'pageon',
238+
'knifeAndSpoon',
239+
'pageon',
240+
'KnifeAndSpoon',
241+
],
242+
// theme with camelcased name
243+
[
244+
'fork-cms-theme',
245+
'pageon',
246+
'knifeAndSpoon',
247+
'pageon',
248+
'KnifeAndSpoon',
249+
],
250+
// module with camelcased name and module affix
251+
[
252+
'fork-cms-module',
253+
'pageon',
254+
'knifeAndSpoonModule',
255+
'pageon',
256+
'KnifeAndSpoon',
257+
],
258+
// theme with camelcased name and theme affix
259+
[
260+
'fork-cms-theme',
261+
'pageon',
262+
'knifeAndSpoonTheme',
263+
'pageon',
264+
'KnifeAndSpoon',
265+
],
266+
// module with camelcased name and module affix and fork-cms prefix
267+
[
268+
'fork-cms-module',
269+
'pageon',
270+
'ForkCmsKnifeAndSpoonModule',
271+
'pageon',
272+
'KnifeAndSpoon',
273+
],
274+
// theme with camelcased name and theme affix and fork-cms prefix
275+
[
276+
'fork-cms-theme',
277+
'pageon',
278+
'ForkCmsKnifeAndSpoonTheme',
279+
'pageon',
280+
'KnifeAndSpoon',
281+
],
282+
// module with camelcased name and fork-cms prefix
283+
[
284+
'fork-cms-module',
285+
'pageon',
286+
'ForkCmsKnifeAndSpoon',
287+
'pageon',
288+
'KnifeAndSpoon',
289+
],
290+
// theme with camelcased name and fork-cms prefix
291+
[
292+
'fork-cms-theme',
293+
'pageon',
294+
'ForkCmsKnifeAndSpoon',
295+
'pageon',
296+
'KnifeAndSpoon',
297+
],
298+
];
299+
}
300+
}

0 commit comments

Comments
 (0)