exampleapp/modules/Tasks/Factory.php

76 lines
2.0 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Modules\Tasks;
use Modules\Tasks\Interfaces\IModulesProvider;
use Modules\Tasks\Application\Factory as AppFactory;
use Modules\Tasks\Infrastructure\Factory as InfrastructureFactory;
use Modules\Tasks\Dto\Factory as DtoFactory;
class Factory
{
const TASKS_TABLE = 'tasks_table';
private array $settings = [];
private IModulesProvider $modulesProvider;
private ?AppFactory $appFactory = null;
private ?InfrastructureFactory $infrastructureFactory = null;
private ?DtoFactory $dtoFactory = null;
public function loadSettings(array $settings): void
{
$this->settings = $settings;
}
public function getSetting(string $key)
{
return $this->settings[$key];
}
public function injectModules(IModulesProvider $provider): void
{
// Так сделано для предотвращения проблем с циклической зависимостью
$this->modulesProvider = $provider;
}
public function getModulesProvider(): IModulesProvider
{
return $this->modulesProvider;
}
public function getApplicationFactory(): AppFactory
{
if ($this->appFactory) {
return $this->appFactory;
}
$this->appFactory = new AppFactory();
$this->appFactory->setModuleFactory($this);
return $this->appFactory;
}
public function getInfrastructureFactory(): InfrastructureFactory
{
if ($this->infrastructureFactory) {
return $this->infrastructureFactory;
}
$this->infrastructureFactory = new InfrastructureFactory();
$this->infrastructureFactory->setModuleFactory($this);
return $this->infrastructureFactory;
}
public function getDtoFactory(): DtoFactory
{
if ($this->dtoFactory) {
return $this->dtoFactory;
}
$this->dtoFactory = new DtoFactory;
$this->dtoFactory->setModuleFactory($this);
return $this->dtoFactory;
}
}