Guest User

Untitled

a guest
Jan 16th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. public function __construct(Request $request){
  2. $this->startGameSession($request);
  3. }
  4.  
  5. Catchable Fatal Error: Argument 1 passed to MyController::__construct() must be an instance of SymfonyComponentHttpFoundationRequest, none given...
  6.  
  7. namespace AppBundleController;
  8.  
  9. use SymfonyBundleFrameworkBundleControllerController;
  10. use SymfonyComponentHttpFoundationRequestStack;
  11.  
  12. class ServiceController extends Controller
  13. {
  14. public function __construct(RequestStack $requestStack)
  15. {
  16. //do something with $requestStack->getCurrentRequest();
  17. }
  18. }
  19.  
  20. # app/config/services.yml
  21. services:
  22. service_controller:
  23. class: AppBundleControllerServiceController
  24. arguments: ['@request_stack']
  25.  
  26. # app/config/routing.yml
  27. index:
  28. path: /index
  29. defaults: { _controller: service_controller:indexAction }
  30.  
  31. use SymfonyComponentHttpFoundationRequest;
  32.  
  33. namespace SymfonyComponentHttpKernelControllerControllerResolver;
  34.  
  35. ...
  36.  
  37. public function getController(Request $request)
  38. {
  39. if (!$controller = $request->attributes->get('_controller')) {
  40. if (null !== $this->logger) {
  41. $this->logger->warning('Unable to look for the controller as the "_controller" parameter is missing.');
  42. }
  43.  
  44. return false;
  45. }
  46.  
  47. if (is_array($controller)) {
  48. return $controller;
  49. }
  50.  
  51. if (is_object($controller)) {
  52. if (method_exists($controller, '__invoke')) {
  53. return $controller;
  54. }
  55.  
  56. throw new InvalidArgumentException(sprintf('Controller "%s" for URI "%s" is not callable.', get_class($controller), $request->getPathInfo()));
  57. }
  58.  
  59. if (false === strpos($controller, ':')) {
  60. if (method_exists($controller, '__invoke')) {
  61. return $this->instantiateController($controller);
  62. } elseif (function_exists($controller)) {
  63. return $controller;
  64. }
  65. }
  66.  
  67. $callable = $this->createController($controller);
  68.  
  69. if (!is_callable($callable)) {
  70. throw new InvalidArgumentException(sprintf('The controller for URI "%s" is not callable. %s', $request->getPathInfo(), $this->getControllerError($callable)));
  71. }
  72.  
  73. return $callable;
  74. }
  75.  
  76. namespace AppBundleController;
  77.  
  78. use SymfonyBundleFrameworkBundleControllerController;
  79. use SymfonyComponentHttpFoundationRequestStack;
  80.  
  81. class MyController extends Controller
  82. {
  83. public function __construct(RequestStack $requestStack)
  84. {
  85. $request = $requestStack->getCurrentRequest();
  86. //do something with the $request
  87.  
  88. }
  89. }
Add Comment
Please, Sign In to add comment