Move factory classes to a subfolder

This commit is contained in:
Pierre Rudloff 2020-10-20 23:29:50 +02:00
parent 123a6c5ad9
commit 0a220d4d8e
9 changed files with 21 additions and 17 deletions

View file

@ -0,0 +1,45 @@
<?php
namespace Alltube\Factory;
use Alltube\Config;
use Alltube\Exception\ConfigException;
use Alltube\UglyRouter;
use Slim\Container;
use Symfony\Component\ErrorHandler\Debug;
/**
* Class ConfigFactory
* @package Alltube
*/
class ConfigFactory
{
/**
* @param Container $container
* @return Config
* @throws ConfigException
*/
public static function create(Container $container)
{
$configPath = __DIR__ . '/../../config/config.yml';
if (is_file($configPath)) {
$config = Config::fromFile($configPath);
} else {
$config = new Config();
}
if ($config->uglyUrls) {
$container['router'] = new UglyRouter();
}
if ($config->debug) {
/*
We want to enable this as soon as possible,
in order to catch errors that are thrown
before the Slim error handler is ready.
*/
Debug::enable();
}
return $config;
}
}