| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Yatra\Compatibility; |
| 6 |
|
| 7 |
/** |
| 8 |
* Compatibility Manager (Loader) |
| 9 |
* |
| 10 |
* This file is intentionally small: it conditionally loads and registers |
| 11 |
* compatibility handlers (Elementor, etc.) from subfolders. |
| 12 |
* |
| 13 |
* Folder convention: |
| 14 |
* - app/Compatibility/Elementor/Assets.php |
| 15 |
* - app/Compatibility/SomePlugin/Assets.php |
| 16 |
*/ |
| 17 |
final class Compatibility |
| 18 |
{ |
| 19 |
/** |
| 20 |
* Register all compatibility handlers. |
| 21 |
*/ |
| 22 |
public static function register(): void |
| 23 |
{ |
| 24 |
if (is_admin()) { |
| 25 |
return; |
| 26 |
} |
| 27 |
|
| 28 |
foreach (self::handlers() as $handler) { |
| 29 |
$file = $handler['file'] ?? ''; |
| 30 |
$class = $handler['class'] ?? ''; |
| 31 |
|
| 32 |
if (!is_string($file) || $file === '' || !is_string($class) || $class === '') { |
| 33 |
continue; |
| 34 |
} |
| 35 |
|
| 36 |
if (file_exists($file)) { |
| 37 |
require_once $file; |
| 38 |
} |
| 39 |
|
| 40 |
if (!class_exists($class)) { |
| 41 |
continue; |
| 42 |
} |
| 43 |
|
| 44 |
// Handlers expose register(): void (and can self-check plugin presence) |
| 45 |
if (is_callable([$class, 'register'])) { |
| 46 |
try { |
| 47 |
$class::register(); |
| 48 |
} catch (\Throwable $e) { |
| 49 |
// Never break frontend due to optional integrations. |
| 50 |
continue; |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* @return array<int,array{file:string,class:string}> |
| 58 |
*/ |
| 59 |
private static function handlers(): array |
| 60 |
{ |
| 61 |
$base = defined('YATRA_PLUGIN_PATH') ? rtrim((string) YATRA_PLUGIN_PATH, '/\\') . '/app/Compatibility/' : ''; |
| 62 |
if ($base === '') { |
| 63 |
return []; |
| 64 |
} |
| 65 |
|
| 66 |
return [ |
| 67 |
[ |
| 68 |
'file' => $base . 'Elementor/Assets.php', |
| 69 |
'class' => 'Yatra\\Compatibility\\Elementor\\Assets', |
| 70 |
], |
| 71 |
[ |
| 72 |
'file' => $base . 'LiteSpeed/Assets.php', |
| 73 |
'class' => 'Yatra\\Compatibility\\LiteSpeed\\Assets', |
| 74 |
], |
| 75 |
[ |
| 76 |
'file' => $base . 'Wanderland/Header.php', |
| 77 |
'class' => 'Yatra\\Compatibility\\Wanderland\\Header', |
| 78 |
], |
| 79 |
]; |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
|