2017 © Pedro Pelรกez
 

library router

Strukt Router

image

strukt/router

Strukt Router

  • Friday, July 20, 2018
  • by pitsolu
  • Repository
  • 1 Watchers
  • 1 Stars
  • 57 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 58 % Grown

The README.md

Strukt Router

Build Status Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Getting Started

Quick Start

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());

Advanced Router (The Nitty Gritty)

Permissions

$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());

Authentication

$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());

Environment

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

Apache

.htaccess file:, (*5)

DirectoryIndex index.php

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

BTW, DB Tip...

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)

The Versions

20/07 2018

dev-master

9999999-dev

Strukt Router

  Sources   Download

MIT

The Requires

 

The Development Requires

by Moderator