> */ private $subjects = []; /** @var array */ private $subjectKeyClassMap = []; /** @param Subject[] $subjects */ public function __construct( Automation $automation, Step $step, array $subjects ) { $this->automation = $automation; $this->step = $step; foreach ($subjects as $subject) { $key = $subject->getKey(); $this->subjects[$key] = $subject; $this->subjectKeyClassMap[get_class($subject)] = $key; } } public function getAutomation(): Automation { return $this->automation; } public function getStep(): Step { return $this->step; } /** @return Subject[] */ public function getSubjects(): array { return array_values($this->subjects); } /** @return Subject */ public function getSingleSubject(string $key): Subject { $subject = $this->subjects[$key] ?? null; if (!$subject) { throw Exceptions::subjectNotFound($key); } return $subject; } /** * @template P of Payload * @template S of Subject

* @param class-string $class * @return S

*/ public function getSingleSubjectByClass(string $class): Subject { $key = $this->subjectKeyClassMap[$class] ?? null; if (!$key) { throw Exceptions::subjectClassNotFound($class); } /** @var S

$subject -- for PHPStan */ $subject = $this->getSingleSubject($key); return $subject; } }