Start here

Explicit architecture for PHP

Unphramed is an MVC approach to building PHP applications: the web server routes requests directly to PHP controllers, dependencies are assembled in PHP, and views render the results.

The architecture is small enough to follow from a URL to the code that handles it.

text
Request → web server → PHP controller → model
                              ↓
                             view → response
On this page

The essential choices

Routing belongs to the web server. Its configuration is loaded at startup or reload. For each request, the server applies those routes and selects a PHP script directly. PHP does not load a routing configuration or run a dispatcher to find the controller.

Controllers are ordinary PHP files. A script in the public directory receives the request, calls the application and selects a response. Shared logic can move into a class when that is useful.

Composer manages dependencies and autoloading. It installs the PHP libraries you choose and generates an autoloader for their classes and your own. The examples use PSR-4 to map an application namespace to src/.

Dependency injection is PHP code. Constructors declare dependencies; typed factories assemble them with new and method calls. You can read and navigate the wiring directly.

MVC leaves your model free. Your application's behavior, storage and libraries are your choices. Views receive prepared data. The examples use typed PHP objects for rendering, but another template engine can fill that role.

Unphramed describes an approach rather than requiring a framework runtime. Compose your application with the libraries that fit its needs, and assemble their objects through explicit PHP factories.

Start small

Write a Hello world, then build a small application with several routes, dependency injection and a form.

For individual mechanisms, read routing, dependency injection and PHP object views. The same PHP examples run with Nginx or Apache; choose the matching routing configuration.

Optional tools

CLI tools for routes and DI, and a PhpStorm plugin, can help edit application routing and PHP factories. They are development conveniences; the application runs without them. Current prototypes are not yet publicly distributed. Every example here works without these tools.