Skip to content
Go to file

Latest commit


Failed to load latest commit information.

PHP-DI application demo

This repository demonstrates how to write a simple application using PHP-DI without any framework.



Watch out, this project is meant to show how to build an application from scratch with PHP-DI in the simplest way possible. Be aware that this code is only meant for learning purposes and should probably not go to production as-is.

Improvements and pull requests are welcome.


To run this demo, you need to clone it and install dependencies:

git clone
cd demo/
composer install

You can then run the web application using PHP's built-in server:

php -S -t web/

The web application is running at http://localhost:8000.

You can also run the CLI application:

php console.php

The following commands are available:

  • php console.php articles: lists the blog articles
  • php console.php article [id]: displays a blog article by its ID


The container is created in app/bootstrap.php. The configuration file for the container is app/config.php.

Both the web application and the CLI application require app/bootstrap.php to get the container:

  • the web application (web/index.php) uses FastRoute for routing, and then creates and invokes the controller using PHP-DI
  • the CLI application (console.php) uses Silly: Silly uses the container to create and invoke the commands

You will note that in both case, the controllers/commands are instantiated and invoked by PHP-DI: this is to benefit from dependency injection in those classes.


Demo of a simple application built using PHP-DI




No releases published


No packages published
You can’t perform that action at this time.