daniel-samson / teensyphp
The minimalists web framework
Installs: 162
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
pkg:composer/daniel-samson/teensyphp
Requires (Dev)
- phpunit/phpunit: 12.4.1
- dev-main
- v1.5.13
- v1.5.12
- v1.5.11
- v1.5.10
- v1.5.9
- v1.5.8
- v1.5.7
- v1.5.6
- v1.5.5
- v1.5.4
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.0
- v1.2.0
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.76
- v1.0.75
- v1.0.74
- v1.0.73
- v1.0.72
- v1.0.71
- v1.0.70
- v1.0.69
- v1.0.68
- v1.0.67
- v1.0.66
- v1.0.65
- v1.0.64
- v1.0.63
- v1.0.62
- v1.0.61
- v1.0.60
- v1.0.59
- v1.0.58
- v1.0.57
- v1.0.56
- v1.0.55
- v1.0.54
- v1.0.53
- v1.0.52
- v1.0.51
- v1.0.50
- v1.0.49
- v1.0.48
- v1.0.47
- v1.0.46
- v1.0.45
- v1.0.44
- v1.0.43
- v1.0.42
- v1.0.41
- v1.0.40
- v1.0.39
- v1.0.38
- v1.0.37
- v1.0.36
- v1.0.35
- v1.0.34
- v1.0.33
- v1.0.32
- v1.0.31
- v1.0.30
- v1.0.29
- v1.0.28
- v1.0.27
- v1.0.26
- v1.0.25
- v1.0.24
- v1.0.23
- v1.0.22
- v1.0.21
- v1.0.20
- v1.0.19
- v1.0.18
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-renovate/all
- dev-daniel-samson-patch-1
- dev-release/2.0.0
This package is auto-updated.
Last update: 2025-12-13 05:38:23 UTC
README
Teensy PHP is a micro web framework for rapidly creating REST APIs and hypermedia.
Project Status
Features
- Lightweight Framework
- Simple Router
- PHP Templating Engine
- Middleware Support
- Easy to inject or replace functionality (its just some small functions)
- env Config Utility
- Database Connection Manager Utility
- ArrayAccessImplementation, Crud Traits
Examples
<?php // routes/web.php use App\Actions\Home\DisplayHome; routerGroup("/", function () { // Homepage route(method(GET), url_path('/'), DisplayHome::class); // Example url parameter route(method(GET), url_path_params("/hello/:name"), function () { render(200, html_out(template('src/templates/hello.php', ['name' => $_GET[':name']]))); }); });
<?php // routes/api.php // /api/{route} routerGroup("/api", function () { // API home route(method("GET"), url_path("/"), function () { render(200, json_out(["message" => "Hello World!"])); }); // Example JSON body (echo server) route(method(POST), url_path("/echo"), function () { $body = json_in(); render(201, json_out($body)); }); });
<?php // App/Actions/Home/DisplayHome.php namespace App\Actions\Home; class DisplayHome { public function __invoke() { $accept = request_header('Accept'); if ($accept === 'application/json') { render(200, json_out(['message' => 'Hello World'])); } else { render(200, html_out(template(app_root() . "/templates/pages/home.php", []))); } } }
Requirements
- PHP 8.0+
- Composer
Documentation
Please see the wiki for more information on how to rapidly create apps with teensyphp.
Creating a new project
Install teensyphp command line tool
composer global require daniel-samson/teensyphp
Create a new project
teensyphp new project-name
cd project-name
composer install
Start buit in web server
composer dev
- open web route http://localhost:8000
- open api route http://localhost:8000/api
Update Teensyphp
composer global update
Background
This project was an exploration of Object Oriented Programming vs Procedural / Structure Programming. At the time (2012), composer autoloading only worked for classes. I asked the question "What if functions were first class like they are in JS/Haskel?". At the time, classes seem to take up more overhead eg. more memory and cpu time. However, functions didn't seem to have this penalty. This was partly to do with how the autoloader worked (which improved over time). I also was wanting to change how projects that were OO worked. I didn't like facades. I liked having simple higher order functions that i could replace with my own implementations. TeensyPHP explored what it would be like to just use functions. however, as it grew, I needed to manage database connections. So i introduced entities, a environment config manager and a database manager.
Everything in TeensyPHP is completely replaceable!