summaryrefslogtreecommitdiff
path: root/routers/router.php
diff options
context:
space:
mode:
authorGuillaume Mazoyer <respawneral@gmail.com>2014-09-24 14:24:43 +0200
committerGuillaume Mazoyer <respawneral@gmail.com>2014-09-24 14:24:43 +0200
commit652b2723b3a2915acb65cd4af9ad775665ad8deb (patch)
tree12c515af99b7ff0113e7603b554aecb4d982f486 /routers/router.php
parentcb1b79ba4f9e764ed3904c10e575a0dcbf35e55b (diff)
Externalize output formatter to a dedicated function.
The dedicated function 'format_output(command, output)' can be redefined by router and can be used to format the output according to what is inside. In this way, the output can be formatted differently according to the router type and the command.
Diffstat (limited to 'routers/router.php')
-rw-r--r--routers/router.php18
1 files changed, 13 insertions, 5 deletions
diff --git a/routers/router.php b/routers/router.php
index b436849..3d6bd07 100644
--- a/routers/router.php
+++ b/routers/router.php
@@ -39,7 +39,7 @@ abstract class Router {
$this->requester = $requester;
}
- private function process_output($output) {
+ private function sanitize_output($output) {
global $config;
// No filters defined
@@ -70,6 +70,13 @@ abstract class Router {
return preg_replace('/(?:\n|\r\n|\r)$/D', '', $filtered);
}
+ protected function format_output($command, $output) {
+ $displayable = '<p><kbd>Command: '.$command.'</kdb></p>';
+ $displayable .= '<pre class="pre-scrollable">'.$output.'</pre>';
+
+ return $displayable;
+ }
+
protected abstract function build_commands($command, $parameters);
public function send_command($command, $parameters) {
@@ -85,10 +92,11 @@ abstract class Router {
$data = '';
foreach ($commands as $selected) {
- $data .= '<p><kbd>Command: '.$selected.'</kdb></p>';
- $data .= '<pre class="pre-scrollable">';
- $data .= $this->process_output($auth->send_command($selected));
- $data .= '</pre>';
+ $output = $auth->send_command($selected);
+ $output = $this->sanitize_output($output);
+
+ $data .= $this->format_output($selected, $output);
+
log_to_file('[client: '.$this->requester.'] '.$this->config['host'].
'> '.$selected);
}