Skip to content

Explore the world of Design Patterns in PHP. Discover reusable solutions to common software design challenges through Creational, Structural, and Behavioral Patterns. This project, inspired by the Gang of Four (GoF) design patterns and Refactoring.Guru.

Notifications You must be signed in to change notification settings

eduardoraider/php-design-patterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Design Patterns Repository

Welcome to the PHP Design Patterns repository, where we delve into the exploration of fundamental design patterns in software development. Design patterns serve as standardized solutions to recurring challenges in software design, offering pre-established blueprints that can be tailored to address common issues in code implementation.

Overview

This repository categorizes design patterns into three main groups:

  • Creational Patterns: Enhance flexibility and code reuse through object creation mechanisms.
  • Structural Patterns: Illustrate how to organize objects and classes into larger, flexible, and efficient structures.
  • Behavioral Patterns: Focus on effective communication and the assignment of responsibilities among objects.

All examples in this repository are based on the classic Gang of Four (GoF) design patterns, with PHP implementations inspired by the Refactoring.Guru project.

Motivation

The primary goal of this project is to demonstrate the practical application of Design Patterns using PHP. However, the concepts explored here are transferable to other programming languages such as Go, Rust, Java, Python, TypeScript, and C#, among others.

The repository has been upgraded to PHP 8.3, and testing is made seamless using Docker. Detailed instructions for executing each pattern via the command line in Docker are provided in the README of each pattern.

Expect periodic updates, with a new pattern added every two or three days. The sequence will begin with Behavioral Patterns, followed by Structural Patterns, and finally, Creational Patterns.

Requirements

To run the examples, ensure you have Docker installed on your system. Follow the installation instructions for your operating system on the official Docker documentation.

Getting Started

Follow these steps to set up and use Docker:

  1. Clone the Repository

    git clone https://github.com/eduardoraider/php-design-patterns.git
    cd php-design-patterns
  2. Run Composer Dump

    After cloning the repository, it's essential to run Composer to generate the autoload files:

    composer dump
  3. Build Docker Image

    Navigate to the project directory and build a Docker image:

    docker build -t php-design-patterns-image .
  4. Run Docker Container

    Run a Docker container using the image you built:

    docker run -it --rm -v $(pwd):/app -w /app --name php-design-patterns-container php-design-patterns-image /bin/bash
  5. Access the Pattern Directory

    Navigate to the pattern directory (example):

    cd src/BehavioralDesignPatterns/ChainOfResponsibility

    Launch examples via Docker using the PHP executable:

    php index.php
  6. Manage Containers

    Manage Docker containers using various commands:

    • List all running containers:

      docker ps
    • Stop a container:

      docker stop container_id
    • Remove a container:

      docker rm container_id
    • List all images:

      docker images
    • Remove an image:

      docker rmi image_id

License

This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

Creative Commons License

Credits

Alexander Shvets (@neochief) and Alexey Pyltsyn (@lex111)


by Eduardo O. Raider

🛠 🥋 Software Engineer

About

Explore the world of Design Patterns in PHP. Discover reusable solutions to common software design challenges through Creational, Structural, and Behavioral Patterns. This project, inspired by the Gang of Four (GoF) design patterns and Refactoring.Guru.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published