DDMS
[ class tree: DDMS ] [ index: DDMS ] [ all elements ]

Source for file PhpUrlConnection.php

Documentation is available at PhpUrlConnection.php

  1. <?php
  2. /**
  3.  * <b>Class Description</b>: Class representing a URL connection for posting and getting data to and from the DDMS server URL.
  4.  * (see {@link package.php} for documentation
  5.  * of the DDMS package.).
  6.  *@see package.php
  7.  * @since : 29/04/2009
  8.  * @author Jan van der Breggen
  9.  * @package DDMS
  10.  * @subpackage DDMSClient
  11.  ***/
  12.  
  13. {
  14.  
  15.     protected $urlString;
  16.     protected $scheme;
  17.     protected $host;
  18.     protected $port;
  19.     protected $user;
  20.     protected $pass;
  21.     protected $path;
  22.     protected $query;
  23.     protected $fragment;
  24.     protected $timeoutValue = 60;
  25.  
  26.     function __construct($urlString)
  27.     {
  28.         $this->urlString = $urlString;
  29.         foreach (parse_url($urlStringas $key => $value)
  30.         {
  31.             $this->$key $value;
  32.         }
  33.  
  34.     }
  35.  
  36.     public function connected()
  37.     {
  38.         $old_error_handler set_error_handler(array($this'urlErrorHandler'));
  39.         $connected true;
  40.         if (!fopen($this->urlString"r"))
  41.         {
  42.             $connected false;
  43.         }
  44.         set_error_handler($old_error_handler);
  45.         return $connected;
  46.     }
  47.  
  48.     function setConnectionEnvironment($timeOutValue)
  49.     {
  50.         $this->timeoutValue = $timeOutValue;
  51.     }
  52.  
  53.     public function getData($controllerString)
  54.     {
  55.         $options array('http' => array('timeout' => $this->timeoutValue));
  56.         $context stream_context_create($options);
  57.  
  58.         return file_get_contents($this->urlString . "/" $controllerStringfalse$context);
  59.     }
  60.  
  61.  
  62.     public function postData($controllerString$data)
  63.     {
  64.  
  65.  
  66.         $postdata $this->makeQueryString($data);
  67.  
  68.  
  69.         $opts array('http' => array('method' => 'POST''header' =>
  70.             'Content-type: application/x-www-form-urlencoded''content' => $postdata,
  71.             'timeout' => $this->timeoutValue));
  72.  
  73.         $context stream_context_create($opts);
  74.  
  75.         return file_get_contents($this->urlString . "/" $controllerStringfalse$context);
  76.  
  77.     }
  78.  
  79.     function urlErrorHandler($errno$errstr$errfile$errline)
  80.     {
  81.         echo "to handle these kind of errors, probably with a user notification, and what else?";
  82.     }
  83.  
  84.     private function makeQueryString($data)
  85.     {
  86.  
  87.         $contentsArray array();
  88.         $variableNumber 1;
  89.         foreach ($data as $value)
  90.         {
  91.             $contentsArray["var$variableNumber"$value;
  92.             $variableNumber++;
  93.         }
  94.         return http_build_query($contentsArray);
  95.     }
  96.  
  97.  
  98. }
  99.  
  100. ?>

Documentation generated on Mon, 18 May 2009 11:22:13 +0200 by phpDocumentor 1.4.1