deployer/recipe/deploy/config.php
2016-11-19 15:13:32 +07:00

50 lines
1.4 KiB
PHP

<?php
/* (c) Anton Medvedev <anton@medv.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Deployer;
use Deployer\Task\Context;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Style\SymfonyStyle;
desc('Print server configuration');
task('config:dump', function () {
$server = Context::get()->getServer();
$config = Deployer::get()->config;
$env = Context::get()->getEnvironment();
$dump = [];
foreach ($config as $name => $value) {
try {
$env->get($name);
} catch (\RuntimeException $exception) {
// Ignore fails.
$message = 'Failed to dump';
$env->set($name, output()->isDecorated() ? "\033[1;30m$message\033[0m" : $message);
}
}
foreach ($env->getValues() as $name => $value) {
if (is_array($value)) {
$value = json_encode($value);
} elseif (is_bool($value)) {
$value = $value ? 'Yes' : 'No';
}
$dump[] = [$name, $value];
}
$io = new SymfonyStyle(input(), output());
$io->section("[{$server->getConfiguration()->getName()}] {$server->getConfiguration()->getHost()}");
$table = new Table(output());
$table
->setHeaders(['Parameter', 'Value',])
->setRows($dump);
$table->render();
});