Skip to content

learnphp/SOLID-Principles-PHP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🛠️ PHP SOLID Mini Project with Custom Routing

A lightweight PHP project following the SOLID principles with PSR-4 autoloading and a basic routing system - similar to micro-frameworks like Slim or Laravel, but without using any full-stack framework.


✅ What is SOLID?

SOLID is an acronym for five design principles in object-oriented programming that help you write maintainable, scalable, and robust code.

It stands for:

  • S – Single Responsibility Principle (SRP)
  • O – Open/Closed Principle (OCP)
  • L – Liskov Substitution Principle (LSP)
  • I – Interface Segregation Principle (ISP)
  • D – Dependency Inversion Principle (DIP)

🚀 Features

  • Clean architecture using SOLID principles
  • PSR-4 autoloading via Composer
  • Dependency Injection
  • Simple Router (MVC-style)
  • Organized folder structure
  • Easily extendable (add Stripe, database, etc.)

⚙️ Project Setup Highlights

  • ✔️ Clean autoloading with Composer (no more require_once)
  • ✔️ PSR-4 compliant structure (app/services, app/interfaces, etc.)
  • ✔️ Dependency injection (e.g., Order receives PaymentMethod, MailerInterface, LoggerInterface)

📁 Project Directory Structure

 
project-root/
├── app/
│   ├── controllers/
│   │   └── OrderController.php
│   ├── interfaces/
│   ├── services/
│   └── Order.php
├── public/
│   └── index.php
├── routes/
│   └── web.php
├── vendor/
├── composer.json
├── .htaccess
└── README.md
 

⚙️ Installation

git clone https://github.com/learnphp/SOLID-Principles-PHP.git
cd SOLID-Principles-PHP
composer install
composer dump-autoload -o

If Composer is not installed or your PHP version has compatibility issues, you can install dependencies using the command below:

cd SOLID-Principles-PHP
php composer.phar install # or update

💡 Make sure you have composer.phar in your project root if Composer is not globally installed. Attached composer compatibility for PHP 7.2+ users


🌐 Access in Browser

Start PHP's built-in server:

 
php -S localhost:8000 -t public
 

Then open in browser:


🔁 Routing (routes/web.php)

$routes = [
    '/' => fn() => echo "Welcome!",
    '/order' => fn() => (new OrderController())->checkout(),
];

🚀 Optional Enhancements You Can Add

  • ✅ Add a Stripe class (similar to PayPal) and switch dynamically
  • ✅ Write unit tests using PHPUnit
  • ✅ Use .env for switching between test/live mailers and loggers
  • ✅ Fully implement all SOLID principles (you're already halfway there!)

🙋‍♂️ Need Help?

Feel free to reach out:

Chinmay Kumar Sahu
📧 [email protected]
💬 GitHub: @chinmay235

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages