php-spark/src/SparkApplication.php

83 lines
2.2 KiB
PHP

<?php
namespace Spark;
use Psr\Log\LoggerInterface;
use Spark\Environment\Environment;
use Spark\Plugin\PluginManager;
use Spark\Resource\ResourceManager;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\OutputInterface;
class SparkApplication extends Application
{
public static SparkApplication $instance;
private Environment $environment;
private ResourceManager $resourceManager;
private PluginManager $pluginManager;
private LoggerInterface $logger;
public function __construct()
{
parent::__construct("Spark\u{26a1}", APP_VERSION);
self::$instance = $this;
$this->resourceManager = new ResourceManager();
$this->pluginManager = new PluginManager();
$this->environment = Environment::createFromDirectory(null, true);
$this->environment->loadEnvironment();
$this->add(new Commands\RunCommand());
$this->add(new Commands\ResourcesCommand());
$this->add(new Commands\ReplCommand());
$this->add(new Commands\InitCommand());
$this->get("list")->setHidden(true);
$this->get("completion")->setHidden(true);
$this->get("help")->setHidden(true);
if (getenv("SPARK_PLUGINS")) {
$this->add(new Commands\PluginsCommand());
}
}
public function getPluginManager(): PluginManager
{
return $this->pluginManager;
}
public function getEnvironment(): Environment
{
// if (empty($this->environment)) {
// $this->environment = Environment::createFromDirectory();
// $this->environment->setLogger($this->logger);
// }
return $this->environment;
}
public function getResourceManager(): ResourceManager
{
return $this->resourceManager;
}
public function getLogger(): LoggerInterface
{
return $this->logger;
}
public function doRun(InputInterface $input, OutputInterface $output)
{
$this->logger = new ConsoleLogger($output);
parent::doRun($input, $output);
}
}