Microframework PHP, create to web applications with Touch
composer require ericktucto/touch
env: local # local or production
<?php
require __DIR__ . '/../vendor/autoload.php';
use Touch\Application;
use Touch\Core\Kernel;
use Touch\Http\Response;
$app = Application::create(new Kernel());
$app->route()->get("/", fn() => Response::html("Hello world!!!"));
$app->run();
- PHP Dig (dependency injection container)
- Routing by thephpleague (use psr-7 and psr-15 to middleware)
- Eloquent (ORM's Laravel)
- Twig (engine template of Symfony)
- Clockwork (debugger console)
- Valitron (validation data request)
Create your routing web applications
<?php
// code ...
$app->route()->get("/", fn () => Response::html("My index"));
To more infor, you'll visit docs of The php league's Routing. But Touch have some interesed features.
Routing always need a function return a variable that implements Psr\Http\Message\ResponseInterface
(see doc). To make returning response, exists Touch\Http\Response
<?php
// code ...
// return html or text plain, $status is optional and 200 is default value
$app->route("/html", fn () => Response::html("<h3>My first app</h3>", 200));
// return json, $status is optional and 200 is default value
$app->route("/api/v1/json", fn () => Response::json(["message" => "It's okay"], 200);
// first argument can be a object
Routing can group routes (see docs), but you have Touch\Http\Route
to group on class.
<?php
// index file
$app->group('/admin', new AdminRoutes);
// AdminRoutes.php
use League\Route\RouteGroup;
use Touch\Http\Response;
use Touch\Http\Route;
class AdminRoutes extends Route
{
protected function routes(RouteGroup $group)
{
$group->get('/users', [UserController::class, "create"]);
$group->get('/list-users', fn() => Response::html("<!-- list users -->"));
}
}
// routes created
// GET /admin/users -> create method of UserController class
// GET /admin/list-users -> anonymous closure