2016-07-29 07:58:48 +02:00
|
|
|
<?php namespace Todaymade\Daux\Console;
|
|
|
|
|
|
|
|
use Symfony\Component\Console\Command\Command as SymfonyCommand;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
2017-11-05 23:56:46 +01:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
2016-07-29 07:58:48 +02:00
|
|
|
use Todaymade\Daux\Daux;
|
|
|
|
|
|
|
|
class DauxCommand extends SymfonyCommand
|
|
|
|
{
|
2017-11-05 23:56:46 +01:00
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
->addOption('configuration', 'c', InputOption::VALUE_REQUIRED, 'Configuration file')
|
|
|
|
->addOption('value', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Set different configuration values')
|
|
|
|
->addOption('source', 's', InputOption::VALUE_REQUIRED, 'Where to take the documentation from')
|
|
|
|
->addOption('processor', 'p', InputOption::VALUE_REQUIRED, 'Manipulations on the tree');
|
2017-12-08 16:29:44 +01:00
|
|
|
|
|
|
|
// HTML Format only
|
|
|
|
$this->addOption('themes', 't', InputOption::VALUE_REQUIRED, 'Set a different themes directory');
|
2017-11-05 23:56:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function setValue(&$array, $key, $value)
|
|
|
|
{
|
|
|
|
if (is_null($key)) {
|
|
|
|
return $array = $value;
|
|
|
|
}
|
|
|
|
$keys = explode('.', $key);
|
|
|
|
while (count($keys) > 1) {
|
|
|
|
$key = array_shift($keys);
|
|
|
|
if (! isset($array[$key]) || ! is_array($array[$key])) {
|
|
|
|
$array[$key] = [];
|
|
|
|
}
|
|
|
|
$array = &$array[$key];
|
|
|
|
}
|
|
|
|
$array[array_shift($keys)] = $value;
|
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function applyConfiguration(array $options, Daux $daux)
|
|
|
|
{
|
|
|
|
$values = array_map(
|
|
|
|
function ($value) {
|
|
|
|
return array_map("trim", explode('=', $value));
|
|
|
|
},
|
|
|
|
$options
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($values as $value) {
|
|
|
|
$this->setValue($daux->options, $value[0], $value[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-29 07:58:48 +02:00
|
|
|
protected function prepareDaux(InputInterface $input)
|
|
|
|
{
|
|
|
|
$daux = new Daux(Daux::STATIC_MODE);
|
|
|
|
|
|
|
|
// Set the format if requested
|
|
|
|
if ($input->hasOption('format') && $input->getOption('format')) {
|
|
|
|
$daux->getParams()->setFormat($input->getOption('format'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the source directory
|
|
|
|
if ($input->getOption('source')) {
|
|
|
|
$daux->getParams()->setDocumentationDirectory($input->getOption('source'));
|
|
|
|
}
|
|
|
|
|
2016-09-21 23:30:01 +02:00
|
|
|
if ($input->getOption('themes')) {
|
|
|
|
$daux->getParams()->setThemesDirectory($input->getOption('themes'));
|
|
|
|
}
|
|
|
|
|
2016-07-29 07:58:48 +02:00
|
|
|
$daux->initializeConfiguration($input->getOption('configuration'));
|
|
|
|
|
|
|
|
if ($input->hasOption('delete') && $input->getOption('delete')) {
|
|
|
|
$daux->getParams()['confluence']['delete'] = true;
|
|
|
|
}
|
|
|
|
|
2017-11-05 23:56:46 +01:00
|
|
|
if ($input->hasOption('value')) {
|
|
|
|
$this->applyConfiguration($input->getOption('value'), $daux);
|
|
|
|
}
|
|
|
|
|
2016-07-29 07:58:48 +02:00
|
|
|
return $daux;
|
|
|
|
}
|
|
|
|
}
|