miskynscze/freerouter

This package is abandoned and no longer maintained. No replacement package was suggested.
There is no license information available for the latest version (v0.1.3a) of this package.

FreeRouter where the easy routing begins the pain ends.

v0.1.3a 2021-09-29 20:33 UTC

This package is auto-updated.

Last update: 2024-09-29 05:43:07 UTC


README

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