Skip to content

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

Merged
merged 1 commit into from
May 2, 2017
Merged

expand configuration definition and adjust tests, closes #151 #155

merged 1 commit into from
May 2, 2017

Conversation

alcohol
Copy link
Contributor

@alcohol alcohol commented Apr 26, 2017

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related tickets fixes #151
License MIT

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.

@Nyholm Nyholm self-requested a review April 26, 2017 08:23
@alcohol
Copy link
Contributor Author

alcohol commented Apr 26, 2017

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 methods to an empty array though. This is still a work in progress.

Copy link
Collaborator

@dbu dbu left a 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'])
Copy link
Collaborator

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem.

@alcohol
Copy link
Contributor Author

alcohol commented Apr 26, 2017

@stof any idea if I can get the config definition builder to somehow not force methods to always present in the final tree? Only option I see at the moment is to replace prototyped array node with a variable node :-\

->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])
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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()
Copy link
Contributor

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.

Copy link
Contributor Author

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')
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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')
Copy link
Contributor

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 ?

Copy link
Contributor Author

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>
Copy link
Contributor

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

Copy link
Contributor Author

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>
Copy link
Contributor

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

@stof
Copy link
Contributor

stof commented Apr 26, 2017

@alcohol prototyped array nodes always have a default value (the empty array, unless you override it).
What you could do is treating an empty array in a special way when using the config in the DI extension.

@alcohol
Copy link
Contributor Author

alcohol commented Apr 26, 2017

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.

Copy link
Collaborator

@dbu dbu left a 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')
Copy link
Collaborator

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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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

?

Copy link
Contributor

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.

Copy link
Contributor

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

@dbu
Copy link
Collaborator

dbu commented Apr 26, 2017 via email

@alcohol
Copy link
Contributor Author

alcohol commented Apr 28, 2017

Anything that still needs changing/modification?


$config = $builder->root('config');
$config
->fixXmlConfig('method')
Copy link
Contributor Author

@alcohol alcohol Apr 28, 2017

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?

Copy link
Contributor

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 😄

Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Thank you

@Nyholm Nyholm merged commit 79070d6 into php-http:master May 2, 2017
@alcohol alcohol deleted the expand-cache-plugin-configuration branch May 2, 2017 07:09
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.

Allow more cache config
4 participants