Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.
/ freerouter Public archive

Painless routing library using attributes in PHP 8+

License

GPL-3.0, GPL-3.0 licenses found

Licenses found

GPL-3.0
LICENSE
GPL-3.0
LICENSE.md
Notifications You must be signed in to change notification settings

miskynscze/freerouter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FreeRouter

Painless routing for your PHP 8+ project with REST support.

Installation (Still WIP)

composer require miskynscze/freerouter

Example (Basic)

#[Controller]
class ClassController implements IRouter {

    #[Request("/")]
    #[Method(RequestMethod::GET)]
    public function home(): string {
        return "Hello, world!";
    }
}

//Getting RouterConfig
$config = new RouterConfig();
$router = new RouterWrapper();

//Running RouterWrapper
$router->config($config)->run(new ClassController());

It will return

Hello, world!

Example (Basic + parameters)

#[Controller]
class ClassController implements IRouter {

    #[Request("/page/{id}")]
    #[Method(RequestMethod::GET)]
    public function page(string $id): string {
        return "You are on page ($id)";
    }
}

It will also return a string, but with parameters! For example for URL /page/10

You are on page 10

Example (REST)

#[RestController]
class ClassController implements IRouter {

    #[Request("/user/{id}")]
    #[Method(RequestMethod::GET)]
    public function user(string $id): string {
        return [
            "id" => $id,
            "name" => "Test"
        ];
    }
}

It will return (for example /user/1)

{"id": 1, "name": "Test"}
Different request methods

GET, POST, PUT, DELETE