This package provides factory interfaces for a domain-driven design (DDD) approach.
Install the package via Composer:
composer require jardisport/factory- PHP >= 8.2
The package provides a FactoryInterface that defines a standard method for creating objects with support for versioning, dynamic parameters, and shared (singleton) instances.
use JardisPort\Factory\FactoryInterface;
// Get a new instance
$service = $factory->get(MyService::class);
// With a specific version
$service = $factory->get(MyService::class, 'v2');
// With constructor parameters
$service = $factory->get(MyService::class, null, $param1, $param2);$className: The fully qualified class name to instantiate$classVersion: Optional version string for versioned class creation...$parameters: Variadic parameters passed to the class constructor
Register classes as shared to reuse the same instance per (className, version) combination:
// Register a single class
$factory->registerShared(MyService::class);
// Register multiple classes
$factory->registerShared([MyService::class, AnotherService::class]);Shared instances are instantiated once and reused on subsequent get() calls. Only use for stateless services — stateful objects (entities, DTOs, handlers with mutable state) must not be registered.
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/phpcsA pre-commit hook is automatically installed via Composer's post-install script to ensure code quality before commits.
This project is licensed under the MIT License - see the LICENSE file for details.
- Issues: GitHub Issues
- Email: devcore@headgent.dev
- Jardis Core Development (jardisCore@headgent.dev)
- factory
- interfaces
- JardisPort
- Headgent
- DDD (Domain-Driven Design)