@@ -56,7 +56,7 @@ server {
5656 }
5757 location ~ \.php$ {
5858 fastcgi_split_path_info ^(.+\.php)(/.+)$;
59- fastcgi_pass unix:/var/run/php5 -fpm.sock;
59+ fastcgi_pass unix:/var/run/php7.4 -fpm.sock;
6060 fastcgi_index index.php;
6161 include fastcgi.conf;
6262 fastcgi_intercept_errors on;
@@ -68,16 +68,17 @@ server {
6868
6969``` php
7070$config = [
71- 'paths' => [
72- 'controller' => null, //The full path to the directory where the Controller classes are kept.
73- 'middleware' => null, //The full path to the directory where the Middleware classes are kept.
71+ 'paths' => [
72+ 'controller' => null, //The full path to the directory where the Controller classes are kept.
73+ 'middleware' => null, //The full path to the directory where the Middleware classes are kept.
7474 ],
75- 'namespaces' => [
76- 'controller' => null, //Namespace prefix of Controller classes, if applicable.
77- 'middleware' => null, //Namespace prefix of Middleware classes, if applicable.
75+ 'namespaces' => [
76+ 'controller' => null, //Namespace prefix of Controller classes, if applicable.
77+ 'middleware' => null, //Namespace prefix of Middleware classes, if applicable.
7878 ],
79- 'base_path' => '/', // If you are working in a subdirectory; identifies your working directory.
80- 'variable_method' => false, // It makes the request method mutable with Laravel-like $_REQUEST['_method'].
79+ 'base_path' => '/', // If you are working in a subdirectory; identifies your working directory.
80+ 'variable_method' => false, // It makes the request method mutable with Laravel-like $_REQUEST['_method'].
81+ 'argument_new_instance' => false, // This configuration is used for Request and Response objects that you want as arguments.
8182];
8283```
8384
@@ -93,30 +94,12 @@ _**See the Wiki for detailed documentation.**_
9394
9495``` php
9596require_once "vendor/autoload.php";
96- use \InitPHP\HTTP\{Request, Response, Stream, Emitter};
97+ use \InitPHP\HTTP\Message\{Request, Response, Stream};
98+ use \InitPHP\HTTP\Emitter\Emitter;
9799use \InitPHP\Router\Router;
98100
99- if(($headers = function_exists('apache_request_headers') ? apache_request_headers() : []) === FALSE){
100- $headers = [];
101- }
102-
103- $uri = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http')
104- . '://'
105- . ($_SERVER['SERVER_NAME'] ?? 'localhost')
106- . (isset($_SERVER['SERVER_PORT']) && !\in_array($_SERVER['SERVER_PORT'], [80, 443]) ? ':' . $_SERVER['SERVER_PORT'] : '')
107- . ($_SERVER['REQUEST_URI'] ?? '/');
108-
109- // Construct the HTTP request object.
110- $request = new Request(
111- ($_SERVER['REQUEST_METHOD'] ?? 'GET'),
112- $uri,
113- $headers,
114- null,
115- '1.1'
116- );
117-
118- // Create a new HTTP response object.
119- $response = new Response(200, [], (new Stream('', null)), '1.1');
101+ $request = Request::createFromGlobals();
102+ $response = new Response();
120103
121104// Create the router object.
122105$router = new Router($request, $response, []);
@@ -126,6 +109,13 @@ $router->get('/', function () {
126109 return 'Hello World!';
127110});
128111
112+ $router->post('/login', function (Request $request, Response $response) {
113+ return $response->json([
114+ 'status' => 0,
115+ 'message' => 'Unauthorized',
116+ ], 401);
117+ });
118+
129119// If you do not make a definition for 404 errors; An exception is thrown if there is no match with the request.
130120$router->error_404(function () {
131121 echo 'Page Not Found';
0 commit comments