make the request observer work correctly, remove response logging in main class
authorChristian Weiske <cweiske@cweiske.de>
Fri, 17 Dec 2010 23:20:16 +0000 (00:20 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 17 Dec 2010 23:20:16 +0000 (00:20 +0100)
Wrt3g.php
Wrt3g/HtmlParser.php
Wrt3g/RequestObserver.php

index d3b948807e2361bcbb78b1c99f7dfa2794d45d9c..ee48eca8437c4db7c73773ca767b6c3896eff902 100644 (file)
--- a/Wrt3g.php
+++ b/Wrt3g.php
@@ -223,8 +223,6 @@ class Wrt3g
      */
     protected function checkResponseStatus(HTTP_Request2_Response $resp)
     {
      */
     protected function checkResponseStatus(HTTP_Request2_Response $resp)
     {
-        $this->log($resp, 3);
-
         $nStatus = $resp->getStatus();
         $this->log($nStatus . ' ' . $resp->getReasonPhrase(), 1);
         if (intval($nStatus / 100) == 2) {
         $nStatus = $resp->getStatus();
         $this->log($nStatus . ' ' . $resp->getReasonPhrase(), 1);
         if (intval($nStatus / 100) == 2) {
@@ -291,14 +289,6 @@ class Wrt3g
     public function log($msg, $level = 1)
     {
         if ($this->verbosity >= $level) {
     public function log($msg, $level = 1)
     {
         if ($this->verbosity >= $level) {
-            if ($msg instanceof HTTP_Request2_Response) {
-                echo "HTTP Response:\n";
-                echo $msg->getStatus() . ' ' . $msg->getReasonPhrase() . "\n";
-                echo 'Header: ';
-                var_export($msg->getHeader());
-                echo $msg->getBody() . "\n----\n";
-                return;
-            }
             echo $msg . "\n";
         }
     }
             echo $msg . "\n";
         }
     }
index 9574cd032ac6c2bd14448d199f626614ac4caabb..bd613acbcc7f6b467631a8647a9e479f1924f425 100644 (file)
@@ -20,8 +20,10 @@ class Wrt3g_HtmlParser
         'GPRS_MSG.WWBEAR_GPRS' => 'GPRS',
         'GPRS_MSG.WWBEAR_UMTS' => 'UMTS',
         'GPRS_MSG.None'        => null,
         'GPRS_MSG.WWBEAR_GPRS' => 'GPRS',
         'GPRS_MSG.WWBEAR_UMTS' => 'UMTS',
         'GPRS_MSG.None'        => null,
+        'GPRS_MSG.FAIR'        => 'fair',
         'GPRS_MSG.GOOD'        => 'good',
         'GPRS_MSG.EXCELLENT'   => 'excellent',
         'GPRS_MSG.GOOD'        => 'good',
         'GPRS_MSG.EXCELLENT'   => 'excellent',
+        'GPRS_MSG.NOSIGNAL'    => 'no signal',
         'GPRS_MSG.CTIME'       => 'connection time',
         'GPRS_MSG.CFW'         => 'card firmware',
         'GPRS_MSG.CMOD'        => 'card model',
         'GPRS_MSG.CTIME'       => 'connection time',
         'GPRS_MSG.CFW'         => 'card firmware',
         'GPRS_MSG.CMOD'        => 'card model',
index 1e5224f4107cc9f782be29f493a6d5b6886e8170..f9886385e94afd8210bfc9109a4b8427c42ec4e5 100644 (file)
@@ -23,6 +23,9 @@
 class Wrt3g_RequestObserver implements SplObserver
 {
     protected $wrt3g;
 class Wrt3g_RequestObserver implements SplObserver
 {
     protected $wrt3g;
+    protected static $supportedEvents = array(
+        'connect', 'sentHeaders', 'receivedBody', 'disconnect'
+    );
 
     /**
      * Create new instance
 
     /**
      * Create new instance
@@ -46,8 +49,20 @@ class Wrt3g_RequestObserver implements SplObserver
     public function update(SplSubject $subject)
     {
         $event = $subject->getLastEvent();
     public function update(SplSubject $subject)
     {
         $event = $subject->getLastEvent();
+        if (!in_array($event['name'], self::$supportedEvents)) {
+            return;
+        }
+
+        if ($event['name'] == 'receivedBody') {
+            $resp = $event['data'];
+            $event['data']
+                = $resp->getStatus() . ' ' . $resp->getReasonPhrase() . "\n"
+                . 'Header: ' . var_export($resp->getHeader(), true)
+                . $resp->getBody() . "\n----\n";
+        }
+
         $this->wrt3g->log(
         $this->wrt3g->log(
-            'event: ' . $event['name'] . "\n"
+            'event: ' . $event['name'] . ', '
             . 'data: ' . $event['data'],
             3
         );
             . 'data: ' . $event['data'],
             3
         );