Download the PHP package cmatosbc/desired-patterns without Composer

On this page you can find all versions of the php package cmatosbc/desired-patterns. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package desired-patterns

Modern PHP Design Patterns

PHP Lint PHPUnit Tests PHP Composer Code Coverage

A collection of modern PHP design patterns implemented using PHP 8.2+ features. Sexier than older implementations and more readable than ever.

Requirements

Installation

Patterns Implemented

Quick Links:

1. Singleton Pattern

The Singleton pattern ensures a class has only one instance and provides a global point of access to it. Our implementation uses a trait to make it reusable.

2. Multiton Pattern

The Multiton pattern is similar to Singleton but maintains a map of named instances. This is useful when you need multiple named instances of a class.

3. Command Pattern

The Command pattern encapsulates a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.

4. Chain of Responsibility Pattern

The Chain of Responsibility pattern lets you pass requests along a chain of handlers. Upon receiving a request, each handler decides either to process the request or to pass it to the next handler in the chain.

5. Registry Pattern

The Registry pattern provides a global point of access to objects or services throughout an application.

6. Service Locator Pattern

The Service Locator pattern is a design pattern used to encapsulate the processes involved in obtaining a service with a strong abstraction layer.

7. Specification Pattern

The Specification pattern is used to create business rules that can be combined using boolean logic.

8. Strategy Pattern

The Strategy pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. It lets the algorithm vary independently from clients that use it.

Real-World Examples

  1. Payment Processing

    • Different payment methods (Credit Card, PayPal, Cryptocurrency)
    • Each payment method has its own validation and processing logic
    • System can switch between payment strategies based on user selection
  2. Data Export

    • Multiple export formats (CSV, JSON, XML, PDF)
    • Each format has specific formatting requirements
    • Choose export strategy based on user preference or file type
  3. Shipping Calculation
    • Various shipping providers (FedEx, UPS, DHL)
    • Each provider has unique rate calculation algorithms
    • Select provider based on destination, weight, or cost

Complete Example

9. State Pattern

The State pattern allows an object to alter its behavior when its internal state changes. The object will appear to change its class. Our implementation provides a flexible and type-safe way to handle state transitions with context validation.

Real-World Example: Order Processing System

The State pattern is perfect for managing complex workflows like order processing. Each state encapsulates its own rules and behaviors:

  1. States:

    • PendingState: Initial state, validates order details
    • ProcessingState: Handles payment verification
    • ShippedState: Manages shipping details
    • DeliveredState: Handles delivery confirmation
    • CancelledState: Manages order cancellation
  2. Features:

    • Context validation per state
    • Type-safe state transitions
    • State history tracking
    • Fluent interface for state machine setup
  3. Benefits:

    • Clean separation of concerns
    • Easy to add new states
    • Type-safe state transitions
    • Automatic context validation
    • Comprehensive state history
  4. Use Cases:
    • Order Processing Systems
    • Document Workflow Management
    • Game State Management
    • Payment Processing
    • Task Management Systems

10. Pipeline Pattern

The Pipeline pattern allows you to process data through a series of operations, where each operation takes input from the previous operation and produces output for the next one. This pattern is particularly useful for data transformation, validation, and processing workflows.

Features

Basic Usage

Advanced Usage with PipelineBuilder

The PipelineBuilder provides a more structured way to create complex pipelines with validation and error handling:

Real-World Example: Data Processing Pipeline

Here's a real-world example of using the Pipeline pattern for processing user data:

Benefits

  1. Separation of Concerns: Each operation in the pipeline has a single responsibility.
  2. Maintainability: Easy to add, remove, or modify processing steps without affecting other parts.
  3. Reusability: Pipeline operations can be reused across different contexts.
  4. Error Handling: Built-in error handling makes it easy to manage failures.
  5. Validation: Input validation can be added at any point in the pipeline.
  6. Type Safety: PHP 8.2+ generics provide type safety throughout the pipeline.
  7. Testability: Each operation can be tested in isolation.

Use Cases

11. Object Pool Pattern

The Object Pool pattern manages a fixed set of reusable objects that are expensive to create or consume significant resources. Our implementation uses PHP 8.2 features for type-safe object management and automatic cleanup.

  1. Key Features:

    • Type-safe resource management
    • Automatic resource cleanup using WeakMap
    • Configurable pool sizes
    • Resource validation and reset
    • Usage statistics tracking
  2. Use Cases:
    • Database connection pooling
    • File handle management
    • Network socket management
    • Thread/Process pooling
    • Memory-intensive object reuse

12. Null Object Pattern

The Null Object pattern provides an object with neutral ("null") behavior as an alternative to null references. Our implementation uses PHP 8.2 features for type-safe null handling and interface contracts.

  1. Key Features:

    • Type-safe null object implementation
    • Interface-based contracts
    • Abstract base class for null objects
    • Explicit null checking through interface
    • Zero-impact performance for null operations
  2. Use Cases:
    • Optional service dependencies
    • Testing and development environments
    • Feature toggles and graceful degradation
    • Default behavior implementation
    • Error handling and logging

Testing

Run the test suite using PHPUnit :

Or run it updating the coverage report:

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This library is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.


All versions of desired-patterns with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package cmatosbc/desired-patterns contains the following files

Loading the files please wait ....