ClosureBuilder.php
1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* Closure-based builder.
*
* @package lucatume\DI52
*
* @license GPL-3.0
* Modified by learndash on 06-June-2023 using Strauss.
* @see https://github.com/BrianHenryIE/strauss
*/
namespace StellarWP\Learndash\lucatume\DI52\Builders;
use Closure;
use StellarWP\Learndash\lucatume\DI52\Container;
/**
* Class ClosureBuilder
*
* @package StellarWP\Learndash\lucatume\DI52\Builders
*/
class ClosureBuilder implements BuilderInterface
{
/**
* A reference to the resolver currently using the builder.
*
* @var Container
*/
protected $container;
/**
* A reference to the closure the builder should run to build.
*
* @var Closure
*/
protected $closure;
/**
* ClosureBuilder constructor.
*
* @param Container $container A reference to the current DI container instance.
* @param Closure $closure A reference to the closure that should be used to build the implementation.
*/
public function __construct(Container $container, Closure $closure)
{
$this->container = $container;
$this->closure = $closure;
}
/**
* Calls the Closure handled by the builder to return the built implementation.
*
* @return mixed The built implementation.
*/
public function build()
{
$closure = $this->closure;
return $closure($this->container);
}
}