Skip to content

Commit 83c425b

Browse files
authored
allow simpler singleton binding syntax (#43469)
1 parent 9bc41c0 commit 83c425b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Illuminate/Foundation/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,8 @@ public function register($provider, $force = false)
696696

697697
if (property_exists($provider, 'singletons')) {
698698
foreach ($provider->singletons as $key => $value) {
699+
$key = is_int($key) ? $value : $key;
700+
699701
$this->singleton($key, $value);
700702
}
701703
}

tests/Foundation/FoundationApplicationTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public function testSingletonsAreCreatedWhenServiceProviderIsRegistered()
6767
$app->register($provider = new class($app) extends ServiceProvider
6868
{
6969
public $singletons = [
70+
NonContractBackedClass::class,
7071
AbstractClass::class => ConcreteClass::class,
7172
];
7273
});
@@ -77,6 +78,11 @@ public function testSingletonsAreCreatedWhenServiceProviderIsRegistered()
7778

7879
$this->assertInstanceOf(ConcreteClass::class, $instance);
7980
$this->assertSame($instance, $app->make(AbstractClass::class));
81+
82+
$instance = $app->make(NonContractBackedClass::class);
83+
84+
$this->assertInstanceOf(NonContractBackedClass::class, $instance);
85+
$this->assertSame($instance, $app->make(NonContractBackedClass::class));
8086
}
8187

8288
public function testServiceProvidersAreCorrectlyRegisteredWhenRegisterMethodIsNotFilled()
@@ -613,6 +619,11 @@ class ConcreteClass extends AbstractClass
613619
//
614620
}
615621

622+
class NonContractBackedClass
623+
{
624+
//
625+
}
626+
616627
class ConcreteTerminator
617628
{
618629
public static $counter = 0;

0 commit comments

Comments
 (0)