jardispsr/factory

This package provides a factory interfaces for a domain driven design approach

Installs: 84

Dependents: 2

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Language:Makefile

pkg:composer/jardispsr/factory

1.0.0 2025-12-03 12:58 UTC

This package is auto-updated.

Last update: 2025-12-03 12:58:27 UTC


README

Build Status License: MIT PHP Version PHPStan Level PSR-4 PSR-12

This package provides factory interfaces for a domain-driven design (DDD) approach.

Installation

Install the package via Composer:

composer require jardispsr/factory

Requirements

  • PHP >= 8.2

Usage

The package provides a FactoryInterface that defines a standard method for creating objects with support for versioning and dynamic parameters.

use JardisPsr\Factory\FactoryInterface;

class MyFactory implements FactoryInterface
{
    /**
     * @template T
     * @param class-string<T> $className
     * @param ?string $classVersion
     * @param mixed ...$parameters
     * @return T|mixed
     */
    public function get(string $className, ?string $classVersion = null, ...$parameters): mixed
    {
        // Your factory implementation
        return new $className(...$parameters);
    }
}

Parameters

  • $className: The fully qualified class name to instantiate
  • $classVersion: Optional version string for versioned class creation
  • ...$parameters: Variadic parameters passed to the class constructor

Development

Code Quality

The project uses PHPStan for static analysis and PHP_CodeSniffer for code style checks:

# Run PHPStan
vendor/bin/phpstan analyse

# Run PHP_CodeSniffer
vendor/bin/phpcs

Pre-commit Hook

A pre-commit hook is automatically installed via Composer's post-install script to ensure code quality before commits.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

Authors

Keywords

  • factory
  • interfaces
  • JardisPsr
  • Headgent
  • DDD (Domain-Driven Design)