Skip to content

Commit

Permalink
Merge pull request #529 from carakas/main
Browse files Browse the repository at this point in the history
Add support for Fork CMS ^6
  • Loading branch information
Seldaek authored Jun 24, 2024
2 parents 86d774d + 012de40 commit 06b3ec1
Show file tree
Hide file tree
Showing 4 changed files with 360 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ all vendor code in the vendor directory, and not requiring custom installer code
| Eliasis | `eliasis-component`<br>`eliasis-module`<br>`eliasis-plugin`<br>`eliasis-template`
| ExpressionEngine 3 | `ee3-addon`<br>`ee3-theme`
| eZ Platform | `ezplatform-assets`<br>`ezplatform-meta-assets`
| ForkCMS ^v6.x| `fork-cms-module`<br>`fork-cms-theme`
| FuelPHP v1.x | `fuel-module`<br>`fuel-package`<br/>`fuel-theme`
| FuelPHP v2.x | `fuelphp-component`
| Grav | `grav-plugin`<br>`grav-theme`
Expand Down
58 changes: 58 additions & 0 deletions src/Composer/Installers/ForkCMSInstaller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Composer\Installers;

class ForkCMSInstaller extends BaseInstaller
{
/** @var array<string, string> */
protected $locations = [
'module' => 'src/Modules/{$name}/',
'theme' => 'src/Themes/{$name}/'
];

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

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

return $vars;
}

/**
* @param array<string, string> $vars
* @return array<string, string>
*/
protected function inflectModuleVars(array $vars): array
{
$vars['name'] = $this->pregReplace('/^fork-cms-|-module|ForkCMS|ForkCms|Forkcms|forkcms|Module$/', '', $vars['name']);
$vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']); // replace hyphens with spaces
$vars['name'] = str_replace(' ', '', ucwords($vars['name'])); // make module name camelcased

return $vars;
}

/**
* @param array<string, string> $vars
* @return array<string, string>
*/
protected function inflectThemeVars(array $vars): array
{
$vars['name'] = $this->pregReplace('/^fork-cms-|-theme|ForkCMS|ForkCms|Forkcms|forkcms|Theme$/', '', $vars['name']);
$vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']); // replace hyphens with spaces
$vars['name'] = str_replace(' ', '', ucwords($vars['name'])); // make theme name camelcased

return $vars;
}
}
1 change: 1 addition & 0 deletions src/Composer/Installers/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Installer extends LibraryInstaller
'ee3' => 'ExpressionEngineInstaller',
'ee2' => 'ExpressionEngineInstaller',
'ezplatform' => 'EzPlatformInstaller',
'fork' => 'ForkCMSInstaller',
'fuel' => 'FuelInstaller',
'fuelphp' => 'FuelphpInstaller',
'grav' => 'GravInstaller',
Expand Down
300 changes: 300 additions & 0 deletions tests/Composer/Installers/Test/ForkCMSInstallerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
<?php

namespace Composer\Installers\Test;

use Composer\Installers\ForkCMSInstaller;
use Composer\Package\Package;

class ForkCMSInstallerTest extends TestCase
{
/**
* @var ForkCMSInstaller
*/
private $installer;

public function setUp(): void
{
$this->installer = new ForkCMSInstaller(
new Package('Knife', '4.2', '4.2'),
$this->getComposer(),
$this->getMockIO()
);
}

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

public function packageNameInflectionProvider(): array
{
return [
// module with lowercase name
[
'fork-cms-module',
'pageon',
'knife',
'pageon',
'Knife',
],
// theme with lowercase name
[
'fork-cms-theme',
'pageon',
'knife',
'pageon',
'Knife',
],
// module with lowercase name and module affix
[
'fork-cms-module',
'pageon',
'knife-module',
'pageon',
'Knife',
],
// theme with lowercase name and theme affix
[
'fork-cms-theme',
'pageon',
'knife-theme',
'pageon',
'Knife',
],
// module with lowercase name and module affix and fork-cms prefix
[
'fork-cms-module',
'pageon',
'fork-cms-knife-module',
'pageon',
'Knife',
],
// theme with lowercase name and theme affix and fork-cms prefix
[
'fork-cms-theme',
'pageon',
'fork-cms-knife-theme',
'pageon',
'Knife',
],
// module with lowercase name and fork-cms prefix
[
'fork-cms-module',
'pageon',
'fork-cms-knife',
'pageon',
'Knife',
],
// theme with lowercase name and fork-cms prefix
[
'fork-cms-theme',
'pageon',
'fork-cms-knife',
'pageon',
'Knife',
],
// module with hyphenated name
[
'fork-cms-module',
'pageon',
'knife-and-spoon',
'pageon',
'KnifeAndSpoon',
],
// theme with hyphenated name
[
'fork-cms-theme',
'pageon',
'knife-and-spoon',
'pageon',
'KnifeAndSpoon',
],
// module with hyphenated name and module affix
[
'fork-cms-module',
'pageon',
'knife-and-spoon-module',
'pageon',
'KnifeAndSpoon',
],
// theme with hyphenated name and theme affix
[
'fork-cms-theme',
'pageon',
'knife-and-spoon-theme',
'pageon',
'KnifeAndSpoon',
],
// module with hyphenated name and module affix and fork-cms prefix
[
'fork-cms-module',
'pageon',
'fork-cms-knife-and-spoon-module',
'pageon',
'KnifeAndSpoon',
],
// theme with hyphenated name and theme affix and fork-cms prefix
[
'fork-cms-theme',
'pageon',
'fork-cms-knife-and-spoon-theme',
'pageon',
'KnifeAndSpoon',
],
// module with hyphenated name and fork-cms prefix
[
'fork-cms-module',
'pageon',
'fork-cms-knife-and-spoon',
'pageon',
'KnifeAndSpoon',
],
// theme with hyphenated name and fork-cms prefix
[
'fork-cms-theme',
'pageon',
'fork-cms-knife-and-spoon',
'pageon',
'KnifeAndSpoon',
],
// module with underscored name
[
'fork-cms-module',
'pageon',
'knife_and_spoon',
'pageon',
'KnifeAndSpoon',
],
// theme with underscored name
[
'fork-cms-theme',
'pageon',
'knife_and_spoon',
'pageon',
'KnifeAndSpoon',
],
// module with underscored name and module affix
[
'fork-cms-module',
'pageon',
'knife_and_spoon-module',
'pageon',
'KnifeAndSpoon',
],
// theme with underscored name and theme affix
[
'fork-cms-theme',
'pageon',
'knife_and_spoon-theme',
'pageon',
'KnifeAndSpoon',
],
// module with underscored name and module affix and fork-cms prefix
[
'fork-cms-module',
'pageon',
'fork-cms-knife_and_spoon-module',
'pageon',
'KnifeAndSpoon',
],
// theme with underscored name and theme affix and fork-cms prefix
[
'fork-cms-theme',
'pageon',
'fork-cms-knife_and_spoon-theme',
'pageon',
'KnifeAndSpoon',
],
// module with underscored name and fork-cms prefix
[
'fork-cms-module',
'pageon',
'fork-cms-knife_and_spoon',
'pageon',
'KnifeAndSpoon',
],
// theme with underscored name and fork-cms prefix
[
'fork-cms-theme',
'pageon',
'fork-cms-knife_and_spoon',
'pageon',
'KnifeAndSpoon',
],
// module with camelcased name
[
'fork-cms-module',
'pageon',
'knifeAndSpoon',
'pageon',
'KnifeAndSpoon',
],
// theme with camelcased name
[
'fork-cms-theme',
'pageon',
'knifeAndSpoon',
'pageon',
'KnifeAndSpoon',
],
// module with camelcased name and module affix
[
'fork-cms-module',
'pageon',
'knifeAndSpoonModule',
'pageon',
'KnifeAndSpoon',
],
// theme with camelcased name and theme affix
[
'fork-cms-theme',
'pageon',
'knifeAndSpoonTheme',
'pageon',
'KnifeAndSpoon',
],
// module with camelcased name and module affix and fork-cms prefix
[
'fork-cms-module',
'pageon',
'ForkCmsKnifeAndSpoonModule',
'pageon',
'KnifeAndSpoon',
],
// theme with camelcased name and theme affix and fork-cms prefix
[
'fork-cms-theme',
'pageon',
'ForkCmsKnifeAndSpoonTheme',
'pageon',
'KnifeAndSpoon',
],
// module with camelcased name and fork-cms prefix
[
'fork-cms-module',
'pageon',
'ForkCmsKnifeAndSpoon',
'pageon',
'KnifeAndSpoon',
],
// theme with camelcased name and fork-cms prefix
[
'fork-cms-theme',
'pageon',
'ForkCmsKnifeAndSpoon',
'pageon',
'KnifeAndSpoon',
],
];
}
}

0 comments on commit 06b3ec1

Please sign in to comment.