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

API Major rewrite for inclusion into framework #4

Merged
merged 3 commits into from
Feb 26, 2017

Conversation

tractorcow
Copy link

Framework PR will follow later.

Changes:

API Split ConfigCollectionInterface into mutable / immutable
API New CachedConfigCollection behaviour
API Middleware pattern to allow getClassConfig() to be decorated
API Support $class and $name instead of $key for properties
API Revendor from micmania1\config to SilverStripe\Config
BUG Fix support for before:* / after:*
ENHANCEMENT: Allow nulls to replace non-nulls
API Make Priority methods static
API Added shiv for ->update() legacy method
API Drop symfony dependencies to 2.8
API Enable stores and transformers to be constructed as a nested composite object
API Enable deferred loading of private-static classes

API New CachedConfigCollection behaviour
API Middleware pattern to allow getClassConfig() to be decorated
API Support $class and $name instead of $key for properties
API Revendor from micmania1\config to SilverStripe\Config
BUG Fix support for before:* / after:*
ENHANCEMENT: Allow nulls to replace non-nulls
API Make Priority methods static
API Added shiv for ->update() legacy method
API Drop symfony dependencies to 2.8
API Enable stores and transformers to be constructed as a nested composite object
API Enable deferred loading of private-static classes
@chillu
Copy link
Member

chillu commented Feb 22, 2017

Did you mean to include composer.lock here?

@tractorcow
Copy link
Author

The original module had it included. It's for testing only.

@tractorcow
Copy link
Author

I'll take it out; It's probably not needed. :D

Copy link
Member

@sminnee sminnee left a comment

Choose a reason for hiding this comment

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

I'm happy with this, pending @micmania1's feedback.

Copy link
Contributor

@micmania1 micmania1 left a comment

Choose a reason for hiding this comment

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

I've left some comments but overall really happy with the work @tractorcow has done 👍

Could you please update the docs to explain middleware usage?

}

// Check cache
if (isset($this->callCache[$class][$disableFlag])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not really sure what's going on with $options. $options can be an array so when it is, this will break.

Can you give me some background on why $options was implemented in the way it was? ie. Why can it be an int, true or an array instead of deciding on just one type?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, disableFlag doesn't really tell you what its disabling - you have to look through the rest of the code to figure it out. If its kept (re: comment above) it should probably be renames to disableMiddleware or something similar. If we add disableHistory or something like that it could get confusing.

Copy link
Author

Choose a reason for hiding this comment

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

For the sake of simplicity, I think I should simply remove the array-form, and keep this as a simple int for flag-assignment, and rename to something that implies it's purpose more succinctly.

Copy link
Author

Choose a reason for hiding this comment

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

Changed to $excludeMiddleware and phpdoc int|true

*/
protected function saveMetadata($class, $metadata)
{
if (!$this->trackMetadata) {
Copy link
Contributor

Choose a reason for hiding this comment

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

With regards to the disableFlag we're disabling things two separate ways now. I think this is clearer and more explicit so my preference would be for properties.

Copy link
Author

Choose a reason for hiding this comment

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

disableFlag is set at-call, though, not a property on an object. I think these are separate types of use cases.

Copy link
Author

Choose a reason for hiding this comment

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

Actually I'm not sure what you are asking here... bug me on Monday?

* @param MutableConfigCollectionInterface $theirs
* @return MutableConfigCollectionInterface
*/
public static function merge(array $mine, MutableConfigCollectionInterface $theirs)
Copy link
Contributor

Choose a reason for hiding this comment

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

ahhhh I have a problem with adding static functions that I need to get over. I don't know why I didn't make it static to begin with

}
return $otherPatterns !== '*';
}
);
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't comment on the actual line, but this is for line 431 (the todo). There's no sanitsation for the matching so any document name with strange chars will be passed into preg_replace and may break.

}
return $otherPatterns !== '*';
}
);
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't comment on the actual line, but this is for line 431 (the todo). There's no sanitsation for the matching so any document name with strange chars will be passed into preg_replace and may break. Sorry, I never got around to fixing it.

Copy link
Author

Choose a reason for hiding this comment

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

I can escape it. :D

Copy link
Author

Choose a reason for hiding this comment

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

Replaced with:

// Replace all `*` with `[^\.][a-zA-Z0-9\-_\/\.]+`, and quote other characters
        $patternRegExp = implode(
            '[^\.][a-zA-Z0-9\-_\/\.]+',
            array_map(
                function($part) { return preg_quote($part, '%'); },
                explode('*', $pattern)
            )
        );

@sminnee
Copy link
Member

sminnee commented Feb 26, 2017

@tractorcow can you have a look at Michael's feedback on Monday?

@micmania1 assuming all is well, can you merge this on Monday?

@tractorcow
Copy link
Author

Fixing up feedback now.

@tractorcow
Copy link
Author

@micmania1 I've written up some nice docs on middleware too. :) All points are addressed (except #4, which we can talk about Monday).

I'll push up once I check tests are ok.

@tractorcow
Copy link
Author

@micmania1 feedback fixes pushed up as separate commit (for ease of review ^^)

Thanks very much for the review; It's well appreciated friend!

Middleware documentation
Improve regular expression in YamlTransformer
@tractorcow tractorcow force-pushed the pulls/1.0/config-redux branch from 2621054 to a51d1f8 Compare February 26, 2017 03:47
@tractorcow
Copy link
Author

Oh look, it's green. :)

@micmania1 micmania1 merged commit 2c1a787 into silverstripe:master Feb 26, 2017
@tractorcow tractorcow deleted the pulls/1.0/config-redux branch February 27, 2017 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants