-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add fluent setters for parameters in the slack handler #801
Add fluent setters for parameters in the slack handler #801
Conversation
Actually refactoring constructors is one of the few tasks left to do before 2.0 can be released. I am not sure if they should just all change to something like |
Does bubble even need to be in the constructor? Could it just be left as a setter in |
Well technically we almost don't need anything in the constructor.. but it's a convenience IMO to be able to configure everything in constructor, and especially when dealing with dependency injection containers and such dealing with setters vs constructor argument causes extra hurdles/boilerplate. |
A big problem with using array for arguments is that it's even harder to work out what are valid options. There's no other way except looking at the code/API docs to see what is allowed for each constructor then. At least with constructor parameters you can get hints from your IDE or just look at the method signature. |
Imo having dedicated configuration classes would be the best solution. Constructors could be reduced to one argument and the use of classes would allow for autocompletion in IDEs as well as type hinting constructor arguments. Furthermore, configuration classes could optionally validate themselves. |
Until Monolog 2 is out is it possible to get this merged into the 1.x branch? Or are there no plans to for new v1 releases? |
I'd rather not as it then adds more cruft to be removed in 2.0 if we go with configuration classes. Although for non-essential settings (i.e. stuff that can be configured optionally) I don't know if a configuration class brings much over just having setters on the handler itself. Anyway I'd rather have a plan for 2.0 before adding things to 1.x, just so we can avoid introducing future BC breaks where not needed. |
slightly offtopic, but will then 2.0 make such projects like monolog-cascade obsolete as it provides itself some kind of config support? |
Ok I'm gonna abandon the broader changes to all constructors as it doesn't seem worth the breakage. Would be great if this PR can be updated to the latest version of the SlackHandler with all current parameters and taking into account that some getters/setters already exist. If someone can do this I'm up for adding it either in 1.x branch or master for the upcoming 2.0 |
b9e6b87
to
2d75a3e
Compare
2d75a3e
to
c9d15bb
Compare
I think I've updated this correctly now. It's a bit longer because all of the calls need to be passed down to the |
@EspadaV8 Sorry but can you rebase on latest master? I'll try and get this merged quickly once that's done :s |
The current slack handler has way too many constructor parameters and no clear order as to their position. This makes it confusing to work out what is actually trying to be set when constructing a new class, e.g,
This PR makes things a bit easier by adding some fluent setters into the class.
It would be nice to cut back the number of constructor parameters and reorder them to make a bit more sense
Since that would be a fairly major breaking change though I've not included it in this PR. If it would be okay to do in another PR I'll open one up for it.
I've included scalar type hints for the methods because the file include the
declare(strict_types=1);
which is only valid for PHP7 so I assume that is okay. If not then I can easily remove them.