githubtrue/backend/vendor/illuminate/container/ContextualBindingBuilder.php @ f24e2d9d
1 |
<?php
|
---|---|
2 |
|
3 |
namespace Illuminate\Container; |
4 |
|
5 |
use Illuminate\Contracts\Container\ContextualBindingBuilder as ContextualBindingBuilderContract; |
6 |
|
7 |
class ContextualBindingBuilder implements ContextualBindingBuilderContract |
8 |
{
|
9 |
/**
|
10 |
* The underlying container instance.
|
11 |
*
|
12 |
* @var \Illuminate\Container\Container
|
13 |
*/
|
14 |
protected $container; |
15 |
|
16 |
/**
|
17 |
* The concrete instance.
|
18 |
*
|
19 |
* @var string
|
20 |
*/
|
21 |
protected $concrete; |
22 |
|
23 |
/**
|
24 |
* The abstract target.
|
25 |
*
|
26 |
* @var string
|
27 |
*/
|
28 |
protected $needs; |
29 |
|
30 |
/**
|
31 |
* Create a new contextual binding builder.
|
32 |
*
|
33 |
* @param \Illuminate\Container\Container $container
|
34 |
* @param string $concrete
|
35 |
* @return void
|
36 |
*/
|
37 |
public function __construct(Container $container, $concrete) |
38 |
{
|
39 |
$this->concrete = $concrete; |
40 |
$this->container = $container; |
41 |
}
|
42 |
|
43 |
/**
|
44 |
* Define the abstract target that depends on the context.
|
45 |
*
|
46 |
* @param string $abstract
|
47 |
* @return $this
|
48 |
*/
|
49 |
public function needs($abstract) |
50 |
{
|
51 |
$this->needs = $abstract; |
52 |
|
53 |
return $this; |
54 |
}
|
55 |
|
56 |
/**
|
57 |
* Define the implementation for the contextual binding.
|
58 |
*
|
59 |
* @param \Closure|string $implementation
|
60 |
* @return void
|
61 |
*/
|
62 |
public function give($implementation) |
63 |
{
|
64 |
$this->container->addContextualBinding($this->concrete, $this->needs, $implementation); |
65 |
}
|
66 |
}
|