Tiny PHP Framework

Home Getting Started Core Concepts Helpers Extensions Repo

Extensions

Extensions are first-party modules that live in tiny/ext/. They are loaded on demand via the tiny::* accessor pattern — you don’t need to register them.

Available extensions

Extension Accessor Purpose
Cache tiny::cache() APCu / Memcached with remember() and prefix operations
ClickHouse tiny::clickhouse() ClickHouse client for analytics workloads
CMS tiny::cms() File-based markdown CMS with caching
Components Component::* Reusable view fragments
Cookie tiny::cookie() Signed cookie management
CSRF tiny::csrf() CSRF tokens for forms
Database tiny::db() MySQL / PostgreSQL / SQLite
Debugger tiny::dd/dump/log/debug() IP-gated debugging output
Flash tiny::flash('name') One-shot session messages
HTTP tiny::http() HTTP client for outbound requests
Layout Layout::* Layout system for views
Migrations php tiny/cli migrations Versioned schema management
Scheduler tiny::scheduler() Built-in fluent cron-style scheduler
SSE tiny::sse() Server-Sent Events streaming
Swoole tiny::swoole() Coroutine runtime

Calling pattern

Most extensions are exposed as static accessors on the tiny class. They’re lazily instantiated and reused across the request:

tiny::cache()->set('key', 'value', 3600);
$response = tiny::http()->get('https://api.example.com/data');

Component and Layout are global constants pointing at singleton instances, used directly in views:

Component::render('userCard', $user);
Layout::main(['title' => 'Home']);

Configuration

Extensions read their settings from environment variables (via .env.<env> or directly from the server environment). New extensions use the TINY_* prefix; some legacy ones don’t (e.g. COOKIE_TTL, DEBUG_WHITELIST, LOG_FILE). The relevant variables are listed in each extension’s page.

See Configuration for the complete reference.

Writing a custom extension

A custom extension is a class prefixed with Tiny, dropped into tiny/ext/:

<?php
// tiny/ext/myservice.php
declare(strict_types=1);

class TinyMyservice
{
    public function __construct()
    {
        // initialise from $_SERVER['TINY_MYSERVICE_…']
    }

    public function doSomething(): string
    {
        return 'ok';
    }
}

Use it via tiny::myservice():

tiny::myservice()->doSomething();

The framework looks up Tiny<UcfirstName> for any unknown static call to tiny::<name>().

Or: register at runtime

For project-specific extensions you don’t want in the framework folder, register a factory closure on boot (e.g. from app/common.php):

tiny::registerHelper('analytics', function () {
    return new \App\Services\Analytics($_SERVER['TINY_ANALYTICS_TOKEN']);
});

Subsequent calls to tiny::analytics() return the singleton built by the closure.