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
allow parameters in extension #189
Conversation
Ha, funny, but I just realised you could register as much as DIC parameters as you want as soon as key is different from "extensions". |
It doesn't mean we should not use this extension params thing. |
You can add whatever Extension-specific config you want to the main YML, it doesn't have to be keyed via the extension name |
@ciaranmcnulty thanks, I just noticed that later :/ Anyway, as said above, it does not mean we should not provide extension config under the extension class name. Thoughts @everzet ? |
I'd agree if it didn't break BC. |
@marcodebortoli would this impact MageSpec? |
@MarcelloDuarte what @docteurklein said but if you merge it I'll fix MageSpec straight away. I need to review some code anyway this weekend for the presentation so... feel free to proceed. |
@@ -404,7 +404,7 @@ protected function loadConfigurationFile(ServiceContainer $container) | |||
|
|||
foreach ($config as $key => $val) { | |||
if ('extensions' === $key) { | |||
foreach ($val as $class) { | |||
foreach ($val as $class => $params) { | |||
$extension = new $class; | |||
|
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.
Could you add a check here to see whether $class was numeric?
if (is_numeric($class)) {
$class = $params;
$params = array();
}
That would probably preserve BC
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.
I don't think we need. There's only a handful of extensions, and we know must of the guys. Better to keep the code clean in this case, in my opinion. I will have a look at the expect helper (after jet leg has passed) and merge this.
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.
@MarcelloDuarte But this BC break does not impact extension authors. It impacts extension users
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.
instead of providing BC, we could at least throw an exception asking the user to update their config
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.
+1
This will mean a user has to update all extensions associated with PhpSpec, then update their configurations. And it doesn't enable anything that wasn't possible before, just changes the syntax Extensions must use.
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.
Actually, it introduces a new possibility: it decouples the YAML config from the DIC parameters, which means that extensions can make their config more semantic (using a nested array to group related settings), can validate the config provided for the extension and can provide BC for older formats when it gets refactored. Btw, these are the reason why Symfony2 bundles have a system for semantic configuration instead of relying on the user to set DIC parameters directly.
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.
@stof has always the right words :)
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.
@stof Extensions at present could access the YAML config, the question is whether extension-specific config should be under the extension key in the extensions: stanza, or whether extensions should be able to look at global config.
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.
I would say that the extensions should be able to access both. They would have access to "extension-specific" config (semantic, simple for the user) AND to global container parameters.
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.
@ciaranmcnulty Yes, extensions can access the YAML config. But if they want to provide a semantic configuration, which can be processed and for which it can provide BC, it means that you end with extra stuff in the DIC if you start by setting the semantic config as a parameter and then process it after that
@docteurklein I will tag 2.0 first and add this feature straight after, so existing extensions have time to adapt |
perfect! Thanks. |
@docteurklein I'm going to close this PR, can you please re-open against develop branch so we can merge in for 2.1? |
since we have only one master branch anymore, can you reopen it ? |
@docteurklein can you rebase it ? |
I don't think we can break the old format, can you handle both? Maybe by detecting when the value is an array, or detecting when the key is numeric (we're never going to have a numeric Extension name) |
i'll do that, and rebase. |
Thanks - I know we discussed breaking BC before, but there are more extensions now than there used to be :-) |
57b4230
to
452a587
Compare
foreach ($val as $class) { | ||
$extension = new $class(); | ||
foreach ($val as $extensionKey => $extensionValue) { | ||
$extension = is_integer($extensionKey) ? new $extensionValue : new $extensionKey; |
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.
not very elegant, but if you have better I'll take it!
@docteurklein what do you think about passing optional parameters as a extension __construtor arguments? I have very similar extension system in my project and this is how I construct extensions: https://github.com/coduo/TuTu/blob/master/src/Coduo/TuTu/Extension/Initializer.php |
452a587
to
1c2ec7a
Compare
$class = $extensionConfig; | ||
$extensionConfig = array(); | ||
} | ||
var_dump($class); |
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.
needs to be removed
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.
oh my :)
1c2ec7a
to
31e2470
Compare
done. What do you think ? |
I like that future versions of Magespec could have the extension-specific config placed in a clear place in the config file. The proposed BC break could be adopted very quickly, and with a small amount of warning we could be compatible as soon as this merges and tags. @marcodebortoli and @jamescowie? |
dc0d473
to
a96f67e
Compare
$extension = new $class(); | ||
foreach ($val as $class => $extensionConfig) { | ||
if (is_integer($class)) { | ||
$class = $extensionConfig; |
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.
You'll need to validate that $class
is a string here or get a weird error a few lines later
@docteurklein Can you address my notes above? |
a96f67e
to
16309a2
Compare
rabased. |
I didn't implement the BC |
BC is a big issue - it would be much better if you can preserve it. |
16309a2
to
6b1edd1
Compare
@ciaranmcnulty i finally introduced a |
and I got a |
Optional arguments are often missing from Scrutinizer reports - report it as an error or do a PR to php-analyser |
ho crap: https://travis-ci.org/phpspec/phpspec/jobs/42623205#L2013 5.3.3 is definitly a bummer :) |
Upvote this #571 ;-P |
that's exactly what I wanted to hear :) |
@docteurklein I don't think we'll be updating the PHP version soon |
@ciaranmcnulty I suggest putting this on hold until we decide what we do with Testwork (if we go the way of using Testwork extensions, this proposal will be obsolete) |
@stof @ciaranmcnulty good idea. |
I'm going to close the PR for now, it doesn't mean it's not a good idea! |
This is a BC Break.
You must change
phpspec.yml
accordingly:I started to spec this until I realised this class is not speccable with current impl.
We should extract this extension loading mechanism to its own class.