1. Go to this page and download the library: Download zaek/framy 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/ */
new Router(new RoutePrefix('/api', [
'/users' => '/users.php',
'/settings' => '/v.php'
]));
// Is the same as
new Router([
'/api/users' => '/users.php',
'/api/settings' => '/settings.php'
]);
$proxyCallback = function($route) {
return new CbFunction(function(App $app) use($route) {
if($app->user()->getId() < 1) {
throw new Exception('No auth', 401);
}
return new File($route);
});
};
/// The request /api/user/data and /api/personal/data will be proxy by proxyCallback
/// and will throw an exception for non-authorized users
new Router(new RoutePrefix('/api', [
'/data' => '/data.php',
// It could be the proxy inside a group as a group inside the proxy
... new RoutePrefix('/user', new RouteProxy($proxyCallback, [
'GET /data' => '/user_data.php',
])),
... new RouteProxy($proxyCallback, new RoutePrefix('/personal', [
'GET /data' => '/user_personal.php',
]))
]))