PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.5
1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk All 48 releases
fluent-cart / app / Services / ShortCodeParser / Parsers / LicenseParser.php

LicenseParser.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.5, at app/Services/ShortCodeParser/Parsers/LicenseParser.php

58 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Services\ShortCodeParser\Parsers;
4
5 use FluentCart\App\Services\DateTime\DateFormatter;
6 use FluentCart\Framework\Support\Arr;
7
8 class LicenseParser extends BaseParser
9 {
10 private $license;
11
12 /**
13 * Only used as the timezone context for DateFormatter — the order carries the
14 * user_tz captured at checkout. Null when the shortcode runs without one, in
15 * which case DateFormatter falls back to UTC.
16 */
17 private $order;
18
19 public function __construct($data)
20 {
21 $this->license = Arr::get($data, 'license');
22 $this->order = Arr::get($data, 'order');
23 parent::__construct($data);
24 }
25
26 public function parse($accessor = null, $code = null, $transformer = null): ?string
27 {
28 $license = $this->license;
29
30 if (!$license) {
31 return '';
32 }
33
34 switch ($accessor) {
35 case 'sl':
36 return (string) (isset($license->sl) ? $license->sl : '');
37 case 'key':
38 return esc_html($license->license_key);
39 case 'status':
40 return esc_html($license->status);
41 case 'product_name':
42 return esc_html($license->product ? $license->product->post_title : '');
43 case 'variant':
44 return esc_html($license->productVariant ? $license->productVariant->variation_title : '');
45 case 'limit':
46 return $license->limit ? esc_html($license->limit) : __('Unlimited', 'fluent-cart');
47 case 'activation_count':
48 return esc_html($license->activation_count);
49 case 'expiration_date':
50 return $license->expiration_date
51 ? esc_html(DateFormatter::format($license->expiration_date, false, $this->order))
52 : __('Never', 'fluent-cart');
53 default:
54 return Arr::get((array) $license, $accessor, '');
55 }
56 }
57 }
58