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

Config Object #14

Merged
merged 44 commits into from
May 10, 2020
Merged

Config Object #14

merged 44 commits into from
May 10, 2020

Conversation

l0gicgate
Copy link
Member

@l0gicgate l0gicgate commented May 1, 2020

I think that it's probably easier to start with this base versus rewriting #13 entirely.

We have quite a few decisions to make at this particular moment in regards to this:

  • Validation seems clunky, I need input to see if there's an easier way to do this.
  • Default values / Required Values
  • Do we give the option of setting parameters on the fly on the configuration object? Is this necessary? In which case would you need to change parameters on the config at runtime. I almost feel like the setters are unnecessary
  • Same goes for the AbstractCommand object, setting the Application's configuration object from within a command seems like an anti-pattern, so I did not include it. I did include a getter though because I think it could be needed.
  • Error message formats. We need to nail those down
  • We need to define what can be extensible in user land. I feel like Application and Configuration should be extensible. The use case I imagine is a highly customizable console which just blends in with your project versus being standalone for Slim. This goes with the idea that we are allowing users to include external commands. I made the APPLICATION_NAME and VERSION constants protected so one could extend them easily to override them. Let me know what y'all think

Note:
This is mostly untested code and it's just so we can nail down the initial objects. Once we are in agreement I will write the tests.

Progress:

  • Initial Implementation
  • Make decisions
  • Write tests

Closes #6

@l0gicgate l0gicgate added this to the 0.1 milestone May 1, 2020
@l0gicgate l0gicgate mentioned this pull request May 1, 2020
3 tasks
@l0gicgate l0gicgate requested review from ABGEO and adriansuter and removed request for ABGEO May 1, 2020 21:16
@adriansuter
Copy link
Collaborator

adriansuter commented May 1, 2020

I would move the call to validation into the Config constructor? Otherwise someone could construct a Config with invalid params.

@l0gicgate
Copy link
Member Author

l0gicgate commented May 1, 2020

@adriansuter a way to mitigate that would be to make the constructor protected, what do you think? Also, could you show an example of an invalid configuration? Since all the constructor parameters are typed. I suppose you could do a white space string but that would be pretty dumb.

@adriansuter
Copy link
Collaborator

Yes, but we should avoid those dumb (sometimes unintended) errors, shouldn't we?

The setters can be removed, in my opinion. I don't see an example usage - and if needed, they could be added later on.

I have a naming question. Is it Configuration or Config? After all, it is Application and not App.

@l0gicgate
Copy link
Member Author

@adriansuter right. I think that maybe we should rename Application to App instead that would be more cohesive with the main Slim repo right?

I’ll remove the setters and make the constructor protected!

@ABGEO
Copy link
Collaborator

ABGEO commented May 2, 2020

* Validation seems clunky, I need input to see if there's an easier way to do this.

What do you think about Symfony Validator? Using this component we can easily validate the config object.

* I almost feel like the setters are unnecessary

I agreed. I think setters and unsetters are not needed. I have no idea when we would like to change the configuration at runtime.

bin/slim Outdated Show resolved Hide resolved
src/App.php Show resolved Hide resolved
src/App.php Outdated Show resolved Hide resolved
src/Config/CannotResolveConfigurationException.php Outdated Show resolved Hide resolved
src/Config/Config.php Outdated Show resolved Hide resolved
src/Config/Config.php Outdated Show resolved Hide resolved
src/Config/Config.php Outdated Show resolved Hide resolved
src/Config/ConfigResolver.php Outdated Show resolved Hide resolved
src/Config/ConfigResolver.php Outdated Show resolved Hide resolved
src/Config/ConfigResolver.php Outdated Show resolved Hide resolved
@flangofas
Copy link
Collaborator

flangofas commented May 2, 2020

@l0gicgate
One more question to add to the decision list.

  1. Where is the executable slim going to be placed:
    a. In the usual vendor/bin/slim
    b. In the project's root directory
    c. installed globally as @ABGEO07 suggested in Implement config object #13

a makes more sense to me because then config directory can be resolved and used also as project's root directory which is passed to ConfigResolver's constructor (This is currently missing in this draft)

@flangofas
Copy link
Collaborator

  • Same goes for the AbstractCommand object, setting the Application's configuration object from within a command seems like an anti-pattern, so I did not include it. I did include a getter though because I think it could be needed.

The idea was to provide the ability to commands to change the config object if needed. You are right, it seems anti-pattern indeed.

@l0gicgate
Copy link
Member Author

@ABGEO07

What do you think about Symfony Validator? Using this component we can easily validate the config object.

I'm not opposed to it considering we're already using two symfony packages, it would keep dependencies cohesive. My question here is, how much validation are we going to be doing, if the answer is more then it makes sense. Otherwise I'd like to stay away from including too many librairies.

I want to pick your brain about global usage, how do we detect global usage sanely? I'm guessing we would use something like getcwd() to establish the rootDir right?

@l0gicgate l0gicgate marked this pull request as ready for review May 8, 2020 21:44
@l0gicgate l0gicgate requested a review from adriansuter May 8, 2020 21:44
@l0gicgate
Copy link
Member Author

@adriansuter I just wrote all the tests for this. It's a pretty big PR, sorry.

Please review when you have time.

@adriansuter
Copy link
Collaborator

@l0gicgate Config::fromDefaults() is a good solution.

I will try to find some time.

Copy link
Collaborator

@adriansuter adriansuter left a comment

Choose a reason for hiding this comment

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

Wow, that was huge. Great work, @l0gicgate - all the tests are amazing.

By the way, shouldn't your homepage in composer.json have https?

bin/slim Outdated Show resolved Hide resolved
composer.json Outdated Show resolved Hide resolved
src/Command/AbstractCommand.php Outdated Show resolved Hide resolved
src/Config/Config.php Outdated Show resolved Hide resolved
src/Config/Config.php Show resolved Hide resolved
src/Config/Parser/PHPConfigParser.php Show resolved Hide resolved
src/Config/Parser/PHPConfigParser.php Outdated Show resolved Hide resolved
tests/examples/php/slim-console.config.php Show resolved Hide resolved
tests/examples/invalid-php/invalid-format.php Show resolved Hide resolved
tests/Mocks/MockCommand.php Outdated Show resolved Hide resolved
Copy link
Collaborator

@adriansuter adriansuter left a comment

Choose a reason for hiding this comment

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

@l0gicgate You're a rocket.

Two minor changes (type hints). Other than that, I think we are good to go.

src/Config/ConfigResolver.php Outdated Show resolved Hide resolved
src/Config/ConfigResolver.php Outdated Show resolved Hide resolved
@l0gicgate
Copy link
Member Author

Wow we did it y'all! Thank you @adriansuter @ABGEO @flangofas. First piece of the puzzle is getting merged!

@l0gicgate l0gicgate changed the title [WIP] Config Object Config Object May 10, 2020
@l0gicgate l0gicgate merged commit a5a6a81 into slimphp:0.x May 10, 2020
@l0gicgate l0gicgate deleted the Config branch May 10, 2020 17:54
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.

Configuration Object
4 participants