diff --git a/src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php b/src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php index 8dc2912aa81e..dac0d1580875 100644 --- a/src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php +++ b/src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php @@ -32,38 +32,9 @@ public function boot() }); $this->app->resolving(FormRequest::class, function ($request, $app) { - $this->initializeRequest($request, $app['request']); + $request = FormRequest::createFrom($app['request'], $request); $request->setContainer($app)->setRedirector($app->make(Redirector::class)); }); } - - /** - * Initialize the form request with data from the given request. - * - * @param \Illuminate\Foundation\Http\FormRequest $form - * @param \Symfony\Component\HttpFoundation\Request $current - * @return void - */ - protected function initializeRequest(FormRequest $form, Request $current) - { - $files = $current->files->all(); - - $files = is_array($files) ? array_filter($files) : $files; - - $form->initialize( - $current->query->all(), $current->request->all(), $current->attributes->all(), - $current->cookies->all(), $files, $current->server->all(), $current->getContent() - ); - - $form->setJson($current->json()); - - if ($session = $current->getSession()) { - $form->setLaravelSession($session); - } - - $form->setUserResolver($current->getUserResolver()); - - $form->setRouteResolver($current->getRouteResolver()); - } } diff --git a/src/Illuminate/Http/Request.php b/src/Illuminate/Http/Request.php index 4ffd1b599db9..8a87729dc871 100644 --- a/src/Illuminate/Http/Request.php +++ b/src/Illuminate/Http/Request.php @@ -343,6 +343,39 @@ protected function getInputSource() return $this->getRealMethod() == 'GET' ? $this->query : $this->request; } + /** + * Create a new request instance from the given Laravel request. + * + * @param \Illuminate\Http\Request $from + * @param \Illuminate\Http\Request|null $to + * @return static + */ + public static function createFrom(Request $from, $to = null) + { + $request = $to ?: new static; + + $files = $from->files->all(); + + $files = is_array($files) ? array_filter($files) : $files; + + $request->initialize( + $from->query->all(), $from->request->all(), $from->attributes->all(), + $from->cookies->all(), $files, $from->server->all(), $from->getContent() + ); + + $request->setJson($from->json()); + + if ($session = $from->getSession()) { + $request->setLaravelSession($session); + } + + $request->setUserResolver($from->getUserResolver()); + + $request->setRouteResolver($from->getRouteResolver()); + + return $request; + } + /** * Create an Illuminate request from a Symfony instance. *