-
Notifications
You must be signed in to change notification settings - Fork 50
expand configuration definition and adjust tests, closes #151 #155
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
expand configuration definition and adjust tests, closes #151 #155
Conversation
I opted to drop all default values for the config section in favor of letting the plugin handle those instead. Currently I have not yet figured out how to make it not default |
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.
thanks!
->end() | ||
->enumNode('cache_key_generator') | ||
->info('A class implementing Http\Client\Common\Plugin\Cache\Generator\CacheKeyGenerator to generate a PSR-6 cache key') | ||
->values([null, 'Http\Client\Common\Plugin\Cache\Generator\CacheKeyGenerator']) |
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.
please use CacheKeyGenerator::class instead (we are php 5.5 or later so its supported)
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.
No problem.
@stof any idea if I can get the config definition builder to somehow not force |
->scalarNode('default_ttl')->defaultValue(0)->end() | ||
->enumNode('cache_key_generator') | ||
->info('A class implementing '.CacheKeyGenerator::class.' to generate a PSR-6 cache key') | ||
->values([null, CacheKeyGenerator::class]) |
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.
this looks wrong to me. It does not allow passing custom generators anymore
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.
I don't know if it does an instanceof test or literal string comparison. I guess this needs work.
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.
enumNode is just this: an enum. So the value being configured must be one of the provided values. CacheKeyGenerator::class
is just a string. There is nothing about instanceof in string comparisons
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.
Dropped the validation in favor of letting the plugin itself handle it directly.
@@ -368,34 +370,61 @@ private function addSharedPluginNodes(ArrayNodeDefinition $pluginNode, $disableA | |||
->cannotBeEmpty() | |||
->end() | |||
->arrayNode('config') | |||
->addDefaultsIfNotSet() |
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.
if you remove this, you MUST check whether the config
key is defined in the DI extension before using it. Currently, the DI extension relies on the fact that the Configuration class ensures it is always defined, but your change means it is not the case anymore.
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.
Can you elaborate what you mean by this? I don't quite follow.
->scalarNode('cache_lifetime') | ||
->info('The minimum time we should store a cache item') | ||
->end() | ||
->scalarNode('default_ttl') |
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.
integer node looks even better to me for these
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's always been scalar, so I kept it scalar. Not sure why originally integer was not chosen o_O
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.
probably because support for Symfony 2.3 was needed in the past, which did not have the integer node yet.
->info('A class implementing '.CacheKeyGenerator::class.' to generate a PSR-6 cache key') | ||
->values([null, CacheKeyGenerator::class]) | ||
->end() | ||
->scalarNode('cache_lifetime') |
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.
why removing the default value ?
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.
See my first response on this PR.
<respect-response-cache-directives>X-Foo</respect-response-cache-directives> | ||
<respect-response-cache-directives>X-Bar</respect-response-cache-directives> | ||
<methods>GET</methods> | ||
<methods>HEAD</methods> |
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.
this is wrong. The XML tag should be named method
and we need to have the call ->fixXmlConfig('method')
on the parent node.
Prototyped nodes work a bit special in XML, due to the way child tags are handled when parsing XML in SimpleXML (if you put a single method with your current code, you will not get an array).
thus, the tag name will be better with a singular
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.
I'll look into this.
@@ -44,9 +44,11 @@ | |||
<my_service type="service" service="my_auth_service"/> | |||
</authentication> | |||
<cache cache-pool="my_cache_pool" stream-factory="my_other_stream_factory"> | |||
<config default-ttl="42"> | |||
<config default-ttl="42" cache-lifetime="2592000" hash-algo="sha1" cache-key-generator="null"> | |||
<respect-response-cache-directives>X-Foo</respect-response-cache-directives> | |||
<respect-response-cache-directives>X-Bar</respect-response-cache-directives> |
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.
this prototyped node is also broken in XML btw
@alcohol prototyped array nodes always have a default value (the empty array, unless you override it). |
I resorted to just providing the default value instead. I think that is the easiest approach without having to implement too many work-arounds or do all sorts of additional checks. |
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.
thanks for this!
the integerNode was probably caused by me not being aware of that and having seen scalarNode from previous work - i think we did not actually have this work with symfony 2.3 at any point.
->end() | ||
->children() | ||
->scalarNode('cache_key_generator') | ||
->info('A class implementing '.CacheKeyGenerator::class.' to generate a PSR-6 cache key') |
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.
actually the cache plugin phpdoc is confusing on this one. if this option is set, it must contain an instance of CacheKeyGenerator. in symfony config that means it would be a service id.
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.
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.
So...
This must be a service id to a service implementing Http\Client\Common\Plugin\Cache\Generator\CacheKeyGenerator
?
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.
And then it means that the DI extension has to process the config to turn the id into a Reference object.
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.
Currently, the feature is just broken
exactly. if it is set at all - if its empty, the cache plugin creates an
object on its own.
|
Anything that still needs changing/modification? |
|
||
$config = $builder->root('config'); | ||
$config | ||
->fixXmlConfig('method') |
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.
@stof Should this be considered a BC btw?
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.
Well, as there is no XSD file, the existing XML config file will continue to work, for people lucky enough to have a working config before (it was broken when having a single method). And it will allow everyone to have a working config when using XML, for all cases.
Btw, it cannot be considered a BC
. The sentence should be considered a BC break
. The important work in this sentence is break
😄
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.
Thank you
I would like to point out that the official documentation at http://docs.php-http.org/en/latest/plugins/cache.html does not mention the
hash_algo
configuration option.