From f3edeb601556e7741804b0c0bec2711996774bfe Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Tue, 13 Sep 2016 17:03:48 +0200 Subject: [PATCH] replace echo with Log:: calls --- src/shpub/Cli.php | 2 +- src/shpub/Command/Connect.php | 7 ++++--- src/shpub/Command/Like.php | 4 ++-- src/shpub/Command/Note.php | 4 ++-- src/shpub/Command/Reply.php | 4 ++-- src/shpub/Command/Server.php | 6 +++--- src/shpub/Log.php | 10 ++++++++++ src/shpub/Request.php | 2 +- 8 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/shpub/Cli.php b/src/shpub/Cli.php index 12eeaed..30c2d1f 100644 --- a/src/shpub/Cli.php +++ b/src/shpub/Cli.php @@ -41,7 +41,7 @@ class Cli break; } } catch (\Exception $e) { - echo 'Error: ' . $e->getMessage() . "\n"; + Log::err('Error: ' . $e->getMessage()); exit(1); } } diff --git a/src/shpub/Command/Connect.php b/src/shpub/Command/Connect.php index 668d7e9..2fd6d38 100644 --- a/src/shpub/Command/Connect.php +++ b/src/shpub/Command/Connect.php @@ -36,9 +36,10 @@ class Command_Connect list($redirect_uri, $socketStr) = $this->getHttpServerData(); $state = time(); - echo "To authenticate, open the following URL:\n" + Log::msg( + "To authenticate, open the following URL:\n" . $this->getBrowserAuthUrl($host, $user, $redirect_uri, $state) - . "\n"; + ); $authParams = $this->startHttpServer($socketStr); if ($authParams['state'] != $state) { @@ -72,7 +73,7 @@ class Command_Connect } $this->cfg->hosts[$hostKey] = $host; $this->cfg->save(); - echo "Server configuration $hostKey saved successfully.\n"; + Log::info("Server configuration $hostKey saved successfully."); } protected function fetchAccessToken( diff --git a/src/shpub/Command/Like.php b/src/shpub/Command/Like.php index fb396be..5b456f9 100644 --- a/src/shpub/Command/Like.php +++ b/src/shpub/Command/Like.php @@ -46,8 +46,8 @@ class Command_Like extends Command_AbstractProps Log::err($res->getBody()); exit(20); } else { - echo "Like created at server\n"; - echo $postUrl . "\n"; + Log::info('Like created at server'); + Log::msg($postUrl); } } } diff --git a/src/shpub/Command/Note.php b/src/shpub/Command/Note.php index de67948..1ea599b 100644 --- a/src/shpub/Command/Note.php +++ b/src/shpub/Command/Note.php @@ -36,8 +36,8 @@ class Command_Note extends Command_AbstractProps $res = $req->send(); $postUrl = $res->getHeader('Location'); - echo "Post created at server\n"; - echo $postUrl . "\n"; + Log::info('Post created at server'); + Log::msg($postUrl); } } ?> diff --git a/src/shpub/Command/Reply.php b/src/shpub/Command/Reply.php index e84a055..b67d46b 100644 --- a/src/shpub/Command/Reply.php +++ b/src/shpub/Command/Reply.php @@ -50,8 +50,8 @@ class Command_Reply extends Command_AbstractProps $res = $req->send(); $postUrl = $res->getHeader('Location'); - echo "Reply created at server\n"; - echo $postUrl . "\n"; + Log::info('Reply created at server'); + Log::msg($postUrl); } } ?> diff --git a/src/shpub/Command/Server.php b/src/shpub/Command/Server.php index 59843d4..8553414 100644 --- a/src/shpub/Command/Server.php +++ b/src/shpub/Command/Server.php @@ -11,10 +11,10 @@ class Command_Server public function run($verbose) { foreach ($this->cfg->hosts as $key => $host) { - echo $key . "\n"; + Log::msg($key); if ($verbose) { - echo ' URL: ' . $host->server . "\n"; - echo ' User: ' . $host->user . "\n"; + Log::msg(' URL: ' . $host->server); + Log::msg(' User: ' . $host->user); } } } diff --git a/src/shpub/Log.php b/src/shpub/Log.php index 99d9694..7b9dc71 100644 --- a/src/shpub/Log.php +++ b/src/shpub/Log.php @@ -3,6 +3,16 @@ namespace shpub; class Log { + public static function info($msg) + { + echo $msg . "\n"; + } + + public static function msg($msg) + { + echo $msg . "\n"; + } + public static function err($msg) { file_put_contents('php://stderr', $msg . "\n", FILE_APPEND); diff --git a/src/shpub/Request.php b/src/shpub/Request.php index 0924dda..8ee7c5a 100644 --- a/src/shpub/Request.php +++ b/src/shpub/Request.php @@ -114,6 +114,6 @@ class Request $command .= ' ' . escapeshellarg((string) $this->req->getUrl()); - echo $command . "\n"; + Log::msg($command); } } \ No newline at end of file -- 2.30.2