-
Notifications
You must be signed in to change notification settings - Fork 824
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
NEW: Add Config::moduleExists() #3612
Conversation
One thing I wonder for future proofing: should we recommend that people use the full Composer name of the module? If, in the future, we shift to putting modules into the vendor/ directory, then we will have created further BC issues by introducing this patch. For now, the code would have to simply ignore the vendor prefix, and we might make the vendor prefix recommended rather than required. What do others think? Should we future-proof this API change? |
0a9edb2
to
29d6350
Compare
I think it’d be a good idea to do what you’re suggesting. To clarify, we’d store (and check against) in the following order:
Is that along the lines of what you were thinking? |
That seems reasonable; having 3 different things to check is a bit of a code-smell, but I'm not sure which of those options we can drop. Maybe #2 should be dropped? |
I think we can safely drop 2, yeah. 1 adds the new functionality and 3 provides full backwards compatibility. |
@@ -104,9 +104,9 @@ public function testCachingNotForceRegeneration() { | |||
// Test that load is called | |||
$manifest = $this->getManifestMock(array('getCache', 'regenerate', 'buildYamlConfigVariant')); | |||
|
|||
// Load should be called twice | |||
// Load should be called three times |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thrice!
Just a thought... what about namespaces? As long as we're definitely behind Composer I see no problem with the (amended) approach above though. |
@willmorgan Do you mean if two namespaced modules share the same directory? We can’t (currently) support that anyway (conflicting _config.php/yml etc). |
Just re-thinking this, would we want to:
I’m leaning towards the former: it’s probably simpler, it matches the current behaviour, and the latter option would include One potential issue: let’s say I write a module that can be installed either with or without composer, and I want to check if moduleexists: 'ajshort/silverstripe-gridfieldextensions', 'gridfieldextensions' However I think this syntax implies that it’ll check if both of these exist. Do you think we could check for |
Just looking at this, what's the real purpose of this feature? Is it so you can provide functionality with several interchangeable modules? Doesn't this make dependency resolution for your package tricky... You'd have to use suggested dependencies, you'd also have to set a priority for which you prefer if both are available. Other than that, I don't see too much value in having this feature... Scanning composer files or the lock seems pretty nasty and relies on composer being used. If composer has been used, cant we just use a composer class to pull out all the modules? Further, what about modules that aren't pulled in with composer (eg: custom internal modules)? |
@dhensby If I remember correctly it was that I wanted a code-based check for whether a module existed (can’t remember the exact use case).
The intention was to fall back to directory names (which I believe is how the YAML system currently works). That said, I don’t think it’s a crucial feature at all, so I’m happy to leave this - it just stood out to me at the tune that you can set values in YAML based on whether a module exists yet can’t access that information in PHP. |
I think that makes sense. All in all, I think that this feature is going to take up too much time and effort to justify it - I don't see there's a big need for it. You should be able to use your own |
Directory-based check for whether a module exists in the manifest. Uses the same method of checking that the YAML
moduleexists: foo
does, just caches it and adds a way of accessing it throughConfig
.Usage:
Thinking:
class_exists()
is obviously the best way of doing this, but classes can be (and are) added/removed from some modules, so this can sometimes be a more robust check. Plus, the functionality to check already exists - it just can’t be accessed currently.