| 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: | * @internal |
| 27: | * |
| 28: | * @param TData $data |
| 29: | * @param class-string<Installed|Loader> $class |
| 30: | * @param mixed ...$args |
| 31: | */ |
| 32: | public function __construct( |
| 33: | $data, |
| 34: | string $class, |
| 35: | string $method, |
| 36: | ...$args |
| 37: | ) { |
| 38: | $this->Data = $data; |
| 39: | $this->Class = $class; |
| 40: | $this->Method = $method; |
| 41: | $this->Arguments = $args; |
| 42: | } |
| 43: | |
| 44: | /** |
| 45: | * Check if the given Composer runtime API method was called |
| 46: | * |
| 47: | * @param class-string<Installed|Loader> $class |
| 48: | */ |
| 49: | public function isMethod(string $class, string $method): bool |
| 50: | { |
| 51: | return strcasecmp($class, $this->Class) === 0 |
| 52: | && strcasecmp($method, $this->Method) === 0; |
| 53: | } |
| 54: | |
| 55: | /** |
| 56: | * Get arguments passed to the Composer runtime API when the method was |
| 57: | * called |
| 58: | * |
| 59: | * @return mixed[] |
| 60: | */ |
| 61: | public function getArguments(): array |
| 62: | { |
| 63: | return $this->Arguments; |
| 64: | } |
| 65: | |
| 66: | /** |
| 67: | * Get data received from the Composer runtime API |
| 68: | * |
| 69: | * @return TData |
| 70: | */ |
| 71: | public function getData() |
| 72: | { |
| 73: | return $this->Data; |
| 74: | } |
| 75: | |
| 76: | /** |
| 77: | * Replace data received from the Composer runtime API |
| 78: | * |
| 79: | * @param TData $data |
| 80: | */ |
| 81: | public function setData($data): void |
| 82: | { |
| 83: | $this->Data = $data; |
| 84: | } |
| 85: | } |
| 86: |