-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathknown.php
More file actions
executable file
·138 lines (114 loc) · 5.92 KB
/
known.php
File metadata and controls
executable file
·138 lines (114 loc) · 5.92 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/php -q
<?php
define('KNOWN_CONSOLE', 'true');
// Load Symfony
require_once((dirname(__FILE__)) . '/external/Symfony/Component/ClassLoader/UniversalClassLoader.php');
global $known_loader;
$known_loader = new \Symfony\Component\ClassLoader\UniversalClassLoader();
$known_loader->registerNamespace('Symfony\Component', (dirname(__FILE__)) . '/external');
$known_loader->register();
/**
* Retrieve the loader
* @return \Symfony\Component\ClassLoader\UniversalClassLoader
*/
function &loader()
{
global $known_loader;
return $known_loader;
}
// Register console namespace
use Symfony\Component\Console\Application;
// Create new console application
global $console;
$console = new Application();
function &application() {
global $console;
return $console;
}
// Known core namespaces
$known_loader->registerNamespace('Idno', dirname(__FILE__) );
$known_loader->registerNamespace('ConsolePlugins', dirname(__FILE__) );
// Implement the PSR-3 logging interface
$known_loader->registerNamespace('Psr\Log', dirname(__FILE__) . '/external/log');
// Symfony is used for routing, observer design pattern support, and a bunch of other fun stuff
$known_loader->registerNamespace('Symfony\Component', dirname(__FILE__) . '/external');
// TODO: FIND A WAY TO NOT LOAD THESE FOR CONSOLE
// Bonita is being used for templating (although console plugins shouldn't really need this)
$known_loader->registerNamespace('Bonita', dirname(__FILE__) . '/external/bonita/includes');
// Using HTMLPurifier for HTML sanitization
include dirname(__FILE__) . '/external/htmlpurifier-lite/library/HTMLPurifier.auto.php';
///////////////////
// Load any plugin functions
$directory = dirname(__FILE__) . '/ConsolePlugins/';
if ($scanned_directory = array_diff(scandir($directory), array('..', '.'))) {
foreach ($scanned_directory as $file) {
if (is_dir($directory . $file)) {
$class = "ConsolePlugins\\$file\\Main";
if (class_exists($class)) {
$c = new $class();
if ($c instanceof \Idno\Common\ConsolePlugin) {
$console->register($c->getCommand())
->setDescription($c->getDescription())
->setDefinition($c->getParameters())
->setCode([$c, 'execute']);
}
}
}
}
}
// Allow regular plugins to contain a ConsoleMain.php
$directory = dirname(__FILE__) . '/IdnoPlugins/';
if ($scanned_directory = array_diff(scandir($directory), array('..', '.'))) {
foreach ($scanned_directory as $file) {
if (is_dir($directory . $file)) {
$class = "IdnoPlugins\\$file\\ConsoleMain";
if (class_exists($class)) {
$c = new $class();
if ($c instanceof \Idno\Common\ConsolePlugin) {
$console->register($c->getCommand())
->setDescription($c->getDescription())
->setDefinition($c->getParameters())
->setCode([$c, 'execute']);
}
}
}
}
}
$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'));
});
// Boot known
try {
$idno = new Idno\Core\Idno();
} catch (\Exception $e) {
}
// Run the application
$console->run();