Page MenuHomePhorge

Base.php
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

Base.php

<?php
namespace App\Handlers;
abstract class Base
{
/**
* The entitleable class for this handler.
*
* @return string
*/
public static function entitleableClass(): string
{
return '';
}
/**
* Check if the SKU is available to the user. An SKU is available
* to the user when either it is active or there's already an
* active entitlement.
*
* @param \App\Sku $sku The SKU object
* @param \App\User $user The user object
*
* @return bool
*/
public static function isAvailable(\App\Sku $sku, \App\User $user): bool
{
if (!$sku->active) {
if (!$user->entitlements()->where('sku_id', $sku->id)->first()) {
return false;
}
}
return true;
}
/**
* Metadata of this SKU handler.
*
* @param \App\Sku $sku The SKU object
*
* @return array
*/
public static function metadata(\App\Sku $sku): array
{
$handler = explode('\\', static::class);
$handler = strtolower(end($handler));
$type = explode('\\', static::entitleableClass());
$type = strtolower(end($type));
return [
// entitleable type
'type' => $type,
// handler (as a keyword)
'handler' => $handler,
// readonly entitlement state cannot be changed
'readonly' => false,
// is entitlement enabled by default?
'enabled' => false,
// priority on the entitlements list
'prio' => static::priority(),
];
}
/**
* Prerequisites for the Entitlement to be applied to the object.
*
* @param \App\Entitlement $entitlement
* @param mixed $object
*
* @return bool
*/
public static function preReq($entitlement, $object): bool
{
$type = static::entitleableClass();
if (empty($type) || empty($entitlement->entitleable_type)) {
\Log::error("Entitleable class/type not specified");
return false;
}
if ($type !== $entitlement->entitleable_type) {
\Log::error("Entitleable class mismatch");
return false;
}
if (!$entitlement->sku->active) {
\Log::error("Sku not active");
return false;
}
return true;
}
/**
* The priority that specifies the order of SKUs in UI.
* Higher number means higher on the list.
*
* @return int
*/
public static function priority(): int
{
return 0;
}
}

File Metadata

Mime Type
text/x-php
Expires
Mon, Apr 6, 1:57 AM (1 w, 8 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
43/0a/6acef648a843bfa54e57d11fe300
Default Alt Text
Base.php (2 KB)

Event Timeline