Search code examples
symfonyfosrestbundle

Symfony Request Object not being Injected in FosRest nested controller


I'm having an issue with Symphony not injecting the Request object when specified in my controller, my code is as follows:

Routing.yml:

user:
  type: rest
  resource: AppBundle\Controller\UserController

user_comments:
  type: rest
  parent: user
  resource: AppBundle\Controller\UserCommentsController

And FosRest Controller

namespace AppBundle\Controller;

use Symfony\Component\HttpFoundation\Request;

class UserCommentsController extends BaseRestController
{

    public function postCommentAction(Request $request, $userId)
    {
        var_dump($request);

        return $this->view($userId, 201);
    }

My App doesn't respond at all to the route, however when I remove Request $request from postCommentAction it works as expected (but obviously I don't have access to the Request object).

dev.log:

[2015-05-29 10:32:21] request.INFO: Matched route "post_user_comment" (parameters: "_controller": "AppBundle\Controller\UserCommentController::postCommentAction", "_format": "null", "userId": "a2fecac6-b7f6-4e00-8d03-989a9ee0973a", "_route": "post_user_comment") [] []
[2015-05-29 10:32:21] security.INFO: Attempting simple pre-authorization secured_area [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "Nelmio\CorsBundle\EventListener\CorsListener::onKernelRequest". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DumpListener::configure". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "FOS\RestBundle\EventListener\MimeTypeListener::onKernelRequest". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "FOS\RestBundle\EventListener\FormatListener::onKernelRequest". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "FOS\RestBundle\EventListener\BodyListener::onKernelRequest". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\TranslatorListener::onKernelRequest". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". [] []

Solution

  • Sorry everyone - issue was being caused by the var_dump($request) - a basic memory issue hidden in the VM, impressive considering PHP had access to ~512mb ram.