Skip to content

Commit

Permalink
Extract provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Dec 19, 2016
1 parent 893a044 commit b892805
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 78 deletions.
16 changes: 5 additions & 11 deletions src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ class ArtisanServiceProvider extends ServiceProvider
*/
public function register()
{
$this->registerCommands($this->commands);

$this->registerCommands($this->devCommands);
$this->registerCommands(array_merge(
$this->commands, $this->devCommands
));
}

/**
Expand All @@ -128,9 +128,7 @@ public function register()
protected function registerCommands(array $commands)
{
foreach (array_keys($commands) as $command) {
$method = "register{$command}Command";

call_user_func_array([$this, $method], []);
call_user_func_array([$this, "register{$command}Command"], []);
}

$this->commands(array_values($commands));
Expand Down Expand Up @@ -611,10 +609,6 @@ protected function registerNotificationTableCommand()
*/
public function provides()
{
if ($this->app->environment('production')) {
return array_values($this->commands);
} else {
return array_merge(array_values($this->commands), array_values($this->devCommands));
}
return array_merge(array_values($this->commands), array_values($this->devCommands));
}
}
67 changes: 67 additions & 0 deletions src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Illuminate\Foundation\Providers;

use Illuminate\Routing\Redirector;
use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\Http\FormRequest;
use Symfony\Component\HttpFoundation\Request;
use Illuminate\Contracts\Validation\ValidatesWhenResolved;

class FormRequestServiceProvider extends ServiceProvider
{
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
//
}

/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
$this->app->afterResolving(function (ValidatesWhenResolved $resolved) {
$resolved->validate();
});

$this->app->resolving(function (FormRequest $request, $app) {
$this->initializeRequest($request, $app['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()
);

if ($session = $current->getSession()) {
$form->setSession($session);
}

$form->setUserResolver($current->getUserResolver());

$form->setRouteResolver($current->getRouteResolver());
}
}
74 changes: 7 additions & 67 deletions src/Illuminate/Foundation/Providers/FoundationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,16 @@

namespace Illuminate\Foundation\Providers;

use Illuminate\Routing\Redirector;
use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\Http\FormRequest;
use Symfony\Component\HttpFoundation\Request;
use Illuminate\Contracts\Validation\ValidatesWhenResolved;
use Illuminate\Support\AggregateServiceProvider;

class FoundationServiceProvider extends ServiceProvider
class FoundationServiceProvider extends AggregateServiceProvider
{
/**
* Register the service provider.
* The provider class names.
*
* @return void
* @var array
*/
public function register()
{
//
}

/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
$this->configureFormRequests();
}

/**
* Configure the form request related services.
*
* @return void
*/
protected function configureFormRequests()
{
$this->app->afterResolving(function (ValidatesWhenResolved $resolved) {
$resolved->validate();
});

$this->app->resolving(function (FormRequest $request, $app) {
$this->initializeRequest($request, $app['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()
);

if ($session = $current->getSession()) {
$form->setSession($session);
}

$form->setUserResolver($current->getUserResolver());

$form->setRouteResolver($current->getRouteResolver());
}
protected $providers = [
'Illuminate\Foundation\Providers\FormRequestServiceProvider',
];
}

0 comments on commit b892805

Please sign in to comment.