Skip to content
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

add cmf_request_aware tag #37

Merged
merged 3 commits into from
May 15, 2013
Merged

add cmf_request_aware tag #37

merged 3 commits into from
May 15, 2013

Conversation

dbu
Copy link
Member

@dbu dbu commented May 15, 2013

once this is good, we can fix #35

@dbu
Copy link
Member Author

dbu commented May 15, 2013

i think this leads to the services being instantiated on each request. unless there is some event on service instantiation that we can listen to, i see no way we can avoid that however. maybe we need to document to only use this tag for basic things that are needed in most requests anyways.

otherwise one can always revert to inject the container and get the request from it...

}

foreach ($this->services as $service) {
if (method_exists($service, 'setRequest')) {
Copy link
Member

Choose a reason for hiding this comment

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

i dont think that we need this check

Copy link
Member Author

Choose a reason for hiding this comment

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

copied like this from https://github.com/KnpLabs/KnpMenuBundle/blob/master/EventListener/VoterInitializerListener.php - the problem is if its not there, we get a fatal error. but chances are we get a fatal error anyways later when the service tries to access a request that is null. will remove it.

@lsmith77
Copy link
Member

yes .. this listener only makes sense for things that are needed in every (sub)request anyway


public function onKernelRequest(GetResponseEvent $event)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
Copy link
Member

Choose a reason for hiding this comment

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

don't we also need to do this for subrequests?

Copy link
Member Author

Choose a reason for hiding this comment

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

@stof does it like this in https://github.com/KnpLabs/KnpMenuBundle/blob/master/EventListener/VoterInitializerListener.php - i am not sure what makes sense. our listeners so far want to look into the mainContent of the request - i guess that is not there on sub requests?

Copy link
Member

Choose a reason for hiding this comment

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

well the key question is if this affects any services that run in a subrequest .. aren't menu's rendered in subrequests?

Copy link
Member Author

Choose a reason for hiding this comment

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

no they are rendered with a twig function. but one way to work around performance issues would be to make that piece an ESI block to cache it, so its definitely a scenario. but then i don't know how it would work in a sub request. not sure if its even possible to have the master request and a sub request in the same context or if a new one is started anyways.

we could just drop the check here and say if a service only wants the master request, it could make its setter not overwrite the request if its already set. i guess its safe to assume the master request is always the first one...

Copy link
Member

Choose a reason for hiding this comment

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

hmm but we cannot rely on the menu to be rendered in the master request .. but yeah running this for every subrequest might be too much .. :(

@dbu
Copy link
Member Author

dbu commented May 15, 2013

at least the sandbox still works when removing the check if its the master request, so i guess its good for now.

@dbu
Copy link
Member Author

dbu commented May 15, 2013

maybe this could be a use case for the super lazy service instantiation thing added in symfony 2.3... but lets optimize later.

lsmith77 added a commit that referenced this pull request May 15, 2013
@lsmith77 lsmith77 merged commit 7c07fe1 into master May 15, 2013
@lsmith77 lsmith77 deleted the add-request-aware-tag branch May 15, 2013 11:13
@dantleech
Copy link
Member

I want to say "tests" here, should this stuff really be exempt because 3 classes are DI and the other one is so simple?

@dbu
Copy link
Member Author

dbu commented May 22, 2013

imo unit tests make no sense here, but functional tests would make a lot of sense for this.

@dantleech
Copy link
Member

From my pov unit tests always make sense because there part of my development process, I write the test as I write the code to ensure that the code works, often without testing in the browser at all.

If I were to work on this listener, I would write a test for it to prove that it worked. Having tests for all classes also ensures that people who contribute to the same classes in the future also have to expand the existing test, proving that their change works too. It also helps to focus on architecture and to generally be more mindful of the code.

Sorry if that sounds like a rant, its not, I'm just +1 for testing all classes in general. Its debatable in this case I know.

@dbu
Copy link
Member Author

dbu commented May 22, 2013

you take TDD seriously i see. i will try to find some time to do this.
in general we need to go over the bundles and add tests, then it will be
more natural to not add anything untested...

@dantleech
Copy link
Member

Not sure if I do TDD, rather test aided development :) Don't go out of your way to do it on my account, as you say we will go over all the bundles before 1.0 anyway.

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.

Why pass request object to ->checkIsPublishable?
3 participants