2020-04-21 11:53:19 +02:00
|
|
|
<?php
|
|
|
|
|
2023-02-03 20:41:59 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-04-21 11:53:19 +02:00
|
|
|
namespace Engelsystem\Helpers;
|
|
|
|
|
|
|
|
use Carbon\CarbonTimeZone;
|
|
|
|
use Engelsystem\Config\Config;
|
|
|
|
use Engelsystem\Container\ServiceProvider;
|
2023-01-24 19:23:57 +01:00
|
|
|
use Engelsystem\Environment;
|
2020-04-21 12:39:54 +02:00
|
|
|
use Engelsystem\Exceptions\Handler;
|
|
|
|
use Engelsystem\Exceptions\Handlers\HandlerInterface;
|
2020-04-21 11:53:19 +02:00
|
|
|
|
|
|
|
class ConfigureEnvironmentServiceProvider extends ServiceProvider
|
|
|
|
{
|
2022-12-14 19:15:20 +01:00
|
|
|
public function register(): void
|
2020-04-21 11:53:19 +02:00
|
|
|
{
|
|
|
|
/** @var Config $config */
|
|
|
|
$config = $this->app->get('config');
|
|
|
|
|
|
|
|
$timezone = new CarbonTimeZone($config->get('timezone'));
|
|
|
|
$this->setTimeZone($timezone);
|
2020-04-21 12:19:31 +02:00
|
|
|
|
|
|
|
$this->displayErrors(false);
|
|
|
|
if ($config->get('environment') == 'development') {
|
|
|
|
$this->displayErrors(true);
|
|
|
|
$this->errorReporting(E_ALL);
|
2020-04-21 12:39:54 +02:00
|
|
|
$this->setupDevErrorHandler();
|
2020-04-21 12:19:31 +02:00
|
|
|
}
|
2020-04-21 11:53:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
protected function setTimeZone(CarbonTimeZone $timeZone): void
|
2020-04-21 11:53:19 +02:00
|
|
|
{
|
2022-12-25 11:59:45 +01:00
|
|
|
ini_set('date.timezone', (string) $timeZone);
|
2023-02-03 15:04:24 +01:00
|
|
|
date_default_timezone_set((string) $timeZone);
|
2020-04-21 11:53:19 +02:00
|
|
|
}
|
2020-04-21 12:19:31 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
protected function displayErrors(bool $displayErrors): void
|
2020-04-21 12:19:31 +02:00
|
|
|
{
|
|
|
|
ini_set('display_errors', $displayErrors);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
protected function errorReporting(int $errorReporting): void
|
2020-04-21 12:19:31 +02:00
|
|
|
{
|
|
|
|
error_reporting($errorReporting);
|
|
|
|
}
|
2020-04-21 12:39:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup the development error handler
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
protected function setupDevErrorHandler(): void
|
2020-04-21 12:39:54 +02:00
|
|
|
{
|
|
|
|
/** @var Handler $errorHandler */
|
|
|
|
$errorHandler = $this->app->get('error.handler');
|
2023-01-24 19:23:57 +01:00
|
|
|
$errorHandler->setEnvironment(Environment::DEVELOPMENT);
|
2020-04-21 12:39:54 +02:00
|
|
|
$this->app->bind(HandlerInterface::class, 'error.handler.development');
|
|
|
|
}
|
2020-04-21 11:53:19 +02:00
|
|
|
}
|