A simple export management system built with pure PHP using OOP principles and the Factory Design Pattern.
This project demonstrates how to create different export strategies (PDF, TXT, Word, Image) without tightly coupling business logic to concrete implementations.
- Factory Design Pattern
- SOLID Principles
- Open/Closed Principle (OCP)
- Dependency Inversion Principle (DIP)
- Clean OOP Architecture
- Service-Oriented Design
- Extensible Export System
- Export content as PDF
- Export content as TXT
- Export content as Word
- Export content as Image
- Factory-based exporter creation
- Centralized export service
- Download logging support
- Clean and maintainable architecture
Assets/
Classes/
├── FileController.php
├── LogController.php
Config/
├── app.php
├── DBConnection.php
Contracts/
├── ExporterInterface.php
Enums/
├── ExportType.php
Exporters/
├── ImageExporter.php
├── PdfExporter.php
├── TxtExporter.php
├── WordExporter.php
Factories/
├── ExportFactory.php
Helper/
├── GeneralHelperFunction.php
Pages/
├── notfound.php
Services/
├── ExportService.php
vendor/
.htaccess
bootstrap.php
check.php
index.php
composer.json
README.md
The application follows a Factory-based architecture.
User Action
│
▼
ExportService
│
▼
ExportFactory
│
├── PdfExporter
├── TxtExporter
├── WordExporter
└── ImageExporter
The service layer never directly creates exporter objects.
Instead, it delegates object creation to the Factory, making the system easy to extend and maintain.
- User enters content in the editor.
- User selects an export type.
- ExportService receives the request.
- ExportFactory creates the correct exporter instance.
- The selected exporter generates the output.
- The file download is simulated.
The Factory Pattern centralizes object creation.
Instead of:
new PdfExporter();
new TxtExporter();
new WordExporter();the application uses:
$exporter = ExportFactory::make($type);This removes direct dependencies from the business layer.
Adding a new exporter requires only three steps:
class CsvExporter implements ExporterInterface
{
public function export(string $content): void
{
// export logic
}
}case CSV;ExportType::CSV => new CsvExporter(),No existing business logic needs to be modified.
Each exporter is responsible for one export format.
New exporters can be added without modifying existing code.
The service layer depends on abstractions (ExporterInterface) rather than concrete implementations.
- PHP 8.1+
- Composer
- MySQL
Clone the repository:
git clone https://github.com/hesam1996/php-factory.gitInstall dependencies:
composer installImport database:
php_factory.sqlRun the project:
http://127.0.0.1/php-factory Or http://localhost/php-factoryImplemented by Hesam kazembeygi
This project is intended for educational purposes and design pattern practice.