| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Services\ShortCodeParser\Parsers; |
| 4 |
|
| 5 |
use FluentCart\Framework\Support\Arr; |
| 6 |
|
| 7 |
class LicenseParser extends BaseParser |
| 8 |
{ |
| 9 |
private $license; |
| 10 |
|
| 11 |
public function __construct($data) |
| 12 |
{ |
| 13 |
$this->license = Arr::get($data, 'license'); |
| 14 |
parent::__construct($data); |
| 15 |
} |
| 16 |
|
| 17 |
public function parse($accessor = null, $code = null, $transformer = null): ?string |
| 18 |
{ |
| 19 |
$license = $this->license; |
| 20 |
|
| 21 |
if (!$license) { |
| 22 |
return ''; |
| 23 |
} |
| 24 |
|
| 25 |
switch ($accessor) { |
| 26 |
case 'sl': |
| 27 |
return (string) (isset($license->sl) ? $license->sl : ''); |
| 28 |
case 'key': |
| 29 |
return esc_html($license->license_key); |
| 30 |
case 'status': |
| 31 |
return esc_html($license->status); |
| 32 |
case 'product_name': |
| 33 |
return esc_html($license->product ? $license->product->post_title : ''); |
| 34 |
case 'variant': |
| 35 |
return esc_html($license->productVariant ? $license->productVariant->variation_title : ''); |
| 36 |
case 'limit': |
| 37 |
return $license->limit ? esc_html($license->limit) : __('Unlimited', 'fluent-cart'); |
| 38 |
case 'activation_count': |
| 39 |
return esc_html($license->activation_count); |
| 40 |
case 'expiration_date': |
| 41 |
return $license->expiration_date |
| 42 |
? esc_html(date('M j, Y', strtotime($license->expiration_date))) |
| 43 |
: __('Never', 'fluent-cart'); |
| 44 |
default: |
| 45 |
return Arr::get((array) $license, $accessor, ''); |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|