Download the PHP package godie/overphp without Composer
On this page you can find all versions of the php package godie/overphp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download godie/overphp
More information about godie/overphp
Files in godie/overphp
Package overphp
Short Description Minimal PHP API framework with static client serving and CLI support
License MIT
Informations about the package overphp
OverPHP
Minimal, API-first PHP framework designed for serverless and traditional deployments.
- Dependency Injection container (
OverPHP\Core\Container) - Dynamic routing with parameters (
/user/{id}) - Optional static client serving with SPA fallback
- Optional MySQL/SQLite layer with pluggable drivers
- Optional CSRF protection for fullstack use
- CLI scaffolding tool
- CORS helper and clean JSON responses
- Performance benchmark
Install
Scaffold a new project
Quick Start
Structure
Requirements
- PHP 8.1+
- Composer
- MySQL or SQLite only if DB layer is enabled
Routing
Register routes in index.php:
Dynamic parameters are passed to the handler:
Handler options:
- Closure (receives route params as arguments)
"Controller@method"(resolved via DI container)
Route Options
Dependency Injection
The framework includes a simple DI container. Controllers are resolved through it, so constructor dependencies are injected automatically:
Response Object
Controllers can return arrays (auto-serialized to JSON) or Response objects for full control:
Client Serving
Serve a static frontend (React, Vue, etc.) alongside your API. Enable in config:
- Requests matching
route_prefix(/api) go to the router - All other requests serve static files from the client directory
- Missing files fall back to
index.html(SPA support) - Directory traversal is prevented
Configuration
Copy config.example.php to config.php and edit, or use environment variables.
Core
| Key | Env | Default | Description |
|---|---|---|---|
allowed_origins |
— | ['http://localhost:5173'] |
CORS allowlist |
route_prefix |
API_PREFIX |
/api |
API route prefix |
controller_namespace |
CONTROLLER_NAMESPACE |
OverPHP\Controllers |
Controller namespace |
Benchmark
| Key | Env | Default |
|---|---|---|
benchmark.enabled |
BENCHMARK_ENABLED |
false |
When enabled, JSON responses include:
Security / CSRF
| Key | Env | Default | Description |
|---|---|---|---|
security.csrf_enabled |
CSRF_ENABLED |
false |
Enable session-based CSRF protection |
CSRF is disabled by default because the framework is API-first and typically used with stateless authentication (JWT, API keys). Enable it if you use session/cookie-based auth in a fullstack setup.
When enabled, state-changing requests (POST, PUT, PATCH, DELETE) must include a valid CSRF token via X-CSRF-TOKEN header or _csrf_token form field. Individual routes can opt out with 'skip_csrf' => true.
Client
| Key | Env | Default |
|---|---|---|
client.enabled |
CLIENT_ENABLED |
false |
client.path |
CLIENT_PATH |
./client |
client.fallback_index |
— | index.html |
Database (optional)
| Key | Env | Default |
|---|---|---|
database.enabled |
DB_ENABLED |
false |
database.driver |
DB_DRIVER |
mysql |
The database layer uses a pluggable driver architecture. Ships with MySQL and SQLite.
MySQL
SQLite
SQLite requires no external server. Ideal for development, testing, or small-scale APIs.
Custom Driver
Implement DriverInterface or extend AbstractDriver:
Register before use:
Creating a Controller
Custom Controller Namespace
You can use your own namespace for controllers instead of the default OverPHP\Controllers. This is useful when integrating OverPHP into existing projects or when you prefer your own naming convention.
Using Environment Variable
Using Configuration File
Controller Example with Custom Namespace
The controller files should still be placed in src/Controllers/ directory, but you can use your preferred namespace in the class declarations.
License
MIT