PHP code example of reinanbr / vitruvia

1. Go to this page and download the library: Download reinanbr/vitruvia library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

reinanbr / vitruvia example snippets




itruvia\Core\Web\Application;

$app = new Application(__DIR__);

$app->get("/", function ($req, $res) {
    $res->send("Hello, world!");
});

$app->run();

$app->get("/hello/:name", function ($req, $res) {
    $res->send("Hello, {$req->params['name']}!");
});

$app->post("/api/getInfoLibs", [GetInfoLibsApiController::class, "getInfoLibs"]);

$app->use(function ($req, $res, $next) {
    error_log("{$req->method} {$req->path}");
    $next(); // omit this to short-circuit the request
});

$app->get("/admin", $ome");
});

$res->status(201)->set("X-Powered-By", "Vitruvia")->json(["created" => true]);



use Vitruvia\Core\Models\Model;

class LibsModel extends Model
{
    public string $name;
    public string $keyLib;

    public function rules(): array
    {
        return [
            "name" => [self::RULE_REQUIRED],
            "keyLib" => [self::RULE_REQUIRED, [self::RULE_MIN, 'min' => 8], [self::RULE_MAX, 'max' => 20]],
        ];
    }
}

$model = new LibsModel();
$model->loadData($req->body);

if (!$model->validate()) {
    $res->status(422)->json(["errors" => $model->errors]);
}
 echo $name;