-
Notifications
You must be signed in to change notification settings - Fork 5
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
Added default value to config #67
Conversation
87bc864
to
fd8fba6
Compare
I ended up following the second approach. I tested it by installing it in my application, because I couldn't come up with a solution for "integration test". Both Now, |
if (!is_null($uv)) { | ||
$this->data[$path] = $uv; | ||
return $this->data[$path]; | ||
} |
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.
it would be simpler to directly get the ParameterDefinition with $this->configurationManager->get($path); and read the default value (because here you already know you want the default value), and return it if not null
this make the getUserValue() changes not needed
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.
Hm... Now that I remember, I think I did it this way to transform the default value. Perhaps instead of overloading getUserValue
I should create a new getDefaultValue($path)
function. It would share most code with getUserValue
, but the parts that use those functions would be easier to understand
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, I think I understand now. I should get the raw value outside the getUserValue
function, and then call getUserValue($path, $rawDefaultValue)
to transform it.
- Changed variable names to camelCase - Simplified getting default values in ParameterManager - Reverted changes in ParameterManager->getUserValue
I think I solved all issues, is there anything missing? Anything else I should do to improve it? |
hi @daviddavo it seems good indeed ! |
I think you can also do it from GitHub online interface. There's a little arrow on the right of the green "Merge" button |
Related to #66
Furthermore, I'm trying to do an automatic unit test to test it, but I can't get it to work.
I'm trying to use
$this->container->get('sherlockode_configuration.parameter_manager');
but it tells meSymfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "doctrine.orm.entity_manager".
I don't know how to define the service in a bundle, I haven't worked much with symfony, and just with applications.
About how to implement the default values, as I consider it, there are the following approaches:
ParameterManager::loadParameters
so it loads parameters with a default value even if they don't appear in the repositoryget
andgetAll
to consider the case a parameter is not in the repository.get
, just check insidegetUserValue
if its null, and call the new$parameterDefinition->getDefaultValue()
method.getAll
, iterate through ConfigurationManager->getDefinedParameters, checking if its not already set in$this->data
.