From 652b2723b3a2915acb65cd4af9ad775665ad8deb Mon Sep 17 00:00:00 2001 From: Guillaume Mazoyer Date: Wed, 24 Sep 2014 14:24:43 +0200 Subject: 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. --- routers/router.php | 18 +++++++++++++----- 1 file 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 = '

Command: '.$command.'

'; + $displayable .= '
'.$output.'
'; + + 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 .= '

Command: '.$selected.'

'; - $data .= '
';
-        $data .= $this->process_output($auth->send_command($selected));
-        $data .= '
'; + $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); } -- cgit v1.2.3