forked from idno/known
/
known.php
executable file
·67 lines (55 loc) · 3.29 KB
/
known.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/php -q
<?php
// Load Symfony
require_once((dirname(__FILE__)) . '/external/Symfony/Component/ClassLoader/UniversalClassLoader.php');
$known_loader = new \Symfony\Component\ClassLoader\UniversalClassLoader();
$known_loader->registerNamespace('Symfony\Component', (dirname(__FILE__)) . '/external');
$known_loader->register();
// Register console namespace
use Symfony\Component\Console\Application;
// Create new console application
$console = new Application();
// Load any plugin functions
$directory = dirname(__FILE__) . '/ConsolePlugins/';
if ($scanned_directory = array_diff(scandir($directory), array('..', '.'))) {
foreach($scanned_directory as $file) {
if (is_dir($file)) {
if (file_exists($directory . $file . '/Main.php')) {
@include($directory . $file . '/Main.php');
}
}
}
}
$console
->register('makeconfig')
->setDescription('Attempts to write configuration variables to a Known config.ini file')
->setDefinition([
new \Symfony\Component\Console\Input\InputArgument('dbuser', \Symfony\Component\Console\Input\InputArgument::REQUIRED, 'Database username'),
new \Symfony\Component\Console\Input\InputArgument('dbpass', \Symfony\Component\Console\Input\InputArgument::REQUIRED, 'Database password'),
new \Symfony\Component\Console\Input\InputArgument('dbname', \Symfony\Component\Console\Input\InputArgument::REQUIRED, 'Database name'),
new \Symfony\Component\Console\Input\InputArgument('database', \Symfony\Component\Console\Input\InputArgument::OPTIONAL, 'Database type', 'mysql'),
new \Symfony\Component\Console\Input\InputArgument('dbhost', \Symfony\Component\Console\Input\InputArgument::OPTIONAL, 'Database hostname', 'localhost'),
new \Symfony\Component\Console\Input\InputArgument('filename', \Symfony\Component\Console\Input\InputArgument::OPTIONAL, 'Configuration filename', 'config.ini'),
])
->setCode(function (\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) {
if ($fp = fopen($input->getArgument('filename'),'w')) {
fwrite($fp, "[Database configuration]\n");
fwrite($fp, "database=" . $input->getArgument('database') . "\n");
fwrite($fp, "dbhost=" . $input->getArgument('dbhost') . "\n");
fwrite($fp, "dbname=" . $input->getArgument('dbname') . "\n");
fwrite($fp, "dbuser=" . $input->getArgument('dbuser') . "\n");
fwrite($fp, "dbpass=" . $input->getArgument('dbpass') . "\n");
fclose($fp);
} else {
$output->writeln("Couldn't open " . $input->getArgument('filename'));
}
});
$console
->register('version')
->setDescription('Returns the current Known version as defined in version.known')
->setDefinition([])
->setCode(function (\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) {
$output->writeln(file_get_contents(dirname(__FILE__) . '/version.known'));
});
// Run the application
$console->run();