-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAfterBuildEvent.php
More file actions
68 lines (57 loc) · 2.41 KB
/
AfterBuildEvent.php
File metadata and controls
68 lines (57 loc) · 2.41 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
61
62
63
64
65
66
67
68
<?php
declare( strict_types = 1 );
namespace TheWebSolver\Codegarage\Container\Event;
use Closure;
use Psr\EventDispatcher\StoppableEventInterface;
use TheWebSolver\Codegarage\Container\Container;
use TheWebSolver\Codegarage\Container\Pool\CollectionStack;
use TheWebSolver\Codegarage\Container\Traits\StopPropagation;
use TheWebSolver\Codegarage\Container\Interfaces\TaggableEvent;
/** @template TResolved */
class AfterBuildEvent implements StoppableEventInterface, TaggableEvent {
use StopPropagation;
/**
* @param CollectionStack<string,class-string<TResolved>|Closure(TResolved $resolved, Container $app): TResolved> $decorators
* @param CollectionStack<string,Closure(TResolved $resolved, Container $app): void> $updaters
*/
public function __construct(
private readonly Container $app,
private readonly string $entry,
private readonly CollectionStack $decorators = new CollectionStack(),
private readonly CollectionStack $updaters = new CollectionStack()
) {}
public function app(): Container {
return $this->app;
}
/** @return CollectionStack<string,class-string<TResolved>|(Closure(TResolved $resolved, Container $app): TResolved)> */
public function getDecorators(): CollectionStack {
return $this->decorators;
}
/** @return CollectionStack<string,Closure(TResolved $resolved, Container $app): void> */
public function getUpdaters(): CollectionStack {
return $this->updaters;
}
/**
* Decorates resolved value with decorator currently being registered.
*
* @param class-string<TResolved>|(Closure(TResolved $resolved, Container $app): TResolved) $decorator The decorator can be:
* - a Closure that accepts the resolved value as first argument and container as second, or
* - a classname that accepts the resolved value as first argument.
*/
public function decorateWith( string|Closure $decorator ): self {
$this->decorators->set( key: $this->entry, value: $decorator );
return $this;
}
/**
* Updates the resolved value with the given callback currently being registered.
*
* @param Closure(TResolved, Container): void $with Recommended to type-hint first parameter's value to
* resolved type instead of `mixed` for IDE support.
*/
public function update( Closure $with ): void {
$this->updaters->set( key: $this->entry, value: $with );
}
public function getEntry(): string {
return $this->entry;
}
}