The SitePoint PHP blog has an interesting tutorial posted from author Deji Akala showing you how to create a "single file Symfony application" using the MicroKernelTrait, a recently added piece of functionality that, while added for other uses, can be easily adapted to make a "Single File Application".
A Single Page Application (SPA) offers a desktop experience to users of a web application by loading a single HTML page, and dynamically updating it as required without reloading. However, a Symfony application may have hundreds of classes, and in a basic application we end up with lots of files we don’t really need.
The latest versions of Symfony (2.8 and 3.0) introduce us to the concept of a Single File Application (SFA) – a super-slim application or micro-framework implemented in one file.
The tutorial is then broken down into three steps towards creating this application:
- Step 1: Install Barebones Symfony
- Step 2: The Front Controller
- Step 3: The Kernel Class
The last step in that process is where most of the code is created and the work is done. It helps you build out the "SfaKernel" class (using MicroKernelTrait), add a few basic routes and the handlers to match them. There's also a bit about container configuration and adding in other bundles you might need. The tutorial finishes out with a look at potential use cases for a single file application like this such as microservices.