| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Yatra\Providers; |
| 6 |
|
| 7 |
use Yatra\Shortcodes\MyAccountShortcode; |
| 8 |
use Yatra\Shortcodes\TripShortcode; |
| 9 |
use Yatra\Shortcodes\ActivityShortcode; |
| 10 |
use Yatra\Shortcodes\DestinationShortcode; |
| 11 |
use Yatra\Shortcodes\TripCategoryShortcode; |
| 12 |
use Yatra\Shortcodes\DiscountAndDealsShortcode; |
| 13 |
use Yatra\Shortcodes\SearchShortcode; |
| 14 |
use Yatra\Shortcodes\LoginShortcode; |
| 15 |
use Yatra\Ajax\TripShortcodeAjax; |
| 16 |
use Yatra\Ajax\ActivityShortcodeAjax; |
| 17 |
use Yatra\Ajax\DestinationShortcodeAjax; |
| 18 |
use Yatra\Ajax\TripCategoryShortcodeAjax; |
| 19 |
use Yatra\Ajax\DiscountShortcodeAjax; |
| 20 |
use Yatra\Ajax\LoginAjax; |
| 21 |
use Yatra\Ajax\GeocodingAjax; |
| 22 |
|
| 23 |
/** |
| 24 |
* Shortcode Service Provider |
| 25 |
* |
| 26 |
* Registers all Yatra shortcodes |
| 27 |
*/ |
| 28 |
class ShortcodeServiceProvider extends \Yatra\Core\ServiceProvider |
| 29 |
{ |
| 30 |
/** |
| 31 |
* Register services with production optimizations |
| 32 |
*/ |
| 33 |
public function register(): void |
| 34 |
{ |
| 35 |
// Register all shortcodes immediately, not on init hook |
| 36 |
$this->registerShortcodes(); |
| 37 |
|
| 38 |
// Register AJAX handlers with error handling |
| 39 |
$this->registerAjaxHandlers(); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Register AJAX handlers with error handling and lazy loading |
| 44 |
*/ |
| 45 |
private function registerAjaxHandlers(): void |
| 46 |
{ |
| 47 |
$ajax_handlers = [ |
| 48 |
'TripShortcodeAjax', |
| 49 |
'ActivityShortcodeAjax', |
| 50 |
'DestinationShortcodeAjax', |
| 51 |
'TripCategoryShortcodeAjax', |
| 52 |
'DiscountShortcodeAjax', |
| 53 |
'LoginAjax', |
| 54 |
'GeocodingAjax', |
| 55 |
'DirectAttributeQuery', |
| 56 |
]; |
| 57 |
|
| 58 |
foreach ($ajax_handlers as $handler_class) { |
| 59 |
try { |
| 60 |
$full_class_name = "\\Yatra\\Ajax\\{$handler_class}"; |
| 61 |
|
| 62 |
if (class_exists($full_class_name)) { |
| 63 |
new $full_class_name(); |
| 64 |
} else { |
| 65 |
|
| 66 |
} |
| 67 |
} catch (Exception $e) { |
| 68 |
|
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Register all shortcodes with production optimizations |
| 75 |
*/ |
| 76 |
public function registerShortcodes(): void |
| 77 |
{ |
| 78 |
$shortcodes = [ |
| 79 |
'yatra_my_account' => MyAccountShortcode::class, |
| 80 |
'yatra_trip' => TripShortcode::class, |
| 81 |
'yatra_activity' => ActivityShortcode::class, |
| 82 |
'yatra_destination' => DestinationShortcode::class, |
| 83 |
'yatra_trip_category' => TripCategoryShortcode::class, |
| 84 |
'yatra_discount_and_deals' => DiscountAndDealsShortcode::class, |
| 85 |
'yatra_search' => SearchShortcode::class, |
| 86 |
'yatra_login' => LoginShortcode::class, |
| 87 |
]; |
| 88 |
|
| 89 |
foreach ($shortcodes as $tag => $class) { |
| 90 |
try { |
| 91 |
if (class_exists($class)) { |
| 92 |
$shortcode = new $class(); |
| 93 |
|
| 94 |
// Validate that the shortcode class has the register method |
| 95 |
if (method_exists($shortcode, 'register')) { |
| 96 |
$shortcode->register(); |
| 97 |
} else { |
| 98 |
|
| 99 |
} |
| 100 |
} else { |
| 101 |
|
| 102 |
} |
| 103 |
} catch (\Exception $e) { |
| 104 |
// Log error for debugging |
| 105 |
|
| 106 |
// Continue with other shortcodes even if one fails |
| 107 |
continue; |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
|