-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHomeController.php
66 lines (53 loc) · 2.01 KB
/
HomeController.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
<?php
namespace Gac\Routing\sample;
use Gac\Routing\Request;
use Gac\Routing\Response;
use JsonException;
class HomeController
{
public function __construct(protected ?InjectedClass $injected = NULL) { }
public function index() : void {
echo "Hello from controller";
}
/**
* @throws JsonException
*/
public function home(Request $request) : void {
// Old way of doing it
/*$request
->header("Access-Control-Allow-Origin", "https://demo.local")
->header("Content-Type", "application/json")
->status(401, 'Not Authorized')
->send([ "message" => "Hello from controller::home" ]);*/
// New way of doing it
Response::
withHeader("Access-Control-Allow-Origin", "https://demo.local")::
withHeader("Content-Type", "application/json")::
withStatus(401, 'Not authorized')::
withBody([ "message" => "Hello from controller::home" ])::
send();
}
public function getUsers(Request $request) : void {
$request->send([ "message" => "Hello from controller::home", "ses" => $_SESSION ]);
}
public function addUser(Request $request) : void {
$request->send([ "message" => "Hello from controller::home" ]);
}
public function updateUser(Request $request) : void {
$request->send([ "message" => "Hello from controller::home" ]);
}
public function replaceUser(Request $request) : void {
$request->send([ "message" => "Hello from controller::home" ]);
}
public function deleteUser(Request $request) : void {
$request->send([ "message" => "Hello from controller::home" ]);
}
public function test(Request $request, int $userID, string $username, float $amount, bool $valid) : void {
var_dump($this->injected);
echo "Dynamic route here";
}
public function dependency_injection_test(Request $request) : string {
//$request->send([ "isInstanceOf" => $this->injected instanceof InjectedClass ]);
return json_encode([ 'isInstanceOf' => $this->injected instanceof InjectedClass ]);
}
}