-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
141 lines (94 loc) · 3.94 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
// company: PulseStream
// Developed by: Ngwang Shalom
// Location: Cameroon/Bamenda
// Languages: php/hack/javascript/node(library)
// position: Senior dev
//
//
// Please add your own description if you are a contributor
//
//
//
require __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/app/API/Controllers/HomeController.php';
require_once __DIR__ . '/app/API/Controllers/AuthController.php';
//test controller requires
require_once __DIR__ . '/tests/API/Controllers/AuthControllerTest.php';
//Pages for testing failed success or warning
require_once __DIR__ . '/Endpoints/Endpoint.php';
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\HttpFoundation\Request;
$routes = new RouteCollection();
//please add your test routing here before sending to the main route in app please
//test routine
//example
$routes->add('Test Auth', new Route('/TestAuth', [
'_controller' => 'tests\\API\\Controllers\\AuthControllerTest::login',
]));
//all this is just for testing
$routes->add('Failed', new Route('/Failed', [
'_controller' => 'Endpoints\\Endpoint\\EndpointPages::Failed',
]));
$routes->add('Success', new Route('/success', [
'_controller' => 'Endpoints\\Endpoint\\EndpointPages::Success',
]));
$routes->add('Warning', new Route('/warning', [
'_controller' => 'Endpoints\\Endpoint\\EndpointPages::Warning',
]));
//testing
//test ends here thanks
// general routes for all platforms such as web,android and desktop apps
$routes->add('home', new Route('/', [
'_controller' => 'App\\API\\Controllers\\HomeController::index',
]));
$routes->add('login', new Route('/api/login', [
'_controller' => 'App\\API\\Controllers\\AuthController::login',
], [], [], '', [], ['POST']));
$routes->add('register', new Route('/api/register', [
'_controller' => 'App\\API\\Controllers\\AuthController::register',
], [], [], '', [], ['POST']));
$routes->add('logout', new Route('/api/logout', [
'_controller' => 'App\\API\\Controllers\\AuthController::logout',
]));
$routes->add('comment', new Route('/api/comment', [
'_controller' => 'App\\API\\Controllers\\CommentController::create',
], [], [], '', [], ['POST']));
$routes->add('share', new Route('/api/share', [
'_controller' => 'App\\API\\Controllers\\ShareController::create',
], [], [], '', [], ['POST']));
$routes->add('message', new Route('/api/message', [
'_controller' => 'App\\API\\Controllers\\MessageController::create',
], [], [], '', [], ['POST']));
$routes->add('subscription', new Route('/api/subscription', [
'_controller' => 'App\\API\\Controllers\\SubscriptionController::subscribe',
], [], [], '', [], ['POST']));
$routes->add('get_messages', new Route('/api/messages', [
'_controller' => 'App\\API\\Controllers\\MessageController::index',
], [], [], '', [], ['GET']));
$routes->add('get_subscriptions', new Route('/api/subscriptions', [
'_controller' => 'App\\API\\Controllers\\SubscriptionController::index',
], [], [], '', [], ['GET']));
//web specific routes starts here
//web specific routes ends
//mobile specific routes starts
//mobile specific routes ends
//desktop specific routes strnatcasecmp
//desktop specific routes ends
$context = new RequestContext('./');
$context->fromRequest(Request::createFromGlobals());
$matcher = new UrlMatcher($routes, $context);
$request = Request::createFromGlobals();
try {
$parameters = $matcher->match($request->getPathInfo());
$controller = $parameters['_controller'];
[$class, $method] = explode('::', $controller);
$response = call_user_func([$class, $method]);
echo $response;
} catch (ResourceNotFoundException $e) {
echo '<div align="center"><h1 style="color:red; font-size:24;">404- please check the url and try again-{PulseStream-API [Endpoint=>ERROR]}</h1></div>';
}