Download the PHP package omaressaouaf/plain-kit without Composer
On this page you can find all versions of the php package omaressaouaf/plain-kit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download omaressaouaf/plain-kit
More information about omaressaouaf/plain-kit
Files in omaressaouaf/plain-kit
Package plain-kit
Short Description A small PHP toolkit for building MVC-style demos and prototypes without a full framework.
License MIT
Homepage https://github.com/omaressaouaf/plain-kit
Informations about the package plain-kit
PlainKit
A small personal PHP toolkit for building MVC-style demos, prototypes, and coding exercises without installing a full framework.
PlainKit gives you just enough structure around routing, middleware, request handling, sessions, CSRF protection, validation, simple views, environment configuration, and a lightweight service container — while staying close to plain PHP.
PlainKit is not a production framework. It is not intended to replace Laravel, Symfony, Slim, or any mature PHP framework. It exists as a practical foundation for personal small projects, experiments, and learning how framework pieces fit together.
Features
- Application bootstrap with
App::create()and fluent service binding - Router with HTTP verbs, middleware, route parameters, and file-based controllers
- Middleware for
auth,guest, and CSRF verification - Request and Response helpers for input, redirects, JSON, and views
- Session storage with flash data
- CSRF token generation and verification
- Form validation flow with
FormandValidator - Authenticator for login, logout, and password updates
- Database wrapper around PDO
- Environment loading via
.env(vlucas/phpdotenv) - Global helpers for paths, escaping, debugging, and env access
Requirements
- PHP 8.2+
- Composer
Installation
Install via Composer:
Quick Start
A PlainKit application needs:
- A public entry point (
public/index.php) - A routes file (
routes.php) - Controllers under
app/Http/Controllers/ - Views under
app/Views/ - Optional config,
.env, repositories, and services
Entry point
App::create() will:
- set the application base path (
PLAINKIT_BASE_PATH) - load
.envfrom the app root (if present) - start the session
- register default PlainKit bindings
- load
routes.phpand handle the incoming request
Routes
Routes map to PHP files at app/Http/Controllers/{path}.php.
Controller
Controllers are plain PHP files. Resolve dependencies from the container with App::resolve():
Project Structure
A typical app built with PlainKit looks like this:
The package lives in vendor/omaressaouaf/plain-kit. Your app root is the directory passed to App::create() — usually one level above public/.
Environment
PlainKit uses vlucas/phpdotenv to load a .env file from the application root.
.env.example:
config/app.php:
Helpers:
Helpers
PlainKit registers these global helpers:
| Helper | Purpose |
|---|---|
base_path('config/app.php') |
Path relative to the app root |
app_path('Http/Controllers/home.php') |
Path relative to app/ |
env('KEY', 'default') |
Read an environment variable |
load_env($basePath) |
Load .env from a directory |
e($value) |
Escape HTML (returns string) |
_r($value) |
Echo escaped HTML |
dd(...$values) |
Dump and die |
base_path() requires PLAINKIT_BASE_PATH to be defined (via App::create() or manually).
App & Container
Bootstrapping
Default bindings
These are registered automatically:
SessionCsrfMiddlewareRequestResponseRouterDatabaseAuthenticator
Register your own classes with ->bind():
Resolving services
Inside controllers, middleware, forms, repositories, or views:
If a binding is missing, PlainKit throws BindingNotFoundException.
Router
HTTP verbs
Middleware
Attach middleware to the most recently registered route:
Built-in middleware keys:
| Key | Behavior |
|---|---|
auth |
Redirect to /login if the user is not logged in |
guest |
Redirect to / if the user is already logged in |
csrf |
Verify CSRF token on POST requests (applied automatically on every matched route) |
Route parameters
In a controller:
Place static routes before parameterized ones:
Method spoofing
HTML forms can simulate PUT, PATCH, or DELETE via a hidden _method field:
The router reads $_POST['_method'] when handling the request.
404 handling
When no route matches, PlainKit calls Response::abort(404), which loads:
Request
Response
Views receive context variables via extract() and can include partials:
Use e() in views to escape output:
Session
Flash data is cleared automatically at the end of each request via Router::handleRequest().
CSRF
Generate a token in a form:
VerifyCsrf middleware runs on every matched route. On POST requests it checks the submitted _csrf_token. Invalid or missing tokens trigger a 419 response.
Forms & Validation
Creating a form
Extend Form and implement handle():
Validating in a controller
If validation fails, PlainKit throws ValidationException. The router catches it, flashes errors and old input to the session, and redirects back.
Display errors in a view partial:
Validator methods
| Method | Description |
|---|---|
Validator::exists($value) |
Not empty |
Validator::email($value) |
Valid email |
Validator::string($value) |
Non-empty trimmed string |
Validator::numeric($value) |
Numeric value |
Validator::in($value, $array) |
Value in array |
Validator::min($value, $min) |
Min length/count/numeric |
Validator::max($value, $max) |
Max length/count/numeric |
Database
PlainKit includes a thin PDO wrapper. Configuration is read from config/app.php. The connection DSN is currently MySQL-only (mysql:...).
Typical usage in a repository:
Authenticator
Session-based authentication helper:
On successful login, the user record is stored in the session under the user key and the session ID is regenerated.
Middleware
All middleware implements MiddlewareInterface:
Built-in middleware is resolved by key through the Middleware class. To add custom middleware you would extend the middleware map in your own fork or wrapper — PlainKit keeps this intentionally small.
Exceptions
| Exception | When |
|---|---|
BindingNotFoundException |
Container binding not registered |
MiddlewareNotFoundException |
Unknown middleware key |
ValidationException |
Form validation failed (carries $errors and $old) |
Example App
This repository includes a ledger demo at examples/ledger that demonstrates:
- user registration and login
- CRUD for clients and transactions
- filtered reports
- a JSON API endpoint at
/api/reports - forms, repositories, services, CSRF, and middleware
Run the example
From the repository root:
See examples/ledger/README.md for more detail.
Testing
Run unit tests:
License
This package is licensed under the MIT License.