Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Practical PHP examples of SOLID principles across multiple domains (E-commerce, Finance, Health, Education, Social, Travel, Logistics, Gaming, IoT) with bad & good practices and refactoring.

License

Notifications You must be signed in to change notification settings

nourollahr/solid-best-practices-in-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

3 Commits

Repository files navigation

🧩 SOLID Best Practices in PHP

بهترین تمرین‌های SOLID در PHP

PHP License Contributions

This repository shows how to apply SOLID principles in real PHP 8.4 projects —
with Bad vs Good examples across 9 domains like: Health, Finance, Ecommerce, Education, Social, Travel, Logistics, Gaming, IoT.

این مخزن نشان می‌دهد چگونه اصول SOLID را در پروژه‌های واقعی PHP (نسخه 8.4)
با نمونه‌های واقعی از کد بد و کد خوب در ۹ حوزه مختلف مانند: سلامت، مالی، فروشگاه آنلاین، آموزش، شبکه‌های اجتماعی، سفر، لجستیک، بازی، و اینترنت اشیا پیاده‌سازی کنیم.

Each principle is shown with Bad Examples (violating the principle) and Good Examples / Refactored (following the principle).

برای هر اصل، مثال‌های بد (نقض اصل) و مثال‌های خوب / Refactored (رعایت اصل) ارائه شده است.


SOLID Principles / اصول SOLID

  1. SRP - Single Responsibility Principle / اصل مسئولیت واحد
    Each class should have a single responsibility.
    هر کلاس باید یک مسئولیت مشخص داشته باشد.
    Examples → SRP folder

  2. OCP - Open/Closed Principle / اصل باز/بسته
    Software entities should be open for extension but closed for modification.
    موجودیت‌های نرم‌افزاری باید برای توسعه باز و برای تغییر بسته باشند.
    Examples → OCP folder

  3. LSP - Liskov Substitution Principle / اصل جایگزینی لیسکوف
    Subtypes must be substitutable for their base types.
    زیرکلاس‌ها باید قابل جایگزینی با کلاس پایه خود باشند.
    Examples → LSP folder

  4. ISP - Interface Segregation Principle / اصل تفکیک اینترفیس
    Clients should not be forced to depend on interfaces they do not use.
    کلاینت‌ها نباید مجبور شوند به اینترفیس‌هایی که استفاده نمی‌کنند وابسته باشند.
    Examples → ISP folder

  5. DIP - Dependency Inversion Principle / اصل وارونگی وابستگی
    High-level modules should not depend on low-level modules; both should depend on abstractions.
    ماژول‌های سطح بالا نباید به ماژول‌های سطح پایین وابسته باشند؛ هر دو باید به انتزاع‌ها وابسته باشند.
    Examples → DIP folder


Refactoring / Best Practices / بازسازی و بهترین تمرین‌ها

This folder demonstrates how to refactor code to follow SOLID principles.
It includes domain-specific examples where Bad Code is improved into clean, maintainable, and testable code.

این پوشه نشان می‌دهد چگونه می‌توان کد را بازسازی کرد تا اصول SOLID رعایت شود.
شامل مثال‌های حوزه‌ای است که در آن‌ها کد بد به کدی تمیز، قابل نگهداری و تست‌پذیر تبدیل شده است.

Refactoring examples → Refactoring folder


Domains / حوزه‌ها

  • Health / سلامت
  • Finance / مالی
  • Ecommerce / فروشگاه آنلاین
  • Education / آموزش
  • Social / شبکه‌های اجتماعی
  • Travel / سفر
  • Logistics / لجستیک
  • Gaming / بازی
  • IoT / اینترنت اشیا

🚀 Usage / استفاده

  1. Clone the repository / کلون کردن مخزن
git clone https://github.com/nourollahr/solid-best-practices-in-php.git
cd solid-best-practices-in-php
  1. Browse the folders / مرور مثال‌ها هر اصل SOLID و هر حوزه در پوشه‌ی جداگانه قرار دارد.

  2. Run examples with PHP 8.4 / اجرای مثال‌ها با PHP 8.4:

php 1.SRP/Health/BadExample.php

Contribution / مشارکت

We welcome contributions!
از مشارکت شما استقبال می‌کنیم!

Feel free to submit PRs for:

  • Adding new examples
  • Supporting other languages or frameworks
  • Improving existing examples and documentation

می‌توانید PR ارسال کنید برای:

  • افزودن مثال‌های جدید
  • پشتیبانی از زبان‌ها یا فریمورک‌های دیگر
  • بهبود مثال‌ها و مستندات موجود

📄 License / مجوز

This project is licensed under the MIT License.
این پروژه تحت مجوز MIT منتشر شده است.


⭐ Support / حمایت

If this repository helped you, please give it a star to help others find it too!
اگر این ریپو برای شما مفید بود، لطفاً ⭐ ستاره بده تا دیگران هم راحت‌تر پیدایش کنند!

About

Practical PHP examples of SOLID principles across multiple domains (E-commerce, Finance, Health, Education, Social, Travel, Logistics, Gaming, IoT) with bad & good practices and refactoring.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /