Skip to content

Provide Symfony HttpCache as trait #233

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
Oct 24, 2015
Merged

Provide Symfony HttpCache as trait #233

merged 1 commit into from
Oct 24, 2015

Conversation

ddeboer
Copy link
Member

@ddeboer ddeboer commented Aug 2, 2015

Fix #191, fix #238.

  • Provide event dispatching HttpCache as trait
  • Move debug header code to a subscriber
  • Unit tests for debug subscriber
  • Update docs. mention the unit test for event dispatching kernel, should be used whenever using this kernel. and actually most custom extensions to HttpCache should probably be done as event subscribers in this scenario, to keep things understandable.

@ddeboer ddeboer changed the title Provide Symfony HttpCache as trait [WIP] Provide Symfony HttpCache as trait Aug 2, 2015
@ddeboer ddeboer force-pushed the httpcache-trait branch 2 times, most recently from a01685f to 4390ce1 Compare August 2, 2015 11:43
*
* {@inheritDoc}
*/
public function fetch(Request $request, $catch = false)
Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately, we have to add this method here. If I put this in the trait, I get:

Fatal error: Access level to Symfony\Component\HttpKernel\HttpCache\HttpCache::fetch() must be public (as in class FOS\HttpCache\SymfonyCache\CacheInvalidationInterface) in /vagrant/FOSHttpCache/tests/Functional/Fixtures/Symfony/AppCache.php on line 12

Copy link
Contributor

Choose a reason for hiding this comment

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

strange that a trait can't change visibility of a method - or is there a way that would allow it?

Copy link
Contributor

Choose a reason for hiding this comment

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

so actually it does change visibility but there seems to be some bug with interface vs trait somewhere: http://stackoverflow.com/questions/31877844/php-trait-exposing-a-method-and-interfaces

Copy link
Contributor

Choose a reason for hiding this comment

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

@stof this is the solution i came up with, because of the problem i explain on stackoverflow. its annoying but i guess its really a bug (or illogic decision) of traits vs interfaces.

@dbu
Copy link
Contributor

dbu commented Aug 3, 2015

very cool! this will get us rid of a lot of duplication needs.

@dbu
Copy link
Contributor

dbu commented Aug 7, 2015

@ddeboer i investigated a bit and at least found a workaround, albeit not an elegant one. there is one test reliably failing now: SymfonyProxyClientTest::testRefresh

i have to leave now, if you want to further investigate, please do.

@dbu dbu force-pushed the httpcache-trait branch from eafa519 to 34619f1 Compare August 7, 2015 12:44
{
// http://stackoverflow.com/questions/31877844/php-trait-exposing-a-method-and-interfaces
use EventDispatchingHttpCache {fetch as public eventTriggeringFetch;}
Copy link
Member

Choose a reason for hiding this comment

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

is it needed to be public ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

none of this is calling eventTriggeringFetch

Copy link
Contributor

@dbu dbu Aug 19, 2015 via email

Choose a reason for hiding this comment

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

@dbu dbu modified the milestone: 2.0 Aug 15, 2015
@dbu dbu force-pushed the httpcache-trait branch 2 times, most recently from 8ebab9c to b46b7d1 Compare August 17, 2015 07:28
*/
private function dispatchPostHandle(Request $request, Response $response)
protected function dispatch($name, Request $request, Response $response = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

made this protected so that kernels using the trait can also use it, if they need to expand on a method and still need the pre and post event.

@dbu dbu force-pushed the httpcache-trait branch from b46b7d1 to fb17058 Compare August 17, 2015 07:39
@dbu
Copy link
Contributor

dbu commented Aug 17, 2015

so this would be ready for a code review. doc is missing and some unit tests for the debug subscriber.

@dbu dbu force-pushed the httpcache-trait branch from fb17058 to e7295ef Compare August 19, 2015 07:22
@dbu
Copy link
Contributor

dbu commented Aug 19, 2015

@lolautruche can you or somebody else at ez have a look at this? it will affect ez i think, as you use the symfony http cache. i hope its an improvement. BC might be a bit tricky however - but then supporting both FOSHttpCache 1.x and 2.x would be really tricky i think, hope you do not need that.

@ddeboer
Copy link
Member Author

ddeboer commented Sep 30, 2015

@dbu Thanks for fixing the test failure. Can you squash your commits?

@lolautruche Will this change become a problem for eZ? Please keep in mind this change will only make it to the 2.0 version of the library.

@dbu dbu changed the title [WIP] Provide Symfony HttpCache as trait Provide Symfony HttpCache as trait Sep 30, 2015
@dbu
Copy link
Contributor

dbu commented Sep 30, 2015

squashed and rebased. lets give @lolautruche a few more days to have a look at this before merging.

*
* <b>When using FOSHttpCacheBundle, look at FOS\HttpCacheBundle\HttpCache instead.</b>
* Your kernel needs to implement CacheInvalidatorInterface and redeclare the
* fetch method as public. (The later is needed because the trait declaring it
Copy link
Contributor

Choose a reason for hiding this comment

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

s/later/latter

@lolautruche
Copy link
Contributor

Hi

AFAICS, we can be able to use the trait without any hassle for the end developer since we rely on our own abstract HttpCache. We'd do the change here to use the trait, which is fine since we require PHP 5.4+.
As for v2.0 of FOSHttpCache, any ETA? I also need to look into the changelog to be sure our usage is not broken 😉 .

Thanks for noticing (and sorry for the delay).

@lolautruche
Copy link
Contributor

Ping @andrerom for review as well

@dbu
Copy link
Contributor

dbu commented Sep 30, 2015 via email

@lolautruche
Copy link
Contributor

i think we need to wait for php-http

You mean the PHP extension?

@dbu
Copy link
Contributor

dbu commented Sep 30, 2015

@lolautruche no, this thing: http://php-http.readthedocs.org/en/latest/ - it will get a more unique name soon as php-http is not google-friendly.

@lolautruche
Copy link
Contributor

Ah OK, cool

@andrerom
Copy link
Contributor

Ping @andrerom for review as well

Looks ok for me, sensible to move this into trait anyway.

i think we need to wait for php-http (a http client abstraction so that
we don't depend on any specific implementation like a specific guzzle
version) to stabilize before we can call FOSHttpCache stable

makes perfect sense for 2.0

Side: @dbu / @ddeboer any chance of some feedback on the abstract tagging (#237) direction so we can have at least some abstraction in 2.0 to build upon for Sf HttpCache improvements? Me and @lolautruche have a need to work on this topic over the next month, we can't really wait much longer on this topic.

@dbu
Copy link
Contributor

dbu commented Sep 30, 2015

thanks. so lets get this merged.

@ddeboer any idea why hhvm fails: https://travis-ci.org/FriendsOfSymfony/FOSHttpCache/jobs/82876644 ? i already restarted the test, so its not random failure. but it looks like a varnish config issue - but as its specifically hhvm this is strange.

@ddeboer
Copy link
Member Author

ddeboer commented Sep 30, 2015

It’s probably not the Varnish config per se, but HHVM not serving the responses correctly: I’m seeing 404s and 503s (backend fetch failed).

@dbu
Copy link
Contributor

dbu commented Oct 9, 2015

i just restarted the last build of master in https://travis-ci.org/FriendsOfSymfony/FriendsOfSymfony/FOSHttpCache/jobs/77916788

it now fails with the same pattern. i think this means that travis updated their hhvm and we see some regression. ok if we merge as-is and look into fixing hhvm in a separate pull request?

@dbu
Copy link
Contributor

dbu commented Oct 14, 2015

we see the same test failure on master as well. @ddeboer wdyt, should we just merge this? and would you have some time to look into what hhvm is unhappy about?

@dbu dbu force-pushed the httpcache-trait branch from 44ab065 to 9f689e9 Compare October 23, 2015 14:36
@dbu
Copy link
Contributor

dbu commented Oct 23, 2015

fixed the last typo from the comments. @ddeboer is it ok if we merge this? hhvm fails the same way as on master, so imho we should not block this merge. and fix hhvm against master, or disable it if we can't fix it.

ddeboer added a commit that referenced this pull request Oct 24, 2015
@ddeboer ddeboer merged commit d501d01 into master Oct 24, 2015
@ddeboer ddeboer deleted the httpcache-trait branch October 24, 2015 16:21
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.

debug subscriber for symfony http cache Symfony HttpCache trait instead of class
5 participants