PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.13
Yatra – Travel Booking & Tour Operator Software v3.0.13
3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 All 83 releases
yatra / app / Hooks / RestApiHooks.php

RestApiHooks.php in Yatra – Travel Booking & Tour Operator Software 3.0.13, at app/Hooks/RestApiHooks.php

64 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Yatra\Hooks;
6
7 /**
8 * REST API Hooks
9 *
10 * Handles REST API route registration and related functionality
11 */
12 class RestApiHooks
13 {
14 /**
15 * Initialize REST API hooks
16 */
17 public static function init(): void
18 {
19 // Authentication (login, register, email verification)
20 add_action('rest_api_init', [\Yatra\Controllers\AuthController::class, 'registerRoutes']);
21
22 // Cache management
23 if (class_exists('\Yatra\Controllers\CacheController')) {
24 add_action('rest_api_init', [\Yatra\Controllers\CacheController::class, 'registerRoutes']);
25 }
26
27 // Test endpoint to verify REST API is working
28 add_action('rest_api_init', [self::class, 'registerTestEndpoint']);
29 }
30
31 /**
32 * Only administrators can probe REST availability (avoids public version/timestamp disclosure).
33 */
34 public static function canAccessTestEndpoint(): bool
35 {
36 return current_user_can('manage_options');
37 }
38
39 /**
40 * Register test endpoint for REST API verification
41 */
42 public static function registerTestEndpoint(): void
43 {
44 register_rest_route('yatra/v1', '/test', [
45 'methods' => 'GET',
46 'callback' => [self::class, 'handleTestEndpoint'],
47 'permission_callback' => [self::class, 'canAccessTestEndpoint'],
48 ]);
49 }
50
51 /**
52 * Handle test endpoint request
53 */
54 public static function handleTestEndpoint(): array
55 {
56 return [
57 'status' => 'success',
58 'message' => 'Yatra REST API is working',
59 'timestamp' => current_time('timestamp'),
60 'version' => YATRA_VERSION ?? 'dev'
61 ];
62 }
63 }
64