1. Go to this page and download the library: Download mihaiblebea/interceptor library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mihaiblebea / interceptor example snippets
nterceptor\Request;
use Interceptor\Route;
use Interceptor\Router;
use Interceptor\Response;
$request = new Request();
$router = new Router($request);
$register_route = new Route('user/register', function($request) {
...
}, 'POST');
router->add(register_route);
try {
$router->run();
} catch(\Exception $e) {
...
return var_dump(404);
}
nterceptor\Request;
use Interceptor\Route;
use Interceptor\Router;
use Interceptor\Response;
use Interceptor\Middleware;
$request = new Request();
$router = new Router($request);
$auth_middleware = Middleware::apply(function($request) {
...
return $next;
});
// Bind the middleware to the Router object
$router->before(auth_middleware);
// OR
$router->before(Middleware::apply(function($request) {
...
return $next;
}));
// Login user route
$router->add(Route::post('users', function($request) {
...
}));
try {
$router->run();
} catch(\Exception $e) {
...
return var_dump(404);
}
nterceptor\Request;
use Interceptor\Route;
use Interceptor\Router;
use Interceptor\Response;
use Interceptor\Middleware;
$request = new Request();
$router = new Router($request);
$middleware = Middleware::apply(function($request) {
...
$next;
});
// Login user route
$router->add(Route::post('users', function($request) {
...
}, middleware));
try {
$router->run();
} catch(\Exception $e) {
...
return var_dump(404);
}
$router->add(Route::post('users/:user', function($request, $user) {
...
// Get the age from the request: '28'
var_dump($request->retrive('age'));
// OR
var_dump($request->dump()['age']);
// Get the username from the request: 'MihaiBlebea'
var_dump($request->getUrlArray()[1]);
// OR
var_dump($user);
}));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.