Not allow null value for cache default_ttl
tolean opened this issue · 6 comments
Description
Have an error when try to set null value for cache config default_ttl.
Cache plugin support null value https://docs.php-http.org/en/latest/plugins/cache.html?highlight=cache#semantics-of-null-values
but bundle configuration except an integer value
Error message:
Invalid type for path "httplug.clients.***.plugins.0.cache.config.default_ttl". Expected "int", but got "null".
Hint: The default max age of a Response
How to reproduce
httplug:
clients:
bo_inner_api:
factory: 'httplug.factory.symfony'
plugins:
- cache:
cache_pool: my_custom_cache_pull
config:
default_ttl: null
respect_response_cache_directives: []
hi @tolean, hm, what is the reason to set the default_ttl to null
? can't you omit the configuration completely when you don't want to set it? we don't have a default value in the configuration, so not setting it at all should achieve what you want, no?
@dbu, if I omit this config, the default value from the cache plugin is applied, see https://github.com/php-http/cache-plugin/blob/9e4b50f8aea93720ca745cd81b6154bcb6713898/src/CachePlugin.php#L356
oh, thanks you are right, we need to support explicit null.
do you want to do a pull request for the Configuration.php class to allow that?
I'll be happy to fix it. Problem is here
But isn't clear for me how to make nullable numeric node
sorry, this went under. it looks like symfony integerNode can not be nullable. i think we need to change this to a scalarNode and then add a custom validation that says its either null
or is_int
is true, and mark it invalid if its anything else.
do you want to give that a try?