Skip to content

Commit 98a52b8

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 98a52b8

File tree

2 files changed

+369
-4
lines changed

2 files changed

+369
-4
lines changed

src/Illuminate/Container/Container.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,13 @@ public function bind($abstract, $concrete = null, $shared = false)
256256
*/
257257
protected function getClosure($abstract, $concrete)
258258
{
259-
return function ($container, $parameters = []) use ($abstract, $concrete) {
259+
return function (Container $container, $parameters = []) use ($abstract, $concrete) {
260260
if ($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->resolveSilent($concrete, $parameters);
265266
};
266267
}
267268

@@ -633,6 +634,19 @@ public function get($id)
633634
* @return mixed
634635
*/
635636
protected function resolve($abstract, $parameters = [])
637+
{
638+
$this->resolveSilent($abstract, $parameters, false);
639+
}
640+
641+
/**
642+
* Resolve the given type from the container.
643+
*
644+
* @param string $abstract
645+
* @param array $parameters
646+
* @param bool $silent
647+
* @return mixed
648+
*/
649+
private function resolveSilent($abstract, $parameters = [], $silent = true)
636650
{
637651
$abstract = $this->getAlias($abstract);
638652

@@ -674,8 +688,9 @@ protected function resolve($abstract, $parameters = [])
674688
$this->instances[$abstract] = $object;
675689
}
676690

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

0 commit comments

Comments
 (0)