This is a simple project to demonstrate the way in which I used PHP-DI within a Slim PHP app, as wanted to use its Autowiring abilities.
This project uses Slim's Flash Messages, CSRF Middleware, Twig views, Noodlehaus's Config, and Monolog's logger to log when errors occur. It connects to a SQLite3 database using Illuminate.
There is also a simple csrfToken check within App.php which avoids the CSRF Middleware for specified routes, as it uses a session CSRF token, so is useful for Ajax forms that may send multiple HTTP requests from one page.
Most of the Interfaces are all dummy interfaces, existing purely for PHP-DI's autowiring to work.
There are some Developer mode settings withing bootstrap.php. The port 8080 config file is for when using the inbuilt PHP server with the command
php -S localhost:8080 -t ./public/
from within your project folder, then the url will be
If using Apache on your dev machine, then the defaul url for the project will be something like
http://localhost/slim-phpdi-starter/public/index.php
The config.php file pulls in some keys and other details from a local json file, in the directory secrets/dev_secrets.json
If you are using mySql database, then it might look something like this.
{
"CUSTOM": {
},
"MYSQL": {
"DATABASE": "db",
"HOST": "127.0.0.1",
"PASSWORD": "root",
"PORT": "3306",
"TUNNEL": "",
"USER": "root"
},
"DEV": {
"app.base_path": "/test/public/index.php",
"app.cdn": "http://localhost",
"app.css": "/test/public/css",
"app.js": "/test/public/js",
"app.images": "/test/public/img",
"logger.name": "test",
"logger.path": "../../logs/test.log"
}
}
The dev_secrets.json file included in the project is just a sample. You should not include it in source control, so your .gitignore file will need the line dev_secrets.json
added.
There is a simple video of how the sample project should work at http://somup.com/cDXu62JCm