Skip to content

Commit 52d6a31

Browse files
daniserSergey Danilchenko
andauthored
[12.x] Infinite method chaining in contextual binding builder (#57026)
Co-authored-by: Sergey Danilchenko <[email protected]>
1 parent f32dc03 commit 52d6a31

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/Illuminate/Container/ContextualBindingBuilder.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,26 @@ public function needs($abstract)
5757
* Define the implementation for the contextual binding.
5858
*
5959
* @param \Closure|string|array $implementation
60-
* @return void
60+
* @return $this
6161
*/
6262
public function give($implementation)
6363
{
6464
foreach (Util::arrayWrap($this->concrete) as $concrete) {
6565
$this->container->addContextualBinding($concrete, $this->needs, $implementation);
6666
}
67+
68+
return $this;
6769
}
6870

6971
/**
7072
* Define tagged services to be used as the implementation for the contextual binding.
7173
*
7274
* @param string $tag
73-
* @return void
75+
* @return $this
7476
*/
7577
public function giveTagged($tag)
7678
{
77-
$this->give(function ($container) use ($tag) {
79+
return $this->give(function ($container) use ($tag) {
7880
$taggedServices = $container->tagged($tag);
7981

8082
return is_array($taggedServices) ? $taggedServices : iterator_to_array($taggedServices);
@@ -86,10 +88,10 @@ public function giveTagged($tag)
8688
*
8789
* @param string $key
8890
* @param mixed $default
89-
* @return void
91+
* @return $this
9092
*/
9193
public function giveConfig($key, $default = null)
9294
{
93-
$this->give(fn ($container) => $container->get('config')->get($key, $default));
95+
return $this->give(fn ($container) => $container->get('config')->get($key, $default));
9496
}
9597
}

src/Illuminate/Contracts/Container/ContextualBindingBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ public function needs($abstract);
1616
* Define the implementation for the contextual binding.
1717
*
1818
* @param \Closure|string|array $implementation
19-
* @return void
19+
* @return $this
2020
*/
2121
public function give($implementation);
2222

2323
/**
2424
* Define tagged services to be used as the implementation for the contextual binding.
2525
*
2626
* @param string $tag
27-
* @return void
27+
* @return $this
2828
*/
2929
public function giveTagged($tag);
3030

@@ -33,7 +33,7 @@ public function giveTagged($tag);
3333
*
3434
* @param string $key
3535
* @param mixed $default
36-
* @return void
36+
* @return $this
3737
*/
3838
public function giveConfig($key, $default = null);
3939
}

0 commit comments

Comments
 (0)