بهترین تمرینهای SOLID در PHP
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 (رعایت اصل) ارائه شده است.
-
SRP - Single Responsibility Principle / اصل مسئولیت واحد
Each class should have a single responsibility.
هر کلاس باید یک مسئولیت مشخص داشته باشد.
Examples → SRP folder -
OCP - Open/Closed Principle / اصل باز/بسته
Software entities should be open for extension but closed for modification.
موجودیتهای نرمافزاری باید برای توسعه باز و برای تغییر بسته باشند.
Examples → OCP folder -
LSP - Liskov Substitution Principle / اصل جایگزینی لیسکوف
Subtypes must be substitutable for their base types.
زیرکلاسها باید قابل جایگزینی با کلاس پایه خود باشند.
Examples → LSP folder -
ISP - Interface Segregation Principle / اصل تفکیک اینترفیس
Clients should not be forced to depend on interfaces they do not use.
کلاینتها نباید مجبور شوند به اینترفیسهایی که استفاده نمیکنند وابسته باشند.
Examples → ISP folder -
DIP - Dependency Inversion Principle / اصل وارونگی وابستگی
High-level modules should not depend on low-level modules; both should depend on abstractions.
ماژولهای سطح بالا نباید به ماژولهای سطح پایین وابسته باشند؛ هر دو باید به انتزاعها وابسته باشند.
Examples → DIP folder
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
- Health / سلامت
- Finance / مالی
- Ecommerce / فروشگاه آنلاین
- Education / آموزش
- Social / شبکههای اجتماعی
- Travel / سفر
- Logistics / لجستیک
- Gaming / بازی
- IoT / اینترنت اشیا
- Clone the repository / کلون کردن مخزن
git clone https://github.com/nourollahr/solid-best-practices-in-php.git
cd solid-best-practices-in-php-
Browse the folders / مرور مثالها هر اصل SOLID و هر حوزه در پوشهی جداگانه قرار دارد.
-
Run examples with PHP 8.4 / اجرای مثالها با PHP 8.4:
php 1.SRP/Health/BadExample.php
We welcome contributions!
از مشارکت شما استقبال میکنیم!
Feel free to submit PRs for:
- Adding new examples
- Supporting other languages or frameworks
- Improving existing examples and documentation
میتوانید PR ارسال کنید برای:
- افزودن مثالهای جدید
- پشتیبانی از زبانها یا فریمورکهای دیگر
- بهبود مثالها و مستندات موجود
This project is licensed under the MIT License.
این پروژه تحت مجوز MIT منتشر شده است.
If this repository helped you, please give it a star to help others find it too!
اگر این ریپو برای شما مفید بود، لطفاً ⭐ ستاره بده تا دیگران هم راحتتر پیدایش کنند!