Skip to content

Deprecated: Dumbo\Dumbo::detectEnvironment(): Implicitly marking parameter $serverVars as nullable is deprecated #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
abda11ah opened this issue Dec 30, 2024 · 0 comments

Comments

@abda11ah
Copy link

Some errors on PHP 8.4.2 (FrankenPHP docker)

taken example :

<?php

require __DIR__ . "/../vendor/autoload.php";

use Dumbo\Dumbo;
use Dumbo\HTTPException;

$app = new Dumbo();
$user = new Dumbo();

$userData = [
    [
        "id" => 1,
        "name" => "Jamie Barton",
        "email" => "[email protected]",
    ],
];

$user->get("/", function ($c) use ($userData) {
    return $c->json($userData);
});

$user->get("/:id", function ($c) use ($userData) {
    $id = (int) $c->req->param("id");

    $user =
        array_values(array_filter($userData, fn($u) => $u["id"] === $id))[0] ??
        null;

    if (!$user) {
        return $c->json(["error" => "User not found"], 404);
    }

    return $c->json($user);
});

$user->post("/", function ($c) use ($userData) {
    $body = $c->req->body();

    if (!isset($body["name"]) || !isset($body["email"])) {
        return $c->json(["error" => "Name and email are required"], 400);
    }

    $newId = max(array_column($userData, "id")) + 1;

    $newUserData = array_merge(["id" => $newId], $body);

    return $c->json($newUserData, 201);
});

$user->delete("/:id", function ($c) use ($userData) {
    $id = (int) $c->req->param("id");

    $user =
        array_values(array_filter($userData, fn($u) => $u["id"] === $id))[0] ??
        null;

    if (!$user) {
        return $c->json(["error" => "User not found"], 404);
    }

    return $c->json(["message" => "User deleted successfully"]);
});

$app->get("/greet/:greeting", function ($c) {
    $greeting = $c->req->param("greeting");
    $name = $c->req->query("name");

    return $c->json([
        "message" => "$greeting, $name!",
    ]);
});

$app->route("/users", $user);

$app->use(function ($context, $next) {
    $context->set("message", "Dumbo");
    return $next($context);
});

$app->use(function ($c, $next) {
    $c->header("X-Powered-By", "Dumbo");

    return $next($c);
});

$app->get("/redirect", function ($c) {
    $message = $c->get("message");

    return $c->redirect("/greet/hello?name=$message", 301);
});

$app->get("/", function ($c) {
    $message = $c->get("message");

    return $c->html("<h1>Hello from $message!</h1>", 200, [
        "X-Hello" => "World",
    ]);
});

$app->get("/error", function ($c) {
    $customResponse = $c->html("<h1>Something went wrong</h1>", 404);
    throw new HTTPException(
        statusCode: 404,
        message: "Something went wrong",
        customResponse: $customResponse
    );
});

$app->run();

Deprecated: Dumbo\Dumbo::detectEnvironment(): Implicitly marking parameter $serverVars as nullable is deprecated, the explicit nullable type must be used instead in /app/vendor/notrab/dumbo/src/Dumbo.php on line 507

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant