From 11c7d63c8189c028b091273148c52810b2171959 Mon Sep 17 00:00:00 2001 From: Hannes Van De Vreken Date: Wed, 24 Dec 2014 13:31:15 +0100 Subject: [PATCH] Make use of new resolvingType method --- src/Illuminate/Container/Container.php | 6 ++++- .../Contracts/Container/Container.php | 26 +++++++++++++++++++ .../Foundation/Http/FormRequest.php | 2 +- .../Providers/FormRequestServiceProvider.php | 14 ++++------ .../Validation/ValidationServiceProvider.php | 9 +++---- 5 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/Illuminate/Container/Container.php b/src/Illuminate/Container/Container.php index 5e7be82740d5..8fbf5e603c49 100755 --- a/src/Illuminate/Container/Container.php +++ b/src/Illuminate/Container/Container.php @@ -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 */ @@ -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 */ @@ -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 diff --git a/src/Illuminate/Contracts/Container/Container.php b/src/Illuminate/Contracts/Container/Container.php index 400afe373a09..d39386837d9c 100644 --- a/src/Illuminate/Contracts/Container/Container.php +++ b/src/Illuminate/Contracts/Container/Container.php @@ -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); + } diff --git a/src/Illuminate/Foundation/Http/FormRequest.php b/src/Illuminate/Foundation/Http/FormRequest.php index b7612719fa7b..cbd371ae7b44 100644 --- a/src/Illuminate/Foundation/Http/FormRequest.php +++ b/src/Illuminate/Foundation/Http/FormRequest.php @@ -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) { diff --git a/src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php b/src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php index 0dabe292b187..33e49eaf780e 100644 --- a/src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php +++ b/src/Illuminate/Foundation/Providers/FormRequestServiceProvider.php @@ -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']); }); }); } diff --git a/src/Illuminate/Validation/ValidationServiceProvider.php b/src/Illuminate/Validation/ValidationServiceProvider.php index f121efb9c0ff..728634acc5f1 100755 --- a/src/Illuminate/Validation/ValidationServiceProvider.php +++ b/src/Illuminate/Validation/ValidationServiceProvider.php @@ -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(); }); }