entityType; } public function getEntityId(): int { return $this->entityId; } /** @throws \InvalidArgumentException اگر محیط حل نشده باشد */ public function assignTenant(EntityContext $context): void { if (!$context->isResolved()) { throw new \InvalidArgumentException(sprintf( 'Cannot assign an unresolved tenant context to %s.', static::class, )); } [$this->entityType, $this->entityId] = $context->toEntityPair(); } /** * برای فراخوانی‌هایی که جفت را از قبل حل کرده‌اند و موجودیت را در دست ندارند — * مثل DiscountController که owner را به‌صورت اسکالر از resolveOwner می‌گیرد. * ساختن EntityContext از روی اسکالر ممکن نیست: چنین contextی isClinic() درست * می‌دهد ولی ->clinic تهی دارد و مصرف‌کننده را بی‌صدا می‌شکند. * * @throws \InvalidArgumentException اگر جفت معتبر نباشد */ public function assignTenantPair(string $entityType, int $entityId): void { if (!in_array($entityType, [EntityContext::TYPE_DOCTOR, EntityContext::TYPE_CLINIC], true) || $entityId <= 0) { throw new \InvalidArgumentException(sprintf( 'Invalid tenant pair (%s, %d) for %s.', $entityType, $entityId, static::class, )); } $this->entityType = $entityType; $this->entityId = $entityId; } }