| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App; |
| 4 |
|
| 5 |
use FluentCart\Api\StoreSettings; |
| 6 |
use FluentCart\App\Modules\PaymentMethods\Core\GatewayManager; |
| 7 |
use FluentCart\App\Modules\PaymentMethods\Core\PaymentGatewayInterface; |
| 8 |
use FluentCart\Framework\Foundation\App as AppFacade; |
| 9 |
|
| 10 |
/** |
| 11 |
* Class App |
| 12 |
* |
| 13 |
* @method static \FluentCart\Framework\Http\Request\Request request() Get the current request instance. |
| 14 |
* @method static \FluentCart\Framework\Database\DatabaseManager db() |
| 15 |
* @method static \FluentCart\Framework\Http\Response\Response response() |
| 16 |
* @method static \FluentCart\Framework\View\View view() |
| 17 |
* @method static \FluentCart\Framework\Foundation\Config config() |
| 18 |
*/ |
| 19 |
|
| 20 |
|
| 21 |
/** |
| 22 |
* @method static \FluentCart\Framework\Database\Query\WPDBConnection db() |
| 23 |
*/ |
| 24 |
|
| 25 |
class App extends AppFacade |
| 26 |
{ |
| 27 |
public static function slug(): string |
| 28 |
{ |
| 29 |
return static::config()->get('app.slug'); |
| 30 |
} |
| 31 |
|
| 32 |
public static function route(): \FluentCart\Framework\Http\Route |
| 33 |
{ |
| 34 |
return static::request()->route(); |
| 35 |
} |
| 36 |
|
| 37 |
public static function call($action, array $parameters = []) |
| 38 |
{ |
| 39 |
return static::getInstance()->call( |
| 40 |
$action, |
| 41 |
$parameters |
| 42 |
); |
| 43 |
} |
| 44 |
|
| 45 |
public static function storeSettings(): StoreSettings |
| 46 |
{ |
| 47 |
$cached = wp_cache_get(StoreSettings::CACHE_KEY, StoreSettings::CACHE_GROUP); |
| 48 |
if ($cached instanceof StoreSettings) { |
| 49 |
return $cached; |
| 50 |
} |
| 51 |
|
| 52 |
$storeSettings = new StoreSettings(); |
| 53 |
wp_cache_set(StoreSettings::CACHE_KEY, $storeSettings, StoreSettings::CACHE_GROUP); |
| 54 |
|
| 55 |
return $storeSettings; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Get the payment gateway manager or a specific gateway |
| 60 |
* |
| 61 |
* @param string|null $gatewayName Optional gateway name to retrieve directly |
| 62 |
* @return GatewayManager|PaymentGatewayInterface|null |
| 63 |
*/ |
| 64 |
public static function gateway(?string $gatewayName = null) |
| 65 |
{ |
| 66 |
$gatewayManager = static::getInstance('gateway'); |
| 67 |
|
| 68 |
// If gateway name is provided, return the specific gateway |
| 69 |
if ($gatewayName !== null) { |
| 70 |
return $gatewayManager->get($gatewayName); |
| 71 |
} |
| 72 |
|
| 73 |
// Otherwise return the manager instance |
| 74 |
return $gatewayManager; |
| 75 |
} |
| 76 |
|
| 77 |
public static function isProActive(): bool |
| 78 |
{ |
| 79 |
return defined('FLUENTCART_PRO_PLUGIN_VERSION'); |
| 80 |
} |
| 81 |
|
| 82 |
public static function doingRestRequest(): bool |
| 83 |
{ |
| 84 |
if (defined('REST_REQUEST') && REST_REQUEST) { |
| 85 |
return true; |
| 86 |
} |
| 87 |
|
| 88 |
// Fallback: check URL for /wp-json/ |
| 89 |
$rest_prefix = trailingslashit(rest_get_url_prefix()); |
| 90 |
if (isset($_SERVER['REQUEST_URI'])) { |
| 91 |
$request_uri = sanitize_text_field(wp_unslash($_SERVER['REQUEST_URI'])); |
| 92 |
if (strpos($request_uri, $rest_prefix) !== false) { |
| 93 |
return true; |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
return false; |
| 98 |
} |
| 99 |
|
| 100 |
public static function isDevMode(): bool |
| 101 |
{ |
| 102 |
return static::config()->get('env') === 'dev'; |
| 103 |
} |
| 104 |
|
| 105 |
public static function localization() |
| 106 |
{ |
| 107 |
return static::getInstance('localization'); |
| 108 |
} |
| 109 |
} |
| 110 |
|