Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Illuminate/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,8 @@ public function afterResolvingAny(Closure $callback)
}

/**
* Register a new resolving callback for a given type or one of its subtypes.
*
* @param $type
* @param callable $callback
*/
Expand All @@ -974,6 +976,8 @@ public function resolvingType($type, Closure $callback)
}

/**
* Register a new after resolving callback for a given type or one of its subtypes.
*
* @param $type
* @param callable $callback
*/
Expand Down Expand Up @@ -1014,7 +1018,7 @@ protected function fireResolvingCallbacks($abstract, $object)
}

/**
* Get all callbacks for a givne type.
* Get all callbacks for a given type.
*
* @param object $object
* @param array $callbacksPerType
Expand Down
26 changes: 26 additions & 0 deletions src/Illuminate/Contracts/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,30 @@ public function resolving($abstract, Closure $callback);
*/
public function resolvingAny(Closure $callback);

/**
* Register a new resolving callback for a given type or one of its subtypes.
*
* @param string $abstract
* @param \Closure $callback
* @return void
*/
public function resolvingType($abstract, Closure $callback);

/**
* Register a new after resolving callback for all types.
*
* @param \Closure $callback
* @return void
*/
public function afterResolvingAny(Closure $callback);

/**
* Register a new after resolving callback for a given type or one of its subtypes.
*
* @param string $abstract
* @param \Closure $callback
* @return void
*/
public function afterResolvingType($abstract, Closure $callback);

}
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Http/FormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public function setRedirector(Redirector $redirector)
* Set the container implementation.
*
* @param \Illuminate\Container\Container $container
* @return $this
* @return \Illuminate\Foundation\Http\FormRequest
*/
public function setContainer(Container $container)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,14 @@ public function boot()
{
$this->app['events']->listen('router.matched', function()
{
$this->app->resolvingAny(function($resolved, $app)
$this->app->resolvingType('Illuminate\Foundation\Http\FormRequest', function(FormRequest $resolved, $app)
{
// If the resolved instance is an instance of the FormRequest object, we will go
// ahead and initialize the request as well as set a few dependencies on this
// Initialize the request as well as set a few dependencies on this
// request instance. The "ValidatesWhenResolved" hook will fire "validate".
if ($resolved instanceof FormRequest)
{
$this->initializeRequest($resolved, $app['request']);
$this->initializeRequest($resolved, $app['request']);

$resolved->setContainer($app)
->setRedirector($app['Illuminate\Routing\Redirector']);
}
$resolved->setContainer($app)
->setRedirector($app['Illuminate\Routing\Redirector']);
});
});
}
Expand Down
9 changes: 4 additions & 5 deletions src/Illuminate/Validation/ValidationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ public function register()
*/
protected function registerValidationResolverHook()
{
$this->app->afterResolvingAny(function($resolved)
$type = 'Illuminate\Contracts\Validation\ValidatesWhenResolved';

$this->app->afterResolvingType($type, function(ValidatesWhenResolved $resolved)
{
if ($resolved instanceof ValidatesWhenResolved)
{
$resolved->validate();
}
$resolved->validate();
});
}

Expand Down