2020-07-15 21:05:41 +00:00
|
|
|
<?php
|
|
|
|
|
2020-10-20 21:29:50 +00:00
|
|
|
namespace Alltube\Factory;
|
2020-07-15 21:05:41 +00:00
|
|
|
|
2020-10-20 21:29:50 +00:00
|
|
|
use Alltube\Config;
|
|
|
|
use Alltube\Exception\ConfigException;
|
|
|
|
use Alltube\UglyRouter;
|
2020-10-17 22:59:19 +00:00
|
|
|
use Slim\Container;
|
2020-07-15 21:05:41 +00:00
|
|
|
use Symfony\Component\ErrorHandler\Debug;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ConfigFactory
|
|
|
|
* @package Alltube
|
|
|
|
*/
|
|
|
|
class ConfigFactory
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
2020-10-20 21:29:50 +00:00
|
|
|
* @param Container $container
|
2020-07-15 21:05:41 +00:00
|
|
|
* @return Config
|
2020-10-20 21:29:50 +00:00
|
|
|
* @throws ConfigException
|
2020-07-15 21:05:41 +00:00
|
|
|
*/
|
2020-12-17 21:43:05 +00:00
|
|
|
public static function create(Container $container): Config
|
2020-07-15 21:05:41 +00:00
|
|
|
{
|
2021-02-09 21:35:32 +00:00
|
|
|
$configPath = $container->get('root_path') . '/config/config.yml';
|
2020-07-15 21:05:41 +00:00
|
|
|
if (is_file($configPath)) {
|
2020-10-17 20:07:07 +00:00
|
|
|
$config = Config::fromFile($configPath);
|
|
|
|
} else {
|
|
|
|
$config = new Config();
|
2020-07-15 21:05:41 +00:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|