This repository was archived by the owner on Jan 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResponse.php
More file actions
executable file
·91 lines (76 loc) · 1.67 KB
/
Response.php
File metadata and controls
executable file
·91 lines (76 loc) · 1.67 KB
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
<?php
namespace Modulus\Framework;
use Modulus\Http\Rest;
use Modulus\Utility\View;
use Modulus\Http\Redirect;
use Modulus\Framework\Upstart;
use Modulus\Utility\Groupable;
class Response
{
/**
* Make application response
*
* @param Upstart $app
*/
public static function make(Upstart $app)
{
/**
* Get application response
*/
$response = $app->getResponse();
/**
* Convert to collection
*/
if ($response instanceof Groupable) {
$response = $response->all();
}
/**
* Convert to array
*/
if (method_exists($response, 'toArray')) {
$response = $response->toArray();
}
/**
* Create a rest response
*/
if (
is_string($response) ||
is_int($response) ||
is_float($response) ||
is_double($response) ||
is_array($response)
) return is_array($response) ? Rest::response()->json($response)->send() : Rest::response($response)->send();
if (is_bool($response)) return Rest::response($response ? 'true' : 'false')->send();
if ($response instanceof Rest) return $response->send();
/**
* Create a redirect
*/
if ($response instanceof Redirect) return $response->send();
/**
* Create a view page
*/
if (Response::isView($response)) return;
/**
* Avoid "Segmentation fault (core dumped)"
*/
echo ' ';
/**
* Return nothing
*/
return null;
}
/**
* Render a view
*
* @param mixed $response
* @return bool
*/
public static function isView($response) : bool
{
if ($response instanceof View) {
$response->render();
return true;
}
return false;
}
}