Author: raido
Date: Tue May  4 06:41:22 2010
New Revision: 940745

URL: http://svn.apache.org/viewvc?rev=940745&view=rev
Log:
Update PHP Framework, see WOOKIE-128. Except removed methods for "maximize" 
attribute.

Added:
    incubator/wookie/trunk/connector/php/Logger.php
    incubator/wookie/trunk/connector/php/WookieConnectorServiceInterface.php
Modified:
    incubator/wookie/trunk/connector/php/HTTP_Response.php
    incubator/wookie/trunk/connector/php/TestWookieService.php
    incubator/wookie/trunk/connector/php/User.php
    incubator/wookie/trunk/connector/php/Widget.php
    incubator/wookie/trunk/connector/php/WidgetInstance.php
    incubator/wookie/trunk/connector/php/WidgetInstances.php
    incubator/wookie/trunk/connector/php/WidgetProperties.php
    incubator/wookie/trunk/connector/php/WookieConnectorExceptions.php
    incubator/wookie/trunk/connector/php/WookieConnectorService.php
    incubator/wookie/trunk/connector/php/WookieServerConnection.php

Modified: incubator/wookie/trunk/connector/php/HTTP_Response.php
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/php/HTTP_Response.php?rev=940745&r1=940744&r2=940745&view=diff
==============================================================================
--- incubator/wookie/trunk/connector/php/HTTP_Response.php (original)
+++ incubator/wookie/trunk/connector/php/HTTP_Response.php Tue May  4 06:41:22 
2010
@@ -1,4 +1,5 @@
 <?php
+/** @package org.wookie.php */
 
 /*
  *  Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,33 +15,60 @@
  * limitations under the License.
  */
 
+/** 
+ * HTTP Response class, handles HTTP status codes and response text 
+ * @package org.wookie.php
+ */
+
 class HTTP_Response {
+
        private $statusCode;
        private $responseText;
        private $header;
        
+       /** Create new HTTP response
+        * 
+        * @param String response from server
+        * @param String headers from server
+        */
+       
        function __construct($responseText, $header) {
                 //get http status code
                preg_match('|HTTP/\d\.\d\s+(\d+)\s+.*|',$header[0],$outcome);
                
                //store information
-               $this->statusCode = $outcome[1];
+               $this->statusCode = (int) $outcome[1];
                $this->responseText = $responseText;
                $this->header = $header;
        }
        
+       /** Get response text
+        * @return String response text
+        */
+       
        public function getResponseText() {
                return $this->responseText;
        }
        
+       /** Get HTTP status code
+        * @return Integer status cde
+        */
+       
        public function getStatusCode() {
-               return $this->statusCode;
+               return (int) $this->statusCode;
        }
        
+       /** Get header
+        * @return Array header array
+        */
        public function getHeader() {
                return $this->header;
        }
        
+       /** Get header as string
+        * @return String header as string
+        */
+       
        public function headerToString() {
                return implode("\r\n", $this->getHeader());
        }

Added: incubator/wookie/trunk/connector/php/Logger.php
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/php/Logger.php?rev=940745&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/php/Logger.php (added)
+++ incubator/wookie/trunk/connector/php/Logger.php Tue May  4 06:41:22 2010
@@ -0,0 +1,66 @@
+<?php
+/** @package org.wookie.php */
+
+/*
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/** Simple Logger class
+ * @package org.wookie.php
+ */
+
+class Logger {
+
+       private $path;
+
+       /** Create new logger
+        * @param String path to writeable folder
+        */
+       function __construct($path) {
+               $this->setPath($path);
+       }
+
+       /** Set logger path
+        * 
+        * @param String path to writeable folder
+        */
+       
+       public function setPath($path) {
+               $this->path = $path;
+       }
+
+       /** Get current logger path
+        * @return String current logger path
+        */
+       public function getPath() {
+               return $this->path;
+       }
+
+       /** Write data to log, if logger path is set
+        * 
+        * @param String input string
+        */
+       public function write($str) {
+               $path = $this->getPath();
+               if(!empty($path)) {
+                       $str = "[ ".date("d/m/Y H:i:s")." ] ".$str."\n";
+                       $fileWriter = 
@file_put_contents($path."wookie_php.0.log", $str, FILE_APPEND);
+                       if(!$fileWriter) {
+                               echo "<b>Wookie PHP: Writing to log failed, 
check permissions/path</b>";
+                       }
+               }
+       }
+
+}
+
+?>

Modified: incubator/wookie/trunk/connector/php/TestWookieService.php
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/php/TestWookieService.php?rev=940745&r1=940744&r2=940745&view=diff
==============================================================================
--- incubator/wookie/trunk/connector/php/TestWookieService.php (original)
+++ incubator/wookie/trunk/connector/php/TestWookieService.php Tue May  4 
06:41:22 2010
@@ -1,4 +1,9 @@
 <?php
+/** 
+ * @package org.wookie.php.test 
+ * @filesource 
+ */
+
 /*
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -17,9 +22,12 @@
 ini_set('display_errors', 1);
 error_reporting(E_ALL &~ E_NOTICE);
 
+/** @ignore */
 require_once("WookieConnectorService.php");
 
-$test = new WookieConnectorService("http://localhost:8080/wookie/";, "TEST", 
"localhost_test", 'demo_2');
+$test = new WookieConnectorService("http://dev.ubuntu-box.htk:8081/wookie/";, 
"TEST", "localhost_dev", "demo_1");
+//set logging path, if not set then logger doesnt do nohting
+//$test->setLogPath("/home/raido/dev/www/php_framework/logs/");
 //setup different userName
 $test->getUser()->setLoginName("demo_1");
 //get all available widgets
@@ -27,7 +35,9 @@ $availableWidgets = $test->getAvailableW
 //print_r($availableWidgets);
 
 //check connection
-echo $test->getConnection()->Test().'<br />';
+if(!$test->getConnection()->Test()) {
+echo 'error'.'<br />';
+}
 
 //create select menus
 echo '<pre>';
@@ -69,7 +79,9 @@ if($_GET['widget_id'] != '') {
        //setup different userName for current user
        $test->getUser()->setLoginName("demo_2");
        $widget = $test->getOrCreateInstance($_GET['widget_id']);
+  
        if($widget) {
+         echo $widget->isMaximizable();
                echo '<iframe src="'.$widget->getUrl().'" 
width="'.$widget->getWidth().'" height="'.$widget->getHeight().'"></iframe><br 
/>';
        }
        //add participant
@@ -77,10 +89,9 @@ if($_GET['widget_id'] != '') {
        $test->addParticipant($widget, $testUser);
        print_r($test->getUsers($widget));
        
-       //delete participant DOES NOT WORK
+       //delete participant 
        $testUser = new User('demo_2', 'demo_2');
     $test->deleteParticipant($widget, $testUser);
-       $test->deleteParticipant($widget, $testUser);
        echo 'Users after delete <br />';
        print_r($test->getUsers($widget));
        
@@ -95,7 +106,7 @@ if($_GET['widget_id'] != '') {
        print_r($test->getProperty($widget, $newProperty)); // you can use 
property without value for get -> new Property('proovikas');
        
        //finally delete it from server 
-       $newProperty = new Property('proovikas');
+       $newProperty = new Property('demo_property');
        echo 'Properties after delete<br />';
        print_r($test->deleteProperty($widget, $newProperty)); // you can use 
property without value for get -> new Property('proovikas');
        echo '<br />';
@@ -103,8 +114,10 @@ if($_GET['widget_id'] != '') {
 
 if($_GET['widget_id2'] != '') {
        //setup different userName for current user
-       $test->getUser()->setLoginName("demo_3");
+       $test->getUser()->setLoginName("demo_425");
        $widget2 = $test->getOrCreateInstance($_GET['widget_id2']);
+       $newProperty = new Property("test_id", "kasutaja_2");
+       $result = $test->setProperty($widget2, $newProperty);
        if($widget2) {
                echo '<iframe src="'.$widget2->getUrl().'" 
width="'.$widget2->getWidth().'" 
height="'.$widget2->getHeight().'"></iframe><br />';
        }
@@ -119,4 +132,4 @@ if($_GET['widget_id2'] != '') {
 print_r($test->WidgetInstances->get());
 
 
-?>
\ No newline at end of file
+?>

Modified: incubator/wookie/trunk/connector/php/User.php
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/php/User.php?rev=940745&r1=940744&r2=940745&view=diff
==============================================================================
--- incubator/wookie/trunk/connector/php/User.php (original)
+++ incubator/wookie/trunk/connector/php/User.php Tue May  4 06:41:22 2010
@@ -1,5 +1,7 @@
 <?php
-/**
+/** @package org.wookie.php */
+
+/*
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
  *  You may obtain a copy of the License at
@@ -16,7 +18,9 @@
 /**
  * A user represents a possible user of a widget. This class provides a 
standard way
  * of representing users in plugins for host environments.
+ * @package org.wookie.php
  */ 
+
 class User {
   private $loginName = "UNKNOWN";
   private $screenName = "UNKNOWN";
@@ -25,8 +29,8 @@ class User {
   /**
    * Create a new user.
    * 
-   * @param loginName
-   * @param screenName
+   * @param String user login name
+   * @param String user display name
    */
   function __construct($loginName, $screenName, $thumbnail_url = null) {
     $this->setLoginName($loginName);
@@ -36,6 +40,7 @@ class User {
 
   /**
    * Get the login name for this user.
+   * @return String user login name
    */
   public function getLoginName() {
     return $this->loginName;
@@ -44,6 +49,7 @@ class User {
   /**
    * Get the screen name for this user. This is the name that is intended to 
be displayed on
    * screen. In many cases it will be the same as the login name.
+   * @return String user display name
    */
   public function getScreenName() {
     return $this->screenName;
@@ -53,37 +59,35 @@ class User {
    * Set the login name for this user. This is the value that is used by the 
user to register on the
    * system, it is guaranteed to be unique.
    * 
-   * @param loginName
+   * @param String new login name
    */
   public function setLoginName($loginName) {
-    $this->loginName = $loginName;
+    $this->loginName = (string) trim($loginName);
   }
 
   /**
    * Set the screen name for this user. this is the value that should be 
displayed on screen.
    * In many cases it will be the same as the login name.
    * 
-   * @param screenName
+   * @param String new screen name
    */
   public function setScreenName($screenName) {
-    $this->screenName = $screenName;
+    $this->screenName = (string) trim($screenName);
   }
   
   /**
    * Get the URL for a thumbnail representing this user.
-   * @return
+   * @return String user thumbnail icon url
    */
   public function getThumbnailUrl() {
-    // FIXME: manage user thumbnails
-    return "http://fixme.org/thumbnail";;
+    return $this->thumbnailURL;
   }  
 
   /**
    * Set the URL for a thumbnail representing this user.
-   * @return
+   * @param String new thumbnail url
    */
   public function setThumbnailUrl($thumbnail_url) {
-    // FIXME: manage user thumbnails
     $this->thumbnailURL = $thumbnail_url;
   }    
 }

Modified: incubator/wookie/trunk/connector/php/Widget.php
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/php/Widget.php?rev=940745&r1=940744&r2=940745&view=diff
==============================================================================
--- incubator/wookie/trunk/connector/php/Widget.php (original)
+++ incubator/wookie/trunk/connector/php/Widget.php Tue May  4 06:41:22 2010
@@ -1,4 +1,5 @@
 <?php
+/** @package org.wookie.php */
 
 /*
  *  Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,15 +17,22 @@
  
 /**
  * A client side representation of a widget. 
- * 
- * @refactor this duplicates data stored in the Widget bean on the server side.
+ * @package org.wookie.php
  */
+
 class Widget { 
-  var $identifier;
-  var $title;
-  var $description;
-  var $icon;
+  private $identifier;
+  private $title;
+  private $description;
+  private $icon;
 
+  /** Init new Widget
+   * 
+   * @param String widget identifier/guid
+   * @param String widget title
+   * @param String widget description
+   * @param String widgeticon url
+   */
   function __construct($identifier, $title, $description, $icon) {
     $this->identifier = $identifier;
     $this->title = $title;
@@ -35,7 +43,7 @@ class Widget { 
   /**
    * Get a unique identifier for this widget type.
    * 
-   * @return
+   * @return String widget identifier (guid)
    */
   public function getIdentifier() {
     return $this->identifier;
@@ -43,7 +51,7 @@ class Widget { 
 
   /**
    * Get the human readable title of this widget.
-   * @return
+   * @return String widget title
    */
   public function getTitle() {
     return $this->title;
@@ -51,7 +59,7 @@ class Widget { 
 
   /**
    * Get the location of a logo for this widget.
-   * @return
+   * @return String widget icon url
    */
   public function getIcon() {
     return $this->icon;
@@ -60,7 +68,7 @@ class Widget { 
   /**
    * Get the description of the widget.
    * 
-   * @return
+   * @return String widget description
    */
   public function getDescription() {
     return $this->description;

Modified: incubator/wookie/trunk/connector/php/WidgetInstance.php
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/php/WidgetInstance.php?rev=940745&r1=940744&r2=940745&view=diff
==============================================================================
--- incubator/wookie/trunk/connector/php/WidgetInstance.php (original)
+++ incubator/wookie/trunk/connector/php/WidgetInstance.php Tue May  4 06:41:22 
2010
@@ -1,4 +1,5 @@
 <?php
+/** @package org.wookie.php */
 
 /*
  *  Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,78 +17,116 @@
 
 /**
  * An instance of a widget for use on the client.
- * 
- * @refactor this class duplicates code in the widget bean o nthe server side
- *
+ * @package org.wookie.php
  */
  
 class WidgetInstance {
-  var $url;
-  var $guid;
-  var $title;
-  var $height;
-  var $width;
-  var $maximize;
+  private $url;
+  private $guid;
+  private $title;
+  private $height;
+  private $width;
+  
+  /** Init new WidgetInstance
+   * @param String url of widget
+   * @param String guid of widget
+   * @param String title of widget
+   * @param String height of widget
+   * @param String width of widget
+   * @deprecated Maximize value is deprecated and should not be used. It's 
going to be removed in future.
+   */
 
-  public function WidgetInstance($url, $guid, $title, $height, $width, 
$maximize) {
+  function __construct($url, $guid, $title, $height, $width) {
     $this->setIdentifier($guid);
     $this->setUrl($url);
     $this->setTitle($title);
     $this->setHeight($height);
     $this->setWidth($width);
-    $this->setMaximize($maximize);
   }
   
+  /** Get Widget instance url
+   * @return String widget instance url
+   */
+  
   public function getUrl() {
     return $this->url;
   }
 
-  public function setUrl($url) {
+  /** Set widget instance url
+   * 
+   * @param String new url for instance
+   */
+  
+  private function setUrl($url) {
     $this->url = $url;
   }
 
+  /** Get widget guid value
+   * @return String guid of widget
+   */
+  
   public function getIdentifier() {
     return $this->guid;
   }
 
-  public function setIdentifier($guid) {
+  /** Set widget guid value
+   * 
+   * @param String guid value
+   */
+  
+  private function setIdentifier($guid) {
     $this->guid = $guid;
   }
 
+  /** Get widget title
+   * @return String widget title
+   */
+  
   public function getTitle() {
     return $this->title;
   }
 
+  /** Set widget title
+   * 
+   * @param String new widget title
+   */
+  
   public function setTitle($title) {
     $this->title = $title;
   }
 
+  /** Get widget height
+   * @return Integer widget height
+   */
+  
   public function getHeight() {
-    return $this->height;
+    return (int) $this->height;
   }
 
+  /** Set widget height
+   * @param Integer new widget height
+   */
+  
   public function setHeight($height) {
-    $this->height = $height;
+    $this->height = (int) $height;
   }
+  
+  /** Get wiget width
+   * @return Integer widget width
+   */
 
   public function getWidth() {
-    return $this->width;
+    return (int) $this->width;
   }
+  
+  /** Set widget width
+   * 
+   * @param Integer new widget width
+   */
 
   public function setWidth($width) {
-    $this->width = $width;
-  }
-
-  public function getMaximize() {
-    return $this->maximize;
-  }
-
-  public function setMaximize($maximize) {
-    $this->maximize = $maximize;
-  }
-  public function isMaximizable() {
-    return $this->getMaximize;
+    $this->width = (int) $width;
   }
 }
 
-?>
\ No newline at end of file
+?>

Modified: incubator/wookie/trunk/connector/php/WidgetInstances.php
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/php/WidgetInstances.php?rev=940745&r1=940744&r2=940745&view=diff
==============================================================================
--- incubator/wookie/trunk/connector/php/WidgetInstances.php (original)
+++ incubator/wookie/trunk/connector/php/WidgetInstances.php Tue May  4 
06:41:22 2010
@@ -1,4 +1,5 @@
 <?php
+/** @package org.wookie.php */
 
 /*
  *  Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,21 +17,25 @@
 
 /**
  * A collection of known widget instances available to a host.
+ * @package org.wookie.php
  */
+
 class WidgetInstances {
        private $WidgetInstances = array();
   
   /**
    * Record an instance of the given widget.
    * 
-   * @param xml description of the instance as returned by the widget server 
when the widget was instantiated.
-   * @return the identifier for this instance
+   * @param WidgetInstance instance of widget
    */
+       
  public function put($instance) {
     $this->WidgetInstances[$instance->getIdentifier()] = $instance;
   }
   
-  /* Get all Widget instances */
+  /** Get all Widget instances 
+   * @return array array of widget instances 
+   */
   
   public function get() {
        return $this->WidgetInstances;

Modified: incubator/wookie/trunk/connector/php/WidgetProperties.php
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/php/WidgetProperties.php?rev=940745&r1=940744&r2=940745&view=diff
==============================================================================
--- incubator/wookie/trunk/connector/php/WidgetProperties.php (original)
+++ incubator/wookie/trunk/connector/php/WidgetProperties.php Tue May  4 
06:41:22 2010
@@ -1,4 +1,5 @@
 <?php
+/** @package org.wookie.php */
 
 /*
  *  Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,36 +15,75 @@
  * limitations under the License.
  */
 
+/** Property class 
+ * @package org.wookie.php
+ **/
+
  class Property {
        private $propertyName = '';
        private $propertyValue = '';
        private $isPublic = 'false';
        
+       /** Construct new property
+        * @param String property name
+        * @param String property value
+        * @param String is property public (handled as shareddatakey) or 
private
+        */
+       
        function __construct($propertyName, $propertyValue = null, $isPublic = 
'false') {
                $this->propertyName = (string) $propertyName;
                $this->propertyValue = (string) $propertyValue;
                $this->isPublic = (string) $isPublic;
        }
        
+       /** Get property value
+        * @return String value of property
+        */
+       
        public function getValue() {
                return $this->propertyValue;
        }
        
+       /** Get property name
+        * @return String name of property
+        */
+       
        public function getName() {
                return $this->propertyName;
        }
-       public function isPublic() {
+       
+       /** Get property isPublic flag
+        * @return String isPublic flag of property
+        */
+       
+       public function getIsPublic() {
                return $this->isPublic;
        }
        
+       /** Set property value
+        * 
+        * @param String new value
+        */
+       
        public function setValue($value) {
                $this->propertyValue = (string) $value;
        }
        
+       /** Set property name
+        * 
+        * @param String new name
+        */
+       
        public function setName($propertyName) {
                $this->propertyName = (string) $propertyName;
        }
-       public function set_isPublic($isPublic) {
+       
+       /** Set isPublic flag
+        * 
+        * @param String isPublic flag, "true" or "false"
+        */
+       
+       public function setIsPublic($isPublic) {
                $this->isPublic = (string) $isPublic;
        }
        

Modified: incubator/wookie/trunk/connector/php/WookieConnectorExceptions.php
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/php/WookieConnectorExceptions.php?rev=940745&r1=940744&r2=940745&view=diff
==============================================================================
--- incubator/wookie/trunk/connector/php/WookieConnectorExceptions.php 
(original)
+++ incubator/wookie/trunk/connector/php/WookieConnectorExceptions.php Tue May  
4 06:41:22 2010
@@ -1,4 +1,5 @@
 <?php
+/** @package org.wookie.php */
 
 /*
  *  Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,25 +15,58 @@
  * limitations under the License.
  */
 
-class WookieConnectorException extends Exception {
-
-       public function errorMessage() {
-               //error message
-               $errorMsg = 'Exception thrown on line: '.$this->getLine().' in 
'.$this->getFile()
-               .': <b>'.$this->getMessage().'</b>';
-               return $errorMsg;
+/** Class for handling exception information 
+ * @package org.wookie.php
+ **/
+
+class ExceptionString {
+       private $str;
+       
+       /**
+        * Constructor for exception data handling
+        * @param Exception $ex
+        */
+       function __construct($ex) {
+               $this->str = 
@basename($ex->getFile()).':'.$ex->getLine().'::'.$ex->getMessage().'';
+       }
+       
+       /** Return exception data as string
+        * @return String exception information
+        */
+       public function getString() {
+               return (string) $this->str;
        }
 }
 
-class WookieWidgetInstanceException extends Exception {
+/** WookieConnectorException class 
+ * @package org.wookie.php
+ */
 
-       public function errorMessage() {
-               //error message
-               $errorMsg = 'Exception thrown on line: '.$this->getLine().' in 
'.$this->getFile()
-               .': <b>'.$this->getMessage().'</b>';
-               return $errorMsg;
+class WookieConnectorException extends Exception {
+       
+       /** Convert exception data to String
+        * @return String exception information
+        */
+
+       public function toString() {
+               $exStr = new ExceptionString($this);
+               return $exStr->getString();
        }
 }
 
+/** WookieWidgetInstanceException class 
+ * @package org.wookie.php
+ */
+class WookieWidgetInstanceException extends Exception {
+       
+       /** Convert exception data to String
+        * @return String exception information
+        */
+       
+       public function toString() {
+               $exStr = new ExceptionString($this);
+               return $exStr->getString();
+       }
+}
 
-?>
\ No newline at end of file
+?>

Modified: incubator/wookie/trunk/connector/php/WookieConnectorService.php
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/php/WookieConnectorService.php?rev=940745&r1=940744&r2=940745&view=diff
==============================================================================
--- incubator/wookie/trunk/connector/php/WookieConnectorService.php (original)
+++ incubator/wookie/trunk/connector/php/WookieConnectorService.php Tue May  4 
06:41:22 2010
@@ -1,4 +1,5 @@
 <?php
+/** @package org.wookie.php */
 
 /*
  *  Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,6 +15,7 @@
  * limitations under the License.
  */
 
+/** @ignore */
 require("WookieConnectorExceptions.php");
 require("WookieServerConnection.php");
 require("WidgetInstances.php");
@@ -22,54 +24,116 @@ require("WidgetInstance.php");
 require("WidgetProperties.php");
 require("User.php");
 require("HTTP_Response.php");
+require("Logger.php");
+require("WookieConnectorServiceInterface.php");
 
+/**
+ * Wookie connector service, handles all the data requests and responses 
+ * @package org.wookie.php 
+ */
 
-class WookieConnectorService {
+class WookieConnectorService implements WookieConnectorServiceInterface {
        private $conn;
        public  $WidgetInstances;
        private $user;
        private $httpStreamCtx;
+       private $logger;
+       
+       /** Create new connector
+        * 
+        * @param String url to Wookie host
+        * @param String Wookie API key
+        * @param String shareddatakey to use
+        * @param String user login name
+        * @param String user display name
+        */
 
        function __construct($url, $apiKey, $sharedDataKey, $loginName, 
$screenName = null) {
                $this->setConnection(new WookieServerConnection($url, $apiKey, 
$sharedDataKey));
                $this->setWidgetInstancesHolder();
                $this->setUser($loginName, $screenName);
                $this->setHttpStreamContext(array('http' => array('timeout' => 
15)));
+               $this->logger = new Logger("");
        }
 
-       public function setConnection($newConn) {
+       /** Initiate logger
+        * @param String path to writeable folder 
+        */
+       
+       public function setLogPath($path) {
+       $this->getLogger()->setPath($path);
+       }
+
+       /** Get logger
+        * @return Logger Simple logger for ConnectorService
+        */
+       
+       private function getLogger() {
+       return $this->logger;
+       }
+       
+       /** Set Wookie connection
+        * 
+        * @param WookieServerConnection new WookieServerConnection instance
+        */
+       private function setConnection($newConn) {
                $this->conn = $newConn;
        }
+       
+       /** Get current Wookie connection
+        * @return WookieServerConnection current Wookie server connection
+        */
 
        public function getConnection() {
                return $this->conn;
        }
-
-       public function setWidgetInstancesHolder() {
+       
+       /** Set WidgetInstances holder */
+       private function setWidgetInstancesHolder() {
                $this->WidgetInstances = new WidgetInstances();
        }
 
+       /** Set user for connection
+        * 
+        * @param String username
+        * @param String optional display name
+        */
        public function setUser($loginName, $screenName = null) {
                if($screenName == null) {
                        $screenName = $loginName;
                }
                $this->user = new User($loginName, $screenName);
        }
-
+       
+       /** Get current user
+        * @return User current connection user
+        */
        public function getUser() {
                return $this->user;
        }
        
-       private function setHttpStreamContext($params = null) {
+       /** Set HttpStreamContext parameters
+        * 
+        * @param Array array of context parameters
+        */
+       private function setHttpStreamContext($params) {
                $this->httpStreamCtx = @stream_context_create($params);
        }
        
+       /** Get HttpStreamContext
+        * @return StreamContextResource HttpStreamContext resource
+        */
+       
        private function getHttpStreamContext() {
                return $this->httpStreamCtx;
        }
 
-       /* Do HTTP request
-        /* @return new HTTP_Response instance */
+       /** Do HTTP request
+        * @param String url to request
+        * @param String data to send
+        * @param String method to use
+        * @return HTTP_Response new HTTP_Response instance 
+        */
 
        private function do_request($url, $data, $method = 'POST')
        {
@@ -100,15 +164,14 @@ class WookieConnectorService {
        /**
         * Get or create an instance of a widget.
         *
-        * @param widget
-        * @return the ID of the widget instance
-        * @throws IOException
-        * @throws SimalRepositoryException
+        * @param Widget|String instance of widget or guid
+        * @return WidgetInstance WidgetInstance if successful, otherwise false
+        * @throws WookieConnectorException
         */
 
-       public function getOrCreateInstance($Widget_or_GUID = null) {
+       public function getOrCreateInstance($Widget_or_GUID) {
                try {
-                       if(is_object($Widget_or_GUID)) {
+                       if($Widget_or_GUID instanceof Widget) {
                                $guid = $Widget_or_GUID->getIdentifier();
                        } else {
                                $guid = $Widget_or_GUID;
@@ -118,7 +181,6 @@ class WookieConnectorService {
                        }
                        $requestUrl = 
$this->getConnection()->getURL().'widgetinstances';
                        $request.= 
'&api_key='.$this->getConnection()->getApiKey();
-                       $request.= '&servicetype=';
                        $request.= '&userid='.$this->getUser()->getLoginName();
                        $request.= 
'&shareddatakey='.$this->getConnection()->getSharedDataKey();
                        $request.= '&widgetid='.$guid;
@@ -135,10 +197,15 @@ class WookieConnectorService {
                        if($response->getStatusCode() == 401) { throw new 
WookieConnectorException("Invalid API key"); }
 
                        $instance = $this->parseInstance($guid, 
$response->getResponseText());
-                       $this->WidgetInstances->put($instance);
+                       if($instance) {
+                         $this->WidgetInstances->put($instance);
+                       
+                         //add current user as participant
+                         $this->addParticipant($instance, $this->getUser());
+                       }
                        return $instance;
                } catch (WookieConnectorException $e) {
-                       echo $e->errorMessage();
+                       $this->getLogger()->write($e->toString());
                }
                return false;
        }
@@ -147,19 +214,18 @@ class WookieConnectorService {
        /**
         * Record an instance of the given widget.
         *
-        * @param xml description of the instance as returned by the widget 
server when the widget was instantiated.
-        * @return new Widget instance
+        * @param String widget guid
+        * @param String xml description of the instance as returned by the 
widget server when the widget was instantiated.
+        * @return new Widget instance or false
         */
        private function parseInstance($widgetGuid, $xml) {
                $xmlWidgetData = @simplexml_load_string($xml);
-               if(is_object($xmlWidgetData)) {
-                       //print_r($xmlWidgetData);
+               if($xmlWidgetData instanceof SimpleXMLElement) {
                        $url = (string) $xmlWidgetData->url;
                        $title = (string) $xmlWidgetData->title;
                        $height = (string) $xmlWidgetData->height;
                        $width = (string) $xmlWidgetData->width;
-                       $maximize = (string) $xmlWidgetData->maximize;
-                       $instance = new WidgetInstance($url, $widgetGuid, 
$title, $height, $width, $maximize);
+                       $instance = new WidgetInstance($url, $widgetGuid, 
$title, $height, $width);
                        return $instance;
                }
                return false;
@@ -168,8 +234,8 @@ class WookieConnectorService {
        /**
         * Check if URL is parsable.
         *
-        * @param url
-        * @return boolean
+        * @param String url to parse
+        * @return boolean true if parseable, otherwise false
         */
 
        private function checkURL($url) {
@@ -181,18 +247,20 @@ class WookieConnectorService {
        }
 
        /**
-        * @refactor At time of writing the REST API for adding a participant 
is broken so we are
-        * using the non-REST approach. The code for REST API is commented out 
and should be used
-        * in the future.
+        * Add new participant
+        * @param WidgetInstance instance of WidgetInstance
+        * @param User instance of User
         * @return boolean true - if added/exists - false if some error
+        * @throws WookieConnectorException
+        * @throws WookieWidgetInstanceException
         */
 
        public function addParticipant($widgetInstance, $User)  {
                $Url = $this->getConnection()->getURL().'participants';
 
                try {
-                       if(!is_object($widgetInstance)) throw new 
WookieWidgetInstanceException('No Widget instance');
-                       if(!is_object($User)) throw new 
WookieConnectorException('No User object');
+                       if(!$widgetInstance instanceof WidgetInstance) throw 
new WookieWidgetInstanceException('No Widget instance');
+                       if(!$User instanceof User) throw new 
WookieConnectorException('No User object');
 
                        $data = array(
                                'api_key' => 
$this->getConnection()->getApiKey(),
@@ -224,32 +292,34 @@ class WookieConnectorService {
                        }
 
                } catch (WookieConnectorException $e) {
-                       echo $e->errorMessage();
+                       $this->getLogger()->write($e->toString());
                } catch (WookieWidgetInstanceException $e) {
-                       echo '<b>function.addParticipant:</b> 
'.$e->getMessage().'<br />';
+                       $this->getLogger()->write($e->toString());
                }
        return false;
        }
 
        /**
-        * @refactor Delete participant
-        * @param WidgetInstance $widgetInstance
-        * @param UserInstance $User
+        * Delete participant
+        * @param WidgetInstance  instance of WidgetInstance
+        * @param User instance of User
         * @return boolean true - if deleted, false - if not found
+        * @throws WookieConnectorException
+        * @throws WookieWidgetInstanceException
         */
 
        public function deleteParticipant($widgetInstance, $User)  {
                $Url = $this->getConnection()->getURL().'participants';
 
                try {
-                       if(!is_object($widgetInstance)) throw new 
WookieWidgetInstanceException('No Widget instance');
-                       if(!is_object($User)) throw new 
WookieConnectorException('No User object');
+                       if(!$widgetInstance instanceof WidgetInstance) throw 
new WookieWidgetInstanceException('No Widget instance');
+                       if(!$User instanceof User) throw new 
WookieConnectorException('No User object');
 
                        $request = 
'?api_key='.$this->getConnection()->getApiKey();
                        $request .= 
'&shareddatakey='.$this->getConnection()->getSharedDataKey();
                        $request .= '&userid='.$this->getUser()->getLoginName();
                        $request .= 
'&widgetid='.$widgetInstance->getIdentifier();
-                       $request .= 
'&participant_id='.$this->getUser()->getLoginName();
+                       $request .= '&participant_id='.$User->getLoginName();
 
 
                        if(!$this->checkURL($Url)) {
@@ -272,24 +342,25 @@ class WookieConnectorService {
                }
 
                } catch (WookieConnectorException $e) {
-                       echo $e->errorMessage();
+                       $this->getLogger()->write($e->toString());
                } catch (WookieWidgetInstanceException $e) {
-                       echo '<b>function.deleteParticipant:</b> 
'.$e->getMessage().'<br />';
+                       $this->getLogger()->write($e->toString());
                }
                return false;
        }
 
        /**
         * Get the array of users for a widget instance
-        * @param instance
-        * @return an array of users
+        * @param WidgetInstance instance of WidgetInstance
+        * @return Array an array of users
         * @throws WookieConnectorException
+        * @throws WookieWidgetInstanceException
         */
        public function getUsers($widgetInstance) {
                $Url = $this->getConnection()->getURL().'participants';
                $Users = array();
                try {
-                       if(!is_object($widgetInstance)) throw new 
WookieWidgetInstanceException('No Widget instance');
+                       if(!$widgetInstance instanceof WidgetInstance) throw 
new WookieWidgetInstanceException('No Widget instance');
                        $request = 
'?api_key='.$this->getConnection()->getApiKey();
                        $request .= 
'&shareddatakey='.$this->getConnection()->getSharedDataKey();
                        $request .= '&userid='.$this->getUser()->getLoginName();
@@ -304,7 +375,7 @@ class WookieConnectorService {
 
                        $xmlObj = 
@simplexml_load_string($response->getResponseText());
 
-                       if(is_object($xmlObj)) {
+                       if($xmlObj instanceof SimpleXMLElement) {
                                foreach($xmlObj->children() as $participant) {
                                        $participantAttr = 
$participant->attributes();
 
@@ -320,9 +391,9 @@ class WookieConnectorService {
                        }
 
                } catch (WookieWidgetInstanceException $e) {
-                       echo '<b>function.getUsers:</b> '.$e->getMessage().'<br 
/>';
+                       $this->getLogger()->write($e->toString());
                } catch (WookieConnectorException $e) {
-                       echo $e->errorMessage();
+                       $this->getLogger()->write($e->toString());
                }
                return $Users;
        }
@@ -335,7 +406,7 @@ class WookieConnectorService {
         * far in order to allow the application to proceed. The application 
should
         * display an appropriate message in this case.
         *
-        * @return array of available widgets
+        * @return array array of available widgets
         * @throws WookieConnectorException
         */
 
@@ -343,7 +414,6 @@ class WookieConnectorService {
                $widgets = array();
                try {
                        $request = 
$this->getConnection()->getURL().'widgets?all=true';
-
                        if(!$this->checkURL($request)) {
                                throw new WookieConnectorException("URL for 
Wookie is malformed");
                        }
@@ -351,7 +421,7 @@ class WookieConnectorService {
                        $response = new 
HTTP_Response(@file_get_contents($request, false, 
$this->getHttpStreamContext()), $http_response_header);
                        $xmlObj = 
@simplexml_load_string($response->getResponseText());
 
-                       if(is_object($xmlObj)) {
+                       if($xmlObj instanceof SimpleXMLElement) {
                                foreach($xmlObj->children() as $widget) {
                                 $id = (string) 
$widget->attributes()->identifier;
                                 $title = (string) $widget->title;
@@ -368,24 +438,25 @@ class WookieConnectorService {
                        }
 
         } catch(WookieConnectorException $e) {
-                       echo $e->errorMessage();
+                       $this->getLogger()->write($e->toString());
                }
                return $widgets;
        }
 
        /**
         * Set property for Widget instance
-        *
-        * @return new Property instance
+        * @param WidgetInstance instance of WidgetInstance
+        * @param Propety instance of Property
+        * @return Property new Property instance
         * @throws WookieConnectorException, WookieWidgetInstanceException
         */
 
-       public function setProperty($widgetInstance = null, $propertyInstance = 
null) {
+       public function setProperty($widgetInstance, $propertyInstance) {
                $Url = $this->getConnection()->getURL().'properties';
 
                try {
-                       if(!is_object($widgetInstance)) throw new 
WookieWidgetInstanceException('No Widget instance');
-                       if(!is_object($propertyInstance)) throw new 
WookieConnectorException('No properties instance');
+                       if(!$widgetInstance instanceof WidgetInstance) throw 
new WookieWidgetInstanceException('No Widget instance');
+                       if(!$propertyInstance instanceof Property) throw new 
WookieConnectorException('No properties instance');
 
                        $data = array(
                                'api_key' => 
$this->getConnection()->getApiKey(),
@@ -394,11 +465,11 @@ class WookieConnectorService {
                                'widgetid' => $widgetInstance->getIdentifier(),
                                'propertyname' => $propertyInstance->getName(),
                                'propertyvalue' => 
$propertyInstance->getValue(),
-                               'is_public' => $propertyInstance->isPublic(),
+                               'is_public' => $propertyInstance->getIsPublic(),
                        );
 
                        if(!$this->checkURL($Url)) {
-                               throw new WookieConnectorException("Properties 
rest URL is incorrect: ".$Url);
+                               throw new WookieConnectorException("Properties 
rest URL is incorrect: ".$Url); 
                        }
 
                        $response = $this->do_request($Url, $data);
@@ -414,26 +485,27 @@ class WookieConnectorService {
                        }
 
                } catch (WookieConnectorException $e) {
-                       echo $e->errorMessage();
+                       $this->getLogger()->write($e->toString());
                } catch (WookieWidgetInstanceException $e) {
-                       echo '<b>function.setProperty:</b> 
'.$e->getMessage().'<br />';
+                       $this->getLogger()->write($e->toString());
                }
                return false;
        }
 
        /**
         * Get property for Widget instance
-        *
-        * @return new Property(), if request fails, return false;
+        * @param WidgetInstance instance of WidgetInstance
+        * @param Propety instance of Property
+        * @return Property if request fails, return false;
         * @throws WookieConnectorException, WookieWidgetInstanceException
         */
 
-       public function getProperty($widgetInstance = null, $propertyInstance = 
null) {
+       public function getProperty($widgetInstance, $propertyInstance) {
                $Url = $this->getConnection()->getURL().'properties';
 
                try {
-                       if(!is_object($widgetInstance)) throw new 
WookieWidgetInstanceException('No Widget instance');
-                       if(!is_object($propertyInstance)) throw new 
WookieConnectorException('No properties instance');
+                       if(!$widgetInstance instanceof WidgetInstance) throw 
new WookieWidgetInstanceException('No Widget instance');
+                       if(!$propertyInstance instanceof Property) throw new 
WookieConnectorException('No properties instance');
 
                        $data = array(
                                'api_key' => 
$this->getConnection()->getApiKey(),
@@ -456,27 +528,27 @@ class WookieConnectorService {
                        return new Property($propertyInstance->getName(), 
$response->getResponseText());
 
                } catch (WookieConnectorException $e) {
-                       echo $e->errorMessage();
+                       $this->getLogger()->write($e->toString());
                } catch (WookieWidgetInstanceException $e) {
-                       echo '<b>function.getProperty:</b> 
'.$e->getMessage().'<br />';
+                       $this->getLogger()->write($e->toString());
                }
                return false;
        }
 
        /**
         * Delete property for Widget instance
-        *
-        * @access Public
+        * @param WidgetInstance instance of WidgetInstance
+        * @param Propety instance of Property
         * @return boolean true/false -- true if deleted, false if doesnt exist
         * @throws WookieConnectorException, WookieWidgetInstanceException
         */
 
-       public function deleteProperty($widgetInstance = null, 
$propertyInstance = null) {
+       public function deleteProperty($widgetInstance, $propertyInstance) {
                $Url = $this->getConnection()->getURL().'properties';
 
                try {
-                       if(!is_object($widgetInstance)) throw new 
WookieWidgetInstanceException('No Widget instance');
-                       if(!is_object($propertyInstance)) throw new 
WookieConnectorException('No properties instance');
+                       if(!$widgetInstance instanceof WidgetInstance) throw 
new WookieWidgetInstanceException('No Widget instance');
+                       if(!$propertyInstance instanceof Property) throw new 
WookieConnectorException('No properties instance');
 
                        $request = 
'?api_key='.$this->getConnection()->getApiKey();
                        $request .= 
'&shareddatakey='.$this->getConnection()->getSharedDataKey();
@@ -500,12 +572,12 @@ class WookieConnectorService {
                        return true;
 
                } catch (WookieConnectorException $e) {
-                       echo $e->errorMessage();
+                       $this->getLogger()->write($e->toString());
                } catch (WookieWidgetInstanceException $e) {
-                       echo '<b>function.getProperty:</b> 
'.$e->getMessage().'<br />';
+                       $this->getLogger()->write($e->toString());
                }
                return false;
        }
 
 }
-?>
\ No newline at end of file
+?>

Added: incubator/wookie/trunk/connector/php/WookieConnectorServiceInterface.php
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/php/WookieConnectorServiceInterface.php?rev=940745&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/php/WookieConnectorServiceInterface.php 
(added)
+++ incubator/wookie/trunk/connector/php/WookieConnectorServiceInterface.php 
Tue May  4 06:41:22 2010
@@ -0,0 +1,110 @@
+<?php
+/** @package org.wookie.php */
+
+/*
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/** Description: Interface for WookieConnectorService 
+ * @package org.wookie.php
+ */
+
+interface WookieConnectorServiceInterface {
+       
+       /** Get all available widgets 
+        * @return array[Widget]|false array of widgets, otherwise false
+        */
+       
+       public function getAvailableWidgets();
+       
+       /** Set Logger path
+        * @param String path for writeable folder, example: 
/var/log/myWriteableFolder/
+        */
+       
+       public function setLogPath($path);
+       
+       /** Get current connection 
+        * @return WookieServerConnection instance of WookieServerConnection
+        */
+       
+       public function getConnection();
+
+       /** Set new user
+        * @param String username for Wookie connection
+        * @param String screenName for Wookie connection
+        */
+       
+       public function setUser($loginName, $screenName = null);
+       
+       /** Get current user
+        * @return User instance of User
+        */
+       
+       public function getUser();
+       
+       /** Get or create new widget instance
+        * @param Widget|String new Widget or String guid of widget
+        * @return WidgetInstance|false WidgetInstace if successuful, otherwise 
false
+        */
+       
+       public function getOrCreateInstance($Widget_or_GUID);
+       
+       /** Add new participant
+        * @param WidgetInstance instance of WidgetInstance
+        * @param User instance of User
+        * @return boolean true if successful, otherwise false
+        */
+       
+       public function addParticipant($widgetInstance, $User);
+       
+       /** Delete participant
+        * @param WidgetInstance instance of WidgetInstance
+        * @param User instance of User
+        * @return boolean true if successful, otherwise false
+        */
+       
+       public function deleteParticipant($widgetInstance, $User);
+       
+       /** Get all participants of current widget
+        *  @param WidgetInstance instance of WidgetInstance
+        *  @return array[User] array of User instances
+        */
+       
+       public function getUsers($widgetInstance);
+       
+       /** Set new property 
+        * @param WidgetInstance instance of WidgetInstance
+        * @param Property instance of Property
+        * @return Property|false Property if successful, otherwise false
+        */
+       
+       public function setProperty($widgetInstance, $propertyInstance);
+       
+       /** Get property
+        * @param WidgetInstance instance of WidgetInstance
+        * @param Property instance of Property
+        * @return Property|false Property if successful, otherwise false
+        */
+       
+       public function getProperty($widgetInstance, $propertyInstance);
+       
+       /** Delete property
+        * @param WidgetInstance instance of WidgetInstance
+        * @param Property instance of Property
+        * @return boolean true if successful, otherwise false
+        */
+       
+       public function deleteProperty($widgetInstance, $propertyInstance );
+       
+}
+?>
\ No newline at end of file

Modified: incubator/wookie/trunk/connector/php/WookieServerConnection.php
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/php/WookieServerConnection.php?rev=940745&r1=940744&r2=940745&view=diff
==============================================================================
--- incubator/wookie/trunk/connector/php/WookieServerConnection.php (original)
+++ incubator/wookie/trunk/connector/php/WookieServerConnection.php Tue May  4 
06:41:22 2010
@@ -1,4 +1,5 @@
 <?php
+/** @package org.wookie.php */
 
 /*
  *  Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,7 +19,7 @@
  * A connection to a Wookie server. This maintains the necessary data for
  * connecting to the server and provides utility methods for making common 
calls
  * via the Wookie REST API.
- *
+ * @package org.wookie.php
  */
 
 
@@ -29,11 +30,9 @@ class WookieServerConnection {
 
        /**
         * Create a connection to a Wookie server at a given URL.
-        * @param url the URL of the wookie server
-        * @param apiKey the API key for the server
-        * @param sharedDataKey the sharedDataKey for the server connection
-        *
-        * @throws WookieConnectorException if there is a problem setting up 
this connection.
+        * @param String the URL of the wookie server
+        * @param String the API key for the server
+        * @param String the sharedDataKey for the server connection
         */
        function __construct($url, $apiKey, $sharedDataKey) {
                $this->setURL($url);
@@ -44,8 +43,7 @@ class WookieServerConnection {
        /**
         * Get the URL of the wookie server.
         *
-        * @return
-        * @throws WookieConnectionException
+        * @return String current Wookie connection URL
         */
        public function getURL() {
                return $this->url;
@@ -54,8 +52,9 @@ class WookieServerConnection {
        /**
         * Set the URL of the wookie server.
         *
-        * @throws WookieConnectionException
+        * @param String new Wookie server URL
         */
+       
        public function setURL($newUrl) {
                //parse url, if host == localhost, replace it with 127.0.0.1
                // Bug causes Apache crash, while using file_get_contents 
function
@@ -70,16 +69,23 @@ class WookieServerConnection {
        /**
         * Get the API key for this server.
         *
-        * @return
+        * @return String current Wookie connection API key
+        * @throws WookieConnectorException
         */
+       
        public function getApiKey() {
+               if(empty($this->apiKey)) {
+                       throw new WookieConnectorException("API key not set");
+               }
                return $this->apiKey;
        }
 
        /**
         * Set the API key for this server.
-        *
+        * 
+        *...@param String new API key for connection
         */
+       
        public function setApiKey($newApiKey) {
                $this->apiKey = (string) $newApiKey;
        }
@@ -87,19 +93,28 @@ class WookieServerConnection {
        /**
         * Get the shared data key for this server.
         *
-        * @return
+        * @return String current Wookie connection shareddatakey
+        * @throws WookieConnectorException
         */
+       
        public function getSharedDataKey() {
+               if(empty($this->sharedDataKey)) {
+                       throw new WookieConnectorException("No shareddatakey 
set");
+               }
                return $this->sharedDataKey;
        }
 
        /**
         * Set the shared data key for this server.
-        *
+        * @param String new shareddatakey for connection
         */
        public function setSharedDataKey($newKey) {
                $this->sharedDataKey = $newKey;
        }
+       
+       /** Output connection information as string
+        * @return String current connection information (url, apikey, 
shareddatakey)
+        */
 
        public function toString() {
                $str = "Wookie Server Connection - ";
@@ -109,22 +124,25 @@ class WookieServerConnection {
                return $str;
        }
 
-       /* Test Wookie server connection
-        *  @return boolean - true if success, otherwise false
+       /** Test Wookie server connection
+        *  @return boolean true if success, otherwise false
         */
 
        public function Test() {
                $ctx = @stream_context_create(array('http' => array('timeout' 
=> 15)));
-               $response = new 
HTTP_Response(@file_get_contents($this->getURL().'advertise?all=true', false, 
$ctx), $http_response_header);
-               if($response->getStatusCode() == 200) {
-                       $xmlDoc = 
@simplexml_load_string($response->getResponseText());
-                       if(is_object($xmlDoc) && $xmlDoc->getName() == 
'widgets') {
-                               return true;
-                       }
+               $url = $this->getURL();
+               if(!empty($url)) {
+                 $response = new 
HTTP_Response(@file_get_contents($url.'advertise?all=true', false, $ctx), 
$http_response_header);
+                 if($response->getStatusCode() == 200) {
+                         $xmlDoc = 
@simplexml_load_string($response->getResponseText());
+                         if(is_object($xmlDoc) && $xmlDoc->getName() == 
'widgets') {
+                                 return true;
+                         }
+                 }
                }
                return false;
        }
 }
 
 
-?>
\ No newline at end of file
+?>


Reply via email to