-
-
Notifications
You must be signed in to change notification settings - Fork 413
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 #529 from carakas/main
Add support for Fork CMS ^6
- Loading branch information
Showing
4 changed files
with
360 additions
and
0 deletions.
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
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; | ||
} | ||
} |
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
300 changes: 300 additions & 0 deletions
300
tests/Composer/Installers/Test/ForkCMSInstallerTest.php
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,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', | ||
], | ||
]; | ||
} | ||
} |