Skip to content

Commit df0e44b

Browse files
committed
Add missing tests for the resolving callbacks on the container
+ bug fix related to multiple calls to "resolving" and "afterResolving" callbacks
1 parent d329797 commit df0e44b

File tree

4 files changed

+364
-9
lines changed

4 files changed

+364
-9
lines changed

src/Illuminate/Container/Container.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ protected function getClosure($abstract, $concrete)
261261
return $container->build($concrete);
262262
}
263263

264-
return $container->make($concrete, $parameters);
264+
// To prevent extra call to resolving callbacks, we make the object silently.
265+
return $container->make($concrete, $parameters, true);
265266
};
266267
}
267268

@@ -602,11 +603,12 @@ public function makeWith($abstract, array $parameters = [])
602603
*
603604
* @param string $abstract
604605
* @param array $parameters
606+
* @param bool $silent
605607
* @return mixed
606608
*/
607-
public function make($abstract, array $parameters = [])
609+
public function make($abstract, array $parameters = [], $silent = false)
608610
{
609-
return $this->resolve($abstract, $parameters);
611+
return $this->resolve($abstract, $parameters, $silent);
610612
}
611613

612614
/**
@@ -630,9 +632,10 @@ public function get($id)
630632
*
631633
* @param string $abstract
632634
* @param array $parameters
635+
* @param bool $silent
633636
* @return mixed
634637
*/
635-
protected function resolve($abstract, $parameters = [])
638+
protected function resolve($abstract, $parameters = [], $silent = false)
636639
{
637640
$abstract = $this->getAlias($abstract);
638641

@@ -674,8 +677,9 @@ protected function resolve($abstract, $parameters = [])
674677
$this->instances[$abstract] = $object;
675678
}
676679

677-
$this->fireResolvingCallbacks($abstract, $object);
678-
680+
if (! $silent) {
681+
$this->fireResolvingCallbacks($abstract, $object);
682+
}
679683
// Before returning, we will also set the resolved flag to "true" and pop off
680684
// the parameter overrides for this build. After those two things are done
681685
// we will be ready to return back the fully constructed class instance.

src/Illuminate/Contracts/Container/Container.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function factory($abstract);
113113
* @param array $parameters
114114
* @return mixed
115115
*/
116-
public function make($abstract, array $parameters = []);
116+
public function make($abstract, array $parameters = [], $silent);
117117

118118
/**
119119
* Call the given Closure / class@method and inject its dependencies.

src/Illuminate/Foundation/Application.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,17 +722,18 @@ public function registerDeferredProvider($provider, $service = null)
722722
*
723723
* @param string $abstract
724724
* @param array $parameters
725+
* @param bool $silent
725726
* @return mixed
726727
*/
727-
public function make($abstract, array $parameters = [])
728+
public function make($abstract, array $parameters = [], $silent = false)
728729
{
729730
$abstract = $this->getAlias($abstract);
730731

731732
if (isset($this->deferredServices[$abstract]) && ! isset($this->instances[$abstract])) {
732733
$this->loadDeferredProvider($abstract);
733734
}
734735

735-
return parent::make($abstract, $parameters);
736+
return parent::make($abstract, $parameters, $silent);
736737
}
737738

738739
/**

0 commit comments

Comments
 (0)