Allow to use Processors through the new CLI

This commit is contained in:
Stéphane Goetz 2016-11-17 17:02:12 +01:00
parent 2d451be104
commit e5c7747884
3 changed files with 36 additions and 32 deletions

View File

@ -26,7 +26,6 @@
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Todaymade\\Daux\\Extension\\": "daux/",
"Todaymade\\Daux\\": "libs/" "Todaymade\\Daux\\": "libs/"
} }
}, },

View File

@ -17,7 +17,6 @@ class Serve extends DauxCommand
->setName('serve') ->setName('serve')
->setDescription('Serve documentation') ->setDescription('Serve documentation')
->addOption('configuration', 'c', InputOption::VALUE_REQUIRED, 'Configuration file') ->addOption('configuration', 'c', InputOption::VALUE_REQUIRED, 'Configuration file')
->addOption('source', 's', InputOption::VALUE_REQUIRED, 'Where to take the documentation from') ->addOption('source', 's', InputOption::VALUE_REQUIRED, 'Where to take the documentation from')
->addOption('processor', 'p', InputOption::VALUE_REQUIRED, 'Manipulations on the tree') ->addOption('processor', 'p', InputOption::VALUE_REQUIRED, 'Manipulations on the tree')
@ -44,9 +43,7 @@ class Serve extends DauxCommand
putenv('DAUX_SOURCE=' . $daux->getParams()->getDocumentationDirectory()); putenv('DAUX_SOURCE=' . $daux->getParams()->getDocumentationDirectory());
putenv('DAUX_THEME=' . $daux->getParams()->getThemesPath()); putenv('DAUX_THEME=' . $daux->getParams()->getThemesPath());
putenv('DAUX_CONFIGURATION=' . $daux->getParams()->getConfigurationOverrideFile()); putenv('DAUX_CONFIGURATION=' . $daux->getParams()->getConfigurationOverrideFile());
putenv('DAUX_EXTENSION=' . DAUX_EXTENSION);
//TODO :: support processor
//putenv('DAUX_PROCESSOR=' . $daux->getParams()->getProcessorFile());
$base = ProcessUtils::escapeArgument(__DIR__ . '/../../'); $base = ProcessUtils::escapeArgument(__DIR__ . '/../../');
$binary = ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false)); $binary = ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false));
@ -63,16 +60,4 @@ class Serve extends DauxCommand
passthru("{$binary} -S {$host}:{$port} {$base}/index.php"); passthru("{$binary} -S {$host}:{$port} {$base}/index.php");
} }
} }
protected function prepareProcessor(Daux $daux, InputInterface $input, OutputInterface $output, $width)
{
if ($input->getOption('processor')) {
$daux->getParams()['processor'] = $input->getOption('processor');
}
$class = $daux->getProcessorClass();
if (!empty($class)) {
$daux->setProcessor(new $class($daux, $output, $width));
}
}
} }

View File

@ -1,20 +1,40 @@
<?php <?php
// Loaded as a dependency function loadApp() {
if (file_exists(__DIR__ . '/../../../autoload.php')) { // Loaded as a dependency
return require_once __DIR__ . '/../../../autoload.php'; if (file_exists(__DIR__ . '/../../../autoload.php')) {
return require_once __DIR__ . '/../../../autoload.php';
}
// Loaded in the project itself
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
return require_once __DIR__ . '/../vendor/autoload.php';
}
// Loaded in the project itself, when vendor isn't installed
if (file_exists(__DIR__ . '/../daux.phar')) {
define('PHAR_DIR', __DIR__ . '/..');
return require_once 'phar://' . __DIR__ . '/../daux.phar/vendor/autoload.php';
}
throw new Exception('Impossible to load Daux, missing vendor/ or daux.phar');
} }
// Loaded in the project itself $loader = loadApp();
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
return require_once __DIR__ . '/../vendor/autoload.php'; if ($loader) {
$ext = __DIR__ . '/../daux';
if (is_dir(getcwd() . "/daux")) {
$ext = getcwd() . "/daux";
}
$env = getenv('DAUX_EXTENSION');
if ($env && is_dir($env)) {
$ext = $env;
}
define('DAUX_EXTENSION', $ext);
$loader->setPsr4("Todaymade\\Daux\\Extension\\", $ext);
} }
// Loaded in the project itself, when vendor isn't installed
if (file_exists(__DIR__ . '/../daux.phar')) {
define('PHAR_DIR', __DIR__ . '/..');
return require_once 'phar://' . __DIR__ . '/../daux.phar/vendor/autoload.php';
}
throw new Exception('Impossible to load Daux, missing vendor/ or daux.phar');