Skip to content

markc/spe

Simple PHP Examples (SPE)

PHP 8.5 SQLite License: MIT CI Release Website Tutorial Built with Claude Code

Copyright (C) 2015-2025 Mark Constable mc@netserva.org (MIT License)

A progressive PHP 8.5 micro-framework tutorial in 10 chapters. Each chapter builds on the previous, demonstrating modern PHP features and design patterns.

Features

Feature Description
Pipe Operator PHP 8.5's |> for elegant data transformation chains
Micro-Framework Minimal MVC architecture without heavy dependencies
CRUD Operations Complete Create, Read, Update, Delete, List pattern
PSR-4 Autoloading Modern Composer-based class loading
SQLite + PDO Lightweight database with type-safe queries
Custom CSS No Bootstrap - minimal responsive styling (~270 lines)
Plugin System Extensible architecture with meta.json configuration
Full CMS Blog, Pages, Categories, Auth, User management

Modern PHP Showcase

// PHP 8.5 Pipe operator with first-class callables
$value = $input
    |> trim(...)
    |> strtolower(...)
    |> (fn($s) => filter_var($s, FILTER_SANITIZE_URL));

// PHP 8.4 Asymmetric visibility
public private(set) string $page;

// PHP 8.3 Typed constants + Override attribute
private const string DEFAULT = 'home';
#[\Override] public function list(): array { ... }

// PHP 8.2 Readonly classes
final readonly class PluginMeta { ... }

// PHP 8.1 Enums
enum QueryType { case All; case One; case Column; }

Video Tutorials

Watch the complete tutorial series on YouTube - 10 chapters with AI narration covering all framework features.

Want to create your own tutorial videos? See 00-Tutorial for the video generation pipeline.

Requirements

  • PHP 8.5+ (for pipe operator |>)
  • Composer (for chapters 05-09)

Local-first: PHP 8.5 isn't widely deployed yet. Run locally with php -S localhost:8000 to learn and experiment.

Quick Start

git clone https://github.com/markc/spe
cd spe
composer install
php -S localhost:8000

Open http://localhost:8000 to see the chapter index.

Chapters

# Name Description Key Feature
00 Tutorial Video generation pipeline Playwright + Piper TTS
01 Simple Single-file anonymous class Pipe operator basics
02 Styled Custom CSS, dark mode Toast notifications
03 Plugins Plugin architecture CRUDL pattern
04 Themes Model/View separation Multiple layouts
05 Autoload PSR-4 autoloading Composer integration
06 Session Session management State persistence
07 PDO Database access SQLite + QueryType enum
08 Users User management Full CRUDL operations
09 Blog Complete CMS Auth, Blog, Docs, Categories
10 YouTube YouTube Manager OAuth, API, Shared Services

Architecture

URL: ?o=Home&m=list&t=TopNav

o = Object/Plugin name
m = Method/Action (CRUDL: create, read, update, delete, list)
t = Theme (Simple, TopNav, SideBar)

Request Flow

index.php → Init(Ctx) → {Plugin}Model→method() → {Plugin}View→method() → HTML

Directory Structure (chapters 05-09)

XX-Chapter/
├── public/
│   └── index.php          # Entry point
└── src/
    ├── Core/              # Framework classes (Init, Ctx, Db, Plugin, Theme)
    ├── Plugins/           # Feature plugins (Model + View + meta.json)
    └── Themes/            # Layout themes (Simple, TopNav, SideBar)

Styling

No Bootstrap! Custom spe.css (~270 lines):

  • CSS variables for light/dark theming
  • @media (prefers-color-scheme: dark) automatic dark mode
  • Manual toggle via localStorage
  • Responsive layouts (TopNav, SideBar)
  • Dropdown menus, toast notifications, card grids

License

MIT License - See individual file headers for copyright notices.