Skip to content
adelekeogunsonaPublic

About

A minimalist, high-performance PHP framework designed for building secure JSON REST APIs. LeanPHP focuses on simplicity, security, and speed while providing all the essential features needed for modern API development.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

22 Commits

Folders and files

Repository files navigation

LeanPHP

LeanPHP is a small PHP 8.2 framework for JSON APIs. It keeps the moving parts visible: a router, request and response objects, middleware, validation, JWT auth, rate limiting, logging, and a thin PDO wrapper.

The project is intentionally plain. There is no service container, ORM, template layer, or command bus. If you need those, Laravel or Symfony will serve you better. If you want a compact API skeleton that is easy to read and change, this is the point of the project.

What is included

  • HTTP request and response classes
  • RFC 7807 problem responses
  • Route parameters, constraints, groups, HEAD handling, and CORS preflight handling
  • Middleware for errors, request IDs, CORS, JSON body checks, bearer auth, scopes, rate limits, and ETags
  • JWT issuing and verification with key IDs
  • Input validation with common rules
  • PDO helpers for queries and transactions
  • File and APCu rate limit stores
  • PHPUnit and PHPStan configuration

Requirements

  • PHP 8.2 or newer
  • Composer
  • PDO SQLite for the demo database
  • APCu if you want the APCu rate limit store

Setup

composer install
cp .env.example .env
php scripts/seed.php

To run the local server, use:

php -S localhost:8000 -t public public/router.php

Try it

curl http://localhost:8000/health
curl -X POST http://localhost:8000/login \
  -H "Content-Type: application/json" \
  -d '{"email":"[email protected]","password":"secret"}'

Use the returned token:

curl http://localhost:8000/v1/users \
  -H "Authorization: Bearer YOUR_TOKEN_HERE"

Checks

composer test
php -d memory_limit=512M vendor/bin/phpstan analyse

composer stan may fail on machines where PHP uses the default 128 MB memory limit. The command above keeps PHPStan on the same config and gives it enough memory.

Route cache

Generate the route cache before deploying with:

php bin/route_cache.php

Closure routes are skipped because PHP cannot safely cache closures with var_export(). Use controller handlers for routes you want cached.

Documentation

Start with docs/README.md.

License

MIT. See LICENSE.

About

A minimalist, high-performance PHP framework designed for building secure JSON REST APIs. LeanPHP focuses on simplicity, security, and speed while providing all the essential features needed for modern API development.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages