EmailNotifier::class, NotificationType::TYPE_POPUP => PopupNotifier::class ]; protected static function create(string $type, array $params = []): ICanNotify { if (!isset(static::$map[$type])) { throw new InvalidArgumentException("Нет обработчика типа $type."); } return Yii::createObject(static::$map[$type], $params); } public function getNotifiers(array $types): array { $notifiers = []; foreach ($types as $type) { $notifiers[] = $this->create($type); } return $notifiers; } public static function getChatNotifier(int $senderId): ICanNotify { return new ChatNotifier(new PopupNotifier([ 'sender_id' => $senderId, 'category' => Notification::CATEGORY_CHAT, ])); } }