Code Monkey home page Code Monkey logo

demo's Introduction

PHP-DI application demo

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

Screenshot

Disclaimer

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.

Run

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

git clone https://github.com/PHP-DI/demo.git
cd demo/
composer install

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

php -S 0.0.0.0:8000 -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

Architecture

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's People

Contributors

mnapoli avatar raceybe avatar alexhupe avatar planutim avatar wirebox-platform avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.