Lab 15: Capstone — Mini MVC Framework

Objective

Build a production-quality mini MVC framework from scratch combining all practitioner techniques: PSR-4 autoloading, trait-based model system, typed collections, Repository pattern with PDO, middleware pipeline, REST router, Observer-driven events, functional pipelines, and a full test suite — all without external dependencies.

Background

Laravel, Symfony, and Slim are built on the exact same PHP primitives you've learned across labs 1–14. This capstone assembles them into a cohesive mini-framework with: a DI container, event system, data mapper, REST router, and command runner. After completing this lab, you'll understand what every line of a framework startup sequence does.

Time

50 minutes

Prerequisites

  • All PHP Practitioner labs 01–14

Tools

  • Docker: zchencow/innozverse-php:latest


Lab Instructions

Architecture Overview

Full Implementation

💡 A DI container is just a map of names to factory functions. When you call $container->make("orderService"), it runs the registered factory, which in turn calls $container->make("productRepo") and $container->make("bus"). The singleton() variant caches the result so each make() returns the same instance. This is the entire "magic" behind Laravel's app()->make(), resolve(), and new App service resolution.

📸 Verified Output:


What You Built

Layer
Lab Origin
Purpose

DI Container

Lab 07 (Singleton)

Lazy service wiring

EventBus

Lab 07 (Observer)

Decoupled side effects

Traits (Timestampable, Validatable)

Lab 01

Cross-cutting model concerns

Enums (OrderStatus)

Lab 05 (PHP 8)

Type-safe state machine

Repositories

Lab 04 (PDO)

In-memory data access

OrderService

Lab 03 (Exceptions)

Domain orchestration

pipe()

Lab 06 (Functional)

Analytics pipeline

Integration tests

Lab 08 (Testing)

20/20 assertions

Congratulations! 🎉

You have completed all 15 PHP Practitioner labs. You can now:

  • Design clean multi-layer PHP applications without a framework

  • Implement every major design pattern in PHP

  • Use modern PHP 8.3 type system features correctly

  • Write testable, decoupled code with DI and events

  • Build REST APIs, parse JSON/XML, and handle file streams

Further Reading

Last updated