Dominik Prinzensteiner 19819ca8d1
Some checks failed
Tests / build (push) Has been cancelled
Release / Release (push) Has been cancelled
Feature/smarty example (#71)
* add new example for using smarty templating

* update readme

* Update examples/context-view-smarty/README.md

---------

Co-authored-by: Dominik Prinzensteiner <dominik@prinzensteiner.at>
Co-authored-by: Jamie Barton <jamie@notrab.dev>
2024-11-19 09:02:06 +00:00
2024-10-22 13:47:04 +01:00
2024-11-19 09:02:06 +00:00
2024-10-19 11:13:36 +01:00
2024-10-19 11:13:36 +01:00
2024-10-22 13:47:04 +01:00
2024-10-21 07:49:50 +01:00
2024-08-14 20:37:48 +01:00
2024-10-19 11:26:05 +01:00
2024-09-05 10:58:32 +01:00
2024-07-15 13:29:07 +00:00

Dumbo

Dumbo

A lightweight, friendly PHP framework for HTTP — Inspired by Hono.

Discord Contributors Total downloads Examples

Features

  • 🚀 Lightweight and fast
  • 🧩 Middleware support
  • 🛣️ Flexible routing with parameters
  • 🔒 Built-in security features (CSRF, JWT)
  • 🍪 Cookie management
  • 📅 Date helpers
  • 🔍 Request ID for tracing
  • 📁 Static file serving
  • 🔐 Basic and Bearer authentication
  • 📝 Logging support
  • 🗃️ HTTP caching
  • 🔄 CORS support
  • 🧬 Environment-based configuration

Install

composer require notrab/dumbo

Quickstart

Here's a basic example of how it works!

<?php

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

use Dumbo\Dumbo;

$app = new Dumbo();

$app->use(function ($context, $next) {
    $context->set('message', 'Hello from middleware!');
    return $next($context);
});

$app->get('/', function ($context) {
    return $context->json([
        'message' => $context->get('message'),
        'timestamp' => time()
    ]);
});

$app->get('/users/:id', function ($context) {
    $id = $context->req->param('id');
    return $context->json(['userId' => $id]);
});

$app->post('/users', function ($context) {
    $body = $context->req->body();
    return $context->json($body, 201);
});

$app->run();

See the examples directory for more quickstarts.

License

Dumbo is open-sourced software licensed under the MIT license.

Contributors

Contributors

Documentation

Routing

<?php

$app->get('/users', function($context) { /* ... */ });
$app->post('/users', function($context) { /* ... */ });
$app->put('/users/:id', function($context) { /* ... */ });
$app->delete('/users/:id', function($context) { /* ... */ });

Params

<?php

$app->get('/users/:id', function($context) {
    $id = $context->req->param('id');

    return $context->json(['id' => $id]);
});

Nested

<?php

$nestedApp = new Dumbo();

$nestedApp->get('/nested', function($context) {
    return $context->text('This is a nested route');
});

$app->route('/prefix', $nestedApp);

Context

<?php

$app->get('/', function($context) {
    $pathname = $context->req->pathname();
    $routePath = $context->req->routePath();
    $queryParam = $context->req->query('param');
    $tags = $context->req->queries('tags');
    $body = $context->req->body();
    $userAgent = $context->req->header('User-Agent');
});

Response

<?php

return $context->json(['key' => 'value']);
return $context->text('Hello, World!');
return $context->html('<h1>Hello, World!</h1>');
return $context->redirect('/new-url');

Middleware

<?php

$app->use(function($context, $next) {
    $response = $next($context);

    return $response;
});

Custom context

<?php

$app = new Dumbo();

// Set configuration values
$app->set('DB_URL', 'mysql://user:pass@localhost/mydb');
$app->set('API_KEY', 'your-secret-key');
$app->set('DEBUG', true);

// Get configuration values
$dbUrl = $app->get('DB_URL');
$apiKey = $app->get('API_KEY');
$debug = $app->get('DEBUG');

// Use configuration in your routes
$app->get('/api/data', function(Context $context) {
    $apiKey = $context->get('API_KEY');

    // Use $apiKey in your logic...
    return $context->json(['message' => 'API key is set']);
});

$app->run();
Description
A lightweight, friendly PHP framework for HTTP.
Readme MIT 788 KiB
Languages
PHP 100%