Files
backupscript/src/App.php

62 lines
1.4 KiB
PHP
Raw Normal View History

2023-05-31 14:34:35 +00:00
<?php
namespace App;
use Symfony\Component\Yaml\Yaml;
use Symfony\Component\Yaml\Exception\ParseException;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
2023-05-31 14:42:43 +00:00
use Psr\Log\NullLogger;
2023-05-31 14:34:35 +00:00
2023-06-05 09:40:04 +00:00
/**
* Application class
*
* Mostly working as a register pattern for the logging and configuration.
*
* @author Jens True <jens.chr.true@gmail.com>
* @license https://opensource.org/licenses/gpl-license.php GNU Public License
2023-06-05 09:43:50 +00:00
* @link https://jcktrue.dks
2023-06-05 09:40:04 +00:00
*/
2023-06-01 09:16:19 +00:00
class App
{
2023-05-31 14:34:35 +00:00
protected Logger $logger;
protected array $config;
2023-06-05 09:40:04 +00:00
/**
* Create a new instance providing a config file
*
* @param string $configFile Relative or full path to YML config.
*/
2023-05-31 14:34:35 +00:00
function __construct(string $configFile)
{
$this->config = Yaml::parseFile($configFile);
$logger = new Logger('app');
2023-06-01 09:16:19 +00:00
if (isset($this->config['log'])) {
2023-05-31 14:42:43 +00:00
$logger->pushHandler(new StreamHandler($this->getConfig()['log']));
}
2023-05-31 14:34:35 +00:00
$logger->info("Initialization complete");
2023-05-31 14:42:43 +00:00
2023-05-31 14:34:35 +00:00
$this->logger = $logger;
}
2023-06-05 09:40:04 +00:00
/**
* Get the full configuration
*
* @return array Full configuration structure
*/
2023-05-31 14:34:35 +00:00
function getConfig() : array
{
return $this->config;
}
2023-06-05 09:40:04 +00:00
/**
* Get the logger instance.
*
* @return Logger Instance of logger
*/
2023-05-31 14:34:35 +00:00
function getLogger() : Logger
{
return $this->logger;
}
}