Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Do not require _config dir or _config.php for modules #11296

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Core/Manifest/ManifestFileFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class ManifestFileFinder extends FileFinder

const CONFIG_FILE = '_config.php';
const CONFIG_DIR = '_config';
const COMPOSER_FILE = 'composer.json';
const COMPOSER_TYPES = [
'silverstripe-vendormodule',
'silverstripe-theme',
];
const EXCLUDE_FILE = '_manifest_exclude';
const LANG_DIR = 'lang';
const TESTS_DIR = 'tests';
Expand Down Expand Up @@ -179,6 +184,16 @@ public function isDirectoryModule($basename, $pathname, $depth)
return true;
}

// True if composer type
$path = $pathname . '/' . ManifestFileFinder::COMPOSER_FILE;
if (file_exists($path)) {
$composer = json_decode(file_get_contents($path), true);
$type = $composer['type'] ?? '';
if (in_array($type, ManifestFileFinder::COMPOSER_TYPES)) {
return true;
}
}

return false;
}

Expand Down
32 changes: 32 additions & 0 deletions tests/php/Core/Manifest/ManifestFileFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,36 @@ public function testIncludeWithRootConfigFolder()
]
);
}

/**
* Note that this phpunit file is unable to use a dataProvider for some unknown reason
*/
public function testIsDirectoryModule()
{
$provider = [
'vendormodule' => [
'silverstripe-vendormodule',
true,
],
'theme' => [
'silverstripe-theme',
true,
],
'somethingelse' => [
'silverstripe-somethingelse',
false,
],
'notype' => [
'silverstripe-notype',
false,
],
];
foreach ($provider as $data) {
list($subdir, $expected) = $data;
$finder = new ManifestFileFinder();
$pathname = __DIR__ . '/fixtures/manifestfilefinder_rootconfigcomposer/' . $subdir;
$actual = $finder->isDirectoryModule('', $pathname, 0);
$this->assertSame($expected, $actual);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "silverstripe/manifestfilefindertest"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "silverstripe/manifestfilefindertest",
"type": "silverstripe-somethingelse"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "silverstripe/manifestfilefindertest",
"type": "silverstripe-theme"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "silverstripe/manifestfilefindertest",
"type": "silverstripe-vendormodule"
}
Loading