dev-master
9999999-devStrukt Router
MIT
The Requires
The Development Requires
by Moderator
Strukt Router
Create composer.json
script with contents below then run composer update
, (*2)
{ "require":{ "strukt/router":"v1.1.3-alpha" }, "minimum-stability":"dev" }
Your index.php
file., (*3)
require "vendor/autoload.php"; use Strukt\Http\Request; // use Strukt\Http\Response\Plain as Response; $app = new Strukt\Router\QuickStart(); $app->get("/", function(Request $request){ // return new Response("Hello World!"); return "Hello World!"; }); exit($app->run());
$app->inject("permissions", function(){ return array( // "show_secrets" ); }); $app->providers(array( //App\Provider\ExampleProvider::class )); $app->middlewares(array( Strukt\Router\Middleware\Session::class, Strukt\Router\Middleware\Authentication::class, Strukt\Router\Middleware\Authorization::class, )); $app->get("/user/secrets", function(){ return "Shh!"; },"show_secrets"); exit($app->run());
$app->inject("permissions", function(){ return []; }); $app->inject("session", function(){ return new Strukt\Http\Session\Native; }); $app->inject("verify", function(Strukt\Http\Session\Native $session){ $user = new Strukt\User(); $user->setUsername($session->get("username")); return $user; }); $app->providers(array( //App\Provider\ExampleProvider::class )); $app->middlewares(array( Strukt\Router\Middleware\Session::class, Strukt\Router\Middleware\Authentication::class, Strukt\Router\Middleware\Authorization::class, )); $app->post("/login", function(Strukt\Http\Request $request){ $username = $request->get("username"); $password = $request->get("password"); $request->getSession()->set("username", $username); return new Strukt\Http\Response\Plain(sprintf("User %s logged in.", $username)); }); $app->get("/current/user", function(Strukt\Http\Request $request){ return $request->getSession()->get("username"); }); $app->get("/logout", function(Strukt\Http\Request $request){ $request->getSession()->invalidate(); return new Strukt\Http\Response\Plain("User logged out."); }); exit($app->run());
After installation run composer exec static
to get public\
directory., (*4)
public/ โโโ errors โ โโโ 403.html โ โโโ 404.html โ โโโ 405.html โ โโโ 500.html โโโ static โโโ css โ โโโ style.css โโโ index.html โโโ js โโโ script.js
.htaccess
file:, (*5)
DirectoryIndex index.php RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule . index.php [L]
Adminer is a really neat tool! It is a single file dba and can be placed under a router easily! Download the adminer.php file and place in root folder., (*6)
$app->any("/dba", function(Request $request){ include "./adminer-x.x.x.php"; return new Strukt\Http\Response\Plain(); });
Cheers!, (*7)
Strukt Router
MIT