1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Utility\Event; |
4: | |
5: | use Composer\Autoload\ClassLoader as Loader; |
6: | use Composer\InstalledVersions as Installed; |
7: | |
8: | /** |
9: | * Dispatched when package data is received from the Composer runtime API |
10: | * |
11: | * @api |
12: | * |
13: | * @template TData |
14: | */ |
15: | final class PackageDataReceivedEvent |
16: | { |
17: | /** @var TData */ |
18: | private $Data; |
19: | /** @var class-string<Installed|Loader> */ |
20: | private string $Class; |
21: | private string $Method; |
22: | /** @var mixed[] */ |
23: | private array $Arguments; |
24: | |
25: | /** |
26: | * @param TData $data |
27: | * @param class-string<Installed|Loader> $class |
28: | * @param mixed ...$args |
29: | */ |
30: | public function __construct( |
31: | $data, |
32: | string $class, |
33: | string $method, |
34: | ...$args |
35: | ) { |
36: | $this->Data = $data; |
37: | $this->Class = $class; |
38: | $this->Method = $method; |
39: | $this->Arguments = $args; |
40: | } |
41: | |
42: | /** |
43: | * Check if the given Composer runtime API method was called |
44: | * |
45: | * @param class-string<Installed|Loader> $class |
46: | */ |
47: | public function isMethod(string $class, string $method): bool |
48: | { |
49: | return strcasecmp($class, $this->Class) === 0 |
50: | && strcasecmp($method, $this->Method) === 0; |
51: | } |
52: | |
53: | /** |
54: | * Get arguments passed to the Composer runtime API when the method was |
55: | * called |
56: | * |
57: | * @return mixed[] |
58: | */ |
59: | public function getArguments(): array |
60: | { |
61: | return $this->Arguments; |
62: | } |
63: | |
64: | /** |
65: | * Get data received from the Composer runtime API |
66: | * |
67: | * @return TData |
68: | */ |
69: | public function getData() |
70: | { |
71: | return $this->Data; |
72: | } |
73: | |
74: | /** |
75: | * Replace data received from the Composer runtime API |
76: | * |
77: | * @param TData $data |
78: | */ |
79: | public function setData($data): void |
80: | { |
81: | $this->Data = $data; |
82: | } |
83: | } |
84: |