for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Riesenia\Pohoda;
use DomainException;
use ReflectionClass;
use ReflectionException;
class AgendaFactory
{
public function __construct(
protected readonly Common\NamespacesPaths $namespacesPaths,
protected readonly ValueTransformer\SanitizeEncoding $sanitizeEncoding,
protected Common\OptionsResolver\Normalizers\NormalizerFactory $normalizerFactory = new Common\OptionsResolver\Normalizers\NormalizerFactory(),
) {}
/**
* @param string $name
* @throws DomainException
* @return AbstractAgenda
*/
public function getAgenda(string $name): AbstractAgenda
/** @var class-string<AbstractAgenda> $className */
$className = __NAMESPACE__ . '\\' . $name;
try {
$reflection = new ReflectionClass($className);
} catch (ReflectionException) {
throw new DomainException('Agenda class does not exists: ' . $name);
}
if (!$reflection->isInstantiable()) {
throw new DomainException('Agenda class cannot be initialized: ' . $name);
$instance = $reflection->newInstance(
$this->namespacesPaths,
$this->sanitizeEncoding,
$this->normalizerFactory,
);
// @codeCoverageIgnoreStart
throw new DomainException('Agenda class initialization failed: ' . $name);
// @codeCoverageIgnoreEnd
if (!is_a($instance, AbstractAgenda::class)) {
throw new DomainException('Agenda class is not an instance of AbstractAgenda: ' . $name);
return $instance;