php-spark/plugins/com.noccy.docker/sparkplug.php
Christopher Vagnetoft 538383c33d PDO plugin: Reflections
* com.noccy.pdo: Implemented reflection for PDO databases,
  tables and columns. Reflectors for MySQL and Sqlite.
* com.noccy.pdo: Added pdo:inspect command.
* com.noccy.docker: Added basic stack management and commands.
* com.noccy.docker: Moved commands to dedicated namespace.
* Environment: readConfig and writeConfig helper added, with
  a flag to use the global config dir ~/.config/spark.
2021-12-24 01:27:57 +01:00

59 lines
1.8 KiB
PHP

<?php // "name":"Docker plugin for SparkPlug", "author":"Noccy"
namespace SparkPlug\Com\Noccy\Docker;
use Spark\Commands\Command;
use SparkPlug;
use SparkPlug\Com\Noccy\Docker\DockerCompose\Stack;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class DockerPlug extends SparkPlug
{
private array $compose = [];
private Stack $composeStack;
public function load()
{
$config = read_config("docker.json");
$docker = $config['docker']??[];
$hasCompose = array_key_exists('compose', $docker);
$hasBuild = array_key_exists('build', $docker);
if ($hasCompose) {
$this->compose = $docker['compose'];
}
if ($hasCompose || $hasBuild) {
register_command(new Commands\DockerUpCommand);
register_command(new Commands\DockerDownCommand);
register_command(new Commands\DockerStatusCommand);
register_command(new Commands\DockerDbExportCommand);
}
if ($hasBuild) {
register_command(new Commands\DockerBuildCommand);
register_command(new Commands\DockerExecCommand);
}
register_command(new Commands\Stack\StatusCommand);
register_command(new Commands\Stack\RegisterCommand);
register_command(new Commands\Stack\UnregisterCommand);
}
public function getComposeStack(): ?Stack
{
$base = $this->getProjectDirectory();
if (empty($this->composeStack)) {
$composeFile = $base . "/" . ($this->compose['file']??'docker-compose.yml');
$this->composeStack = new Stack($composeFile);
}
return $this->composeStack;
}
}
//if (file_exists(get_environment()->getConfigDirectory()."/maker.json")) {
register_plugin("com.noccy.docker", new DockerPlug());
//}