gnope php gtk gui gnope.org  

GtkSoapClient

 
Post new topic   Reply to topic    gnope.org Forum Index -> Announcements
View previous topic :: View next topic  
Author Message
leon_pegg



Joined: 12 Jun 2006
Posts: 113
Location: hemel / UK

PostPosted: Thu Aug 10, 2006 2:18 am    Post subject: GtkSoapClient Reply with quote

this is a php-gtk wrapper around the NuSoap library. it takes care of the connection error handeling. and makes making calls to a soap server much simpler.
hope you enjoy.
Code:

class GtkSoapClient extends GtkObject {

   private $client = null;
   private $proxyhost = null;
   private $proxyport = null;
   private $proxyusername = null;
   private $proxypassword = null;

   public function __construct($server = null,$wsdl = false){
      if ($server !== null) {
         $this->client = new soapclient($server, $wsdl,
         $this->proxyhost, $this->proxyport, $this->proxyusername, $this->proxypassword);
         $err = $this->client->getError();
         if ($err) {
            trigger_error('Constructor error' . $err, E_USER_WARNING);
         }
      }
   }

   public function set_server($server){
      $this->client = new soapclient($server, true,
      $proxyhost, $proxyport, $proxyusername, $proxypassword);
      $err = $this->client->getError();
      if ($err) {
         trigger_error('Constructor error' . $err, E_USER_ERROR);
      }
   }

   public function set_proxy($proxyhost = null, $proxyport = null, $proxyusername = null, $proxypassword = null){
      $this->proxyhost = $proxyhost;
      $this->proxyport = $proxyport;
      $this->proxyusername = $proxyusername;
      $this->proxypassword = $proxypassword;
   }
   
   public function get_proxy(){
      return array('host' => $this->proxyhost,
               'port' => $this->proxyport,
               'username' => $this->proxyusername,
               'password' => $this->proxypassword);
   }

   public function set_persistent(){
      $this->client->useHTTPPersistentConnection();
   }

   public function __call($method,$arg){
      $result = $this->client->call($method, $arg[0]);
      if ($this->client->fault) {
         return $result;
      } else {
         $err = $this->client->getError();
         if ($err) {
            trigger_error('Error ' . $err,E_USER_WARNING);
         } else {
            return $result;
         }
      }
   }

   public function call($method,$param){
      $result = $this->client->call($method, $param);
      if ($this->client->fault) {
         return $result;
      } else {
         $err = $this->client->getError();
         if ($err) {
            trigger_error('Error ' . $err,E_USER_WARNING);
         } else {
            return $result;
         }
      }
   }

   public function __get($variable){
      switch (strtolower($variable)){
         case 'request' : return $this->client->request; break;
         case 'response' : return $this->client->response; break;
         case 'debug' : return $this->client->getDebug(); break;
      }
   }

   public function clear_debug(){
      $this->client->clearDebug();
   }
}


remember this call requires the Nusoap class from http://dietrich.ganx4.com/nusoap/.

Any feedback welcome and segestions on improvements wanted.


Last edited by leon_pegg on Thu Aug 10, 2006 2:38 am; edited 1 time in total
Back to top
leon_pegg



Joined: 12 Jun 2006
Posts: 113
Location: hemel / UK

PostPosted: Thu Aug 10, 2006 2:34 am    Post subject: Reply with quote

here is an example of using the GtkSoapClient. it is a modifyed version of the notepad tut.
Code:

<?php

require_once('gtksoapclient.php');

class Notepad extends GtkWindow
{
    protected $currentFile;
    protected $buffer;
    protected $status;
    protected $context;
    protected $lastid;
 
    function __construct($fileName = null)
    {
        parent::__construct();
               
        $mainBox  = new GtkVBox();
        $textBuff = new GtkTextBuffer();
        $textView = new GtkTextView($textBuff);
        $statusBar= new GtkStatusBar();
 
        $mainBox->pack_start($this->buildMenu(), false, false);
        $mainBox->pack_start($textView, true, true);
        $mainBox->pack_start($statusBar, false, false);
 
        $this->currentFile = $fileName;
        $this->buffer = $textBuff;
        $this->status = $statusBar;
 
        $this->connect_simple('destroy', array($this, 'quit'));
        $this->set_title('Simple Notepad');
        $this->maximize();
        $this->add($mainBox);
        $this->show_all();
 
        $this->loadFile();
    }
 
    function buildMenu()
    {
        $menuBar  = new GtkMenuBar();
        $fileMenu = new GtkMenu();
        $menuName = new GtkMenuItem('_File');
       
        $quit = new GtkImageMenuItem('gtk-quit');
        $quit->connect_simple('activate', array($this, 'quit'));
        $quit->connect_simple('enter_notify_event',
                                array($this, 'updateStatus'), 1);
        $quit->connect_simple('leave_notify_event',
                                array($this, 'updateStatus'), 0);
       
        $fileMenu->append($quit);
        $menuName->set_submenu($fileMenu);
        $menuBar->add($menuName);
 
        return $menuBar;
    }
   
    function loadFile()
    {
        if($this->currentFile != null) {
            $contents = file_get_contents($this->currentFile);
            $this->buffer->set_text($contents);
        }
    }
   
    function fillbuffer($text){
       $this->buffer->set_text($text);
    }
 
    function updateStatus($enter)
    {
        if($enter) {
            $id = $this->status->get_context_id("Message");
            $lastMsg = $this->status->push($id, "Quits the Application");
            $this->context = $id;
            $this->lastid = $lastMsg;
        } else {
            $this->status->remove($this->context, $this->lastid);
        }
    }
   
    function quit()
    {
        Gtk::main_quit();
    }
 
}
 
$notpad = new Notepad();
$soap = new GtkSoapClient('http://www.scottnichol.com/samples/getfile1.php?wsdl',true);
$notpad->fillbuffer($soap->getFile(array('filename' => 'getfile1.php')));
Gtk::main();
 
?>
Back to top
Osiris



Joined: 17 Dec 2005
Posts: 65

PostPosted: Thu Aug 10, 2006 7:20 am    Post subject: Reply with quote

bad idea to use nuSOAP in PHP-GTK2, which made SOAP easy to use under php4.

There are two main reason, why not to use nuSOAP under PHP-GTK2:
a) PHP5 has it's own SOAP-extension, and due it's direct integration into PHP it may be faster than nuSOAP or Pear_SOAP
b) nuSOAP was build for PHP4, so there may be problems using it, with full error_reporting (E_STRICT or so). And the overhead of nusoap may be much bigger.

Regards

Christian
Back to top
leon_pegg



Joined: 12 Jun 2006
Posts: 113
Location: hemel / UK

PostPosted: Thu Aug 10, 2006 10:38 am    Post subject: Reply with quote

Well it would not take much work to convert this class to use the native php soap extention so i may do that.
i used NuSoap becuase i had it at hand and my copy of php did not have the native soap extention installed.

Thank you for the comments. thay will be taken on board when i write the next update.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    gnope.org Forum Index -> Announcements All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Templates enhanced by DigiWiki. Hosting by Tradebit.