2021-12-07 16:26:34 +00:00
|
|
|
<?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()
|
|
|
|
{
|
2021-12-08 21:19:20 +00:00
|
|
|
parent::__construct("Spark", APP_VERSION);
|
2021-12-07 16:26:34 +00:00
|
|
|
self::$instance = $this;
|
|
|
|
|
|
|
|
$this->resourceManager = new ResourceManager();
|
|
|
|
$this->pluginManager = new PluginManager();
|
|
|
|
|
2021-12-08 21:19:20 +00:00
|
|
|
$this->environment = Environment::createFromDirectory(null, true);
|
2021-12-07 16:26:34 +00:00
|
|
|
$this->environment->loadEnvironment();
|
|
|
|
|
|
|
|
$this->add(new Commands\RunCommand());
|
|
|
|
$this->add(new Commands\ResourcesCommand());
|
|
|
|
$this->add(new Commands\ReplCommand());
|
2021-12-08 01:36:46 +00:00
|
|
|
$this->add(new Commands\InitCommand());
|
2021-12-07 16:26:34 +00:00
|
|
|
|
2021-12-08 23:12:37 +00:00
|
|
|
if (getenv("SPARK_PLUGINS")) {
|
|
|
|
$this->add(new Commands\PluginsCommand());
|
|
|
|
}
|
|
|
|
|
2021-12-07 16:26:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|