Changeset View
Changeset View
Standalone View
Standalone View
src/app/Entitlement.php
<?php | <?php | ||||
namespace App; | namespace App; | ||||
use App\Traits\UuidStrKeyTrait; | use App\Traits\UuidStrKeyTrait; | ||||
use Illuminate\Database\Eloquent\Model; | use Illuminate\Database\Eloquent\Model; | ||||
use Illuminate\Database\Eloquent\SoftDeletes; | use Illuminate\Database\Eloquent\SoftDeletes; | ||||
/** | /** | ||||
* The eloquent definition of an Entitlement. | * The eloquent definition of an Entitlement. | ||||
* | * | ||||
* Owned by a {@link \App\User}, billed to a {@link \App\Wallet}. | * Owned by a {@link \App\User}, billed to a {@link \App\Wallet}. | ||||
* | * | ||||
* @property int $cost | * @property int $cost | ||||
* @property ?string $description | * @property ?string $description | ||||
* @property \App\Domain|\App\User $entitleable The entitled object (receiver of the entitlement). | * @property ?object $entitleable The entitled object (receiver of the entitlement). | ||||
* @property int $entitleable_id | * @property int $entitleable_id | ||||
* @property string $entitleable_type | * @property string $entitleable_type | ||||
* @property int $fee | * @property int $fee | ||||
* @property string $id | * @property string $id | ||||
* @property \App\User $owner The owner of this entitlement (subject). | * @property \App\User $owner The owner of this entitlement (subject). | ||||
* @property \App\Sku $sku The SKU to which this entitlement applies. | * @property \App\Sku $sku The SKU to which this entitlement applies. | ||||
* @property string $sku_id | * @property string $sku_id | ||||
* @property \App\Wallet $wallet The wallet to which this entitlement is charged. | * @property \App\Wallet $wallet The wallet to which this entitlement is charged. | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | class Entitlement extends Model | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function entitleable() | public function entitleable() | ||||
{ | { | ||||
return $this->morphTo()->withTrashed(); // @phpstan-ignore-line | return $this->morphTo()->withTrashed(); // @phpstan-ignore-line | ||||
} | } | ||||
/** | /** | ||||
* Returns entitleable object title (e.g. email or domain name). | |||||
* | |||||
* @return string|null An object title/name | |||||
*/ | |||||
public function entitleableTitle(): ?string | |||||
{ | |||||
if ($this->entitleable instanceof Domain) { | |||||
return $this->entitleable->namespace; | |||||
} | |||||
return $this->entitleable->email; | |||||
} | |||||
/** | |||||
* Simplified Entitlement/SKU information for a specified entitleable object | * Simplified Entitlement/SKU information for a specified entitleable object | ||||
* | * | ||||
* @param object $object Entitleable object | * @param object $object Entitleable object | ||||
* | * | ||||
* @return array Skus list with some metadata | * @return array Skus list with some metadata | ||||
*/ | */ | ||||
public static function objectEntitlementsSummary($object): array | public static function objectEntitlementsSummary($object): array | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |