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

allow parameters in extension #189

Closed

Conversation

docteurklein
Copy link
Contributor

This is a BC Break.

You must change phpspec.yml accordingly:

# before
extensions:
    - Some\Extension

# after:
extensions:
    Some\Extension: ~
    # or, and that's why
    Some\Other\Extension:
        option1: ~

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.

@docteurklein
Copy link
Contributor Author

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".

@docteurklein
Copy link
Contributor Author

It doesn't mean we should not use this extension params thing.

@ciaranmcnulty
Copy link
Member

You can add whatever Extension-specific config you want to the main YML, it doesn't have to be keyed via the extension name

@docteurklein
Copy link
Contributor Author

@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.
It's better than having to maintain arbitrary DIC param names.

Thoughts @everzet ?

docteurklein referenced this pull request in docteurklein/Symfony2Extension Sep 13, 2013
@ciaranmcnulty
Copy link
Member

I'd agree if it didn't break BC.

@MarcelloDuarte
Copy link
Member

@marcodebortoli would this impact MageSpec?

@debo
Copy link

debo commented Sep 14, 2013

@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;

Copy link
Member

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

Copy link
Member

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.

Copy link
Member

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

Copy link
Member

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

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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 :)

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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 referenced this pull request in docteurklein/Symfony2Extension Sep 17, 2013
@MarcelloDuarte
Copy link
Member

@docteurklein I will tag 2.0 first and add this feature straight after, so existing extensions have time to adapt

@docteurklein
Copy link
Contributor Author

perfect! Thanks.

@ciaranmcnulty
Copy link
Member

@docteurklein I'm going to close this PR, can you please re-open against develop branch so we can merge in for 2.1?

@docteurklein
Copy link
Contributor Author

since we have only one master branch anymore, can you reopen it ?

@ciaranmcnulty ciaranmcnulty reopened this Aug 29, 2014
@stof
Copy link
Member

stof commented Aug 29, 2014

@docteurklein can you rebase it ?

@ciaranmcnulty
Copy link
Member

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)

@docteurklein
Copy link
Contributor Author

i'll do that, and rebase.

@ciaranmcnulty
Copy link
Member

Thanks - I know we discussed breaking BC before, but there are more extensions now than there used to be :-)

foreach ($val as $class) {
$extension = new $class();
foreach ($val as $extensionKey => $extensionValue) {
$extension = is_integer($extensionKey) ? new $extensionValue : new $extensionKey;
Copy link
Contributor Author

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!

@norberttech
Copy link
Contributor

@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

$class = $extensionConfig;
$extensionConfig = array();
}
var_dump($class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh my :)

@docteurklein
Copy link
Contributor Author

done. What do you think ?

@shanethehat
Copy link
Contributor

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?

$extension = new $class();
foreach ($val as $class => $extensionConfig) {
if (is_integer($class)) {
$class = $extensionConfig;
Copy link
Member

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

@ciaranmcnulty
Copy link
Member

@docteurklein Can you address my notes above?

@ciaranmcnulty ciaranmcnulty removed this from the 2.1 milestone Nov 24, 2014
@docteurklein
Copy link
Contributor Author

rabased.
@ciaranmcnulty sorry for such a long time, i simply am so busy :)
Anyway, here are the changes concerning the class name validation.

@docteurklein
Copy link
Contributor Author

I didn't implement the BC ParametrizedExtension, since I'm not sure this is something we want.

@ciaranmcnulty
Copy link
Member

BC is a big issue - it would be much better if you can preserve it.

@docteurklein
Copy link
Contributor Author

@ciaranmcnulty i finally introduced a ParametrizedExtensionInterface.
Extensions creators who want to allow extension parameters will have to implement this interface instead of the default one.

@docteurklein
Copy link
Contributor Author

and I got a D for that! (which I understand, seeing the code :) )

@ciaranmcnulty
Copy link
Member

Optional arguments are often missing from Scrutinizer reports - report it as an error or do a PR to php-analyser

@docteurklein
Copy link
Contributor Author

ho crap: https://travis-ci.org/phpspec/phpspec/jobs/42623205#L2013

5.3.3 is definitly a bummer :)
What do you think sould I do ?

@ciaranmcnulty
Copy link
Member

Upvote this #571 ;-P

@docteurklein
Copy link
Contributor Author

that's exactly what I wanted to hear :)

@ciaranmcnulty
Copy link
Member

@docteurklein I don't think we'll be updating the PHP version soon

@stof
Copy link
Member

stof commented Jan 18, 2015

@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)

@docteurklein
Copy link
Contributor Author

@stof @ciaranmcnulty good idea.

@ciaranmcnulty
Copy link
Member

I'm going to close the PR for now, it doesn't mean it's not a good idea!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants