reyjhon/simple-php

The Simple PHP is lightweight web application framework.

Maintainers

Package info

github.com/yourjhay/simple-php

Homepage

Type:project

pkg:composer/reyjhon/simple-php

Statistics

Installs: 105

Dependents: 0

Suggesters: 0

Stars: 3

Open Issues: 0

v3.2.5 2026-06-27 11:34 UTC

README

Latest Stable Version Total Downloads License Monthly Downloads

About Simple

The Simple PHP is a lightweight web application micro framework.

  • Model, View, Controller Pattern
  • Simple Routing engine with regex variables, groups, HTTP method filters
  • Auto-wiring controller method arguments (Request, FormRequest, services)
  • FormRequest validation with automatic validation before controller execution
  • Full-featured validation library (76+ rules, 16+ filters, custom callbacks)
  • CLI console with generators (controllers, models, requests, observers, auth)
  • Uses Twig Template Engine (optional, plain HTML also supported)
  • Resource-friendly database connectivity (PDO)
  • Environment Configuration (.env)
  • Error handling and logging (Whoops for dev, clean error pages for production)
  • Controller action suffix for auth middleware (before/after hooks)
  • Encryption library (defuse/php-encryption)
  • Resource routes
  • PSR-4 autoloading with namespaces

FULL DOCUMENTATION

https://simply.rjhon.net

Installation

Via Composer (recommended):

composer create-project reyjhon/simple-php
cd simple-php

Quick Start

Basic Route

Router::set('/', ['controller' => 'home', 'action' => 'index']);

Controller with Auto-wired Request

use Simple\Request;

class HomeController extends Controller
{
    public function index(Request $request)
    {
        $name = $request->get('name');
        return view('home.index', ['name' => $name]);
    }
}

FormRequest Validation

Generate a form request:

php cli make:request StoreProductRequest

Use it in a controller:

use App\Requests\StoreProductRequest;

class ProductController extends Controller
{
    public function store(StoreProductRequest $request)
    {
        $data = $request->validated();
        Product::create($data);
        return view('product.show', ['product' => $data]);
    }
}

VIEWS

This micro framework uses Twig for the template engine. But it is optional. You can use plain HTML without Twig.

  • Views must be located in app/Views directory.
  • All views must be named with suffix view before the file extension. e.g.: welcome.view.html, product.view.html
  • View cache can be enabled or disabled in the application config.

When rendering a view (with Twig):

return view('welcome');

When a view is inside a folder, include the folder then view name separated by a period:

return view('your_folder.welcome');

Please read the Twig documentation for more information: https://twig.symfony.com/doc/3.x/

NOTE:

  • Views must be a valid HTML file: e.g. welcome.view.html
  • Layout files can be Twig files: e.g. layout.twig, master.twig

When rendering a plain HTML view:

Pass a third parameter 'normal' to render without the template engine:

return view('welcome', [], 'normal');

NOTE:

  • Views must be valid PHP files: e.g. welcome.view.php
  • Normal rendering does not support inheritance
  • The second parameter holds variables to pass. If empty, it must be initialized.

Validation

Simply includes a full validation library with 76+ validation rules and 16+ filters.

use Simple\Validation\Validator as Validate;

$result = Validate::is_valid($_POST, [
    'name'  => 'required|min_len:3|max_len:255',
    'email' => 'required|valid_email',
    'age'   => 'required|numeric|min_numeric:18',
]);

Read the full validation documentation at: https://simply.rjhon.net/documentation/v1/lib/validation

Encryption

Simply offers encryption using defuse/php-encryption.

Run this command once:

php cli key:generate

Encrypt

use Simple\Security\SimplyEncrypt;

$encrypted = SimplyEncrypt::encrypt('secret text');

Decrypt

use Simple\Security\SimplyDecrypt;

$decrypted = SimplyDecrypt::decrypt($ciphertext);

CLI Commands

Command Description
php cli make:controller Generate a controller
php cli make:model Generate a model
php cli make:request Generate a FormRequest class
php cli make:observer Generate an observer
php cli make:auth Scaffold authentication
php cli serve Start PHP development server
php cli key:generate Generate application key
php cli route:list List all registered routes

Routing

Basic

Router::set('products', [
    'controller' => 'ProductController',
    'action'     => 'index'
]);

With variables

Router::set('products/{id:\d+}', [
    'controller' => 'ProductController',
    'action'     => 'show'
]);

Resource routes

Router::resource('products', 'ProductController');
// Generates: index, create, store, show, edit, update, destroy

Route groups

Router::group('admin', function () {
    Router::get('users', ['controller' => 'AdminController', 'action' => 'users']);
});

Full FQCN

Router::set('admin/{action}', [
    'controller' => 'App\Controllers\Admin\AdminController'
]);

Coding Style

PSR-12 Extended Coding Standard: https://www.php-fig.org/psr/psr-12/

Dependencies