PHP Classes

File: IPDetails.tst.php

Recommend this page to a friend!
  Classes of Gilbert BENABOU   ABG_IPDetails   IPDetails.tst.php   Download  
File: IPDetails.tst.php
Role: Example script
Content type: text/plain
Description: Test application
Class: ABG_IPDetails
Get information about IP address from IPInfoDB.com
Author: By
Last change:
Date: 14 years ago
Size: 5,749 bytes
 

Contents

Class file image Download
<?php
################################################################################
# Project : ABG_IPDetails #
# File : IPDetails.tst.php #
# V1.1.0 02/12/2009 : Initial #
# (cy) G. BENABOU / ABG Soft PARIS FRANCE #
# #
# An application to get details about an IP V4 address #
# #
#=== IMPORTS ==================================================================#
# ABG_IPDetail class in ABG_IPDetails.cls.php file #
# ABG_Except class in ABG_IPDetails.cls.php file #
# #
################################################################################

  ### A P P L I C A T I O N ###################################################
 
include_once('ABG_IPDetails.cls.php');
 
$oTester = new ABG_TestIPInfo();
  try{
   
$oTester->PrintData();
  } catch(
ABG_Except $Exc_){
    print(
$Exc_->ErrMsg);
  }

################################################################################
# Class ABG_TestIPInfo #
#=== PURPOSE ==================================================================#
# Provide a test bed and a demo application for class ABG_IPDetails #
#=== PROPERTIES ===============================================================#
# Computed read #
# - str Entry : URL / IP under scrutinity #
# - array SiteInfo : Detailed results of query #
#=== METHODS ==================================================================#
# object function __construct(str Entry) #
# - Create ABG_TestIPInfo object #
# - Create oIPInfo = ABG_IPDetail object #
# - Retrieve details info by invoking oIPInfo::GetIPInfo() method #
#..............................................................................#
# void function PrintData() #
# - Construct an HTML string with details content #
# - Output it #
# #
################################################################################
Class ABG_TestIPInfo{
 
/*** Private Properties *****************************************************/
 
private $oIPInfo = null;
  private
$DivStyle = 'color: navy; font: 12px sans-serif;';
  private
$TblStyle = 'background: #FFFFCC; border: 2px solid Navy;';

 
### C O N S T R U C T O R ###################################################
  /*** object function __construct(str XML) ***********************************
    - Create the ABG_TestIPInfo object instance
  *****************************************************************************/
 
public function __construct($_Entry=null){
    try{
     
$this->oIPInfo = new ABG_IPDetails($_Entry);
     
$this->oIPInfo->GetIPInfo();
    }
    catch(
ABG_Except $Exc_){
      print(
$Exc_->ErrMsg);
    }
    catch(
Exception $Exc_){
      print(
"*** Error : ".$Exc_->GetMessage());
    }
  }
// __construct

  /*** mixed function __Get(str Ppty) *****************************************
    Returns properties values
    - Ppty : property name
  *****************************************************************************/
 
private function __Get($_Ppty){
    switch(
$_Ppty){
      case
'CurEntry' : //flow
     
case 'SiteInfo' : if(isset($this->oIPInfo))
                           return
$this->oIPInfo->$_Ppty;
                         else
                           throw new
ABG_Except('IPInfo', K_RGFatal + 0xF3);
      default : throw new
ABG_Except($_Ppty, K_RGFatal + 0xF0);
    }
  }
// __Get

  /*** str function PrintData() ***********************************************
    Build a HTML fragment table dispaying collected information
  *****************************************************************************/
 
public function PrintData(){
   
$SiteInfo_ = $this->SiteInfo;
   
$CurEntry_ = $this->CurEntry;
   
$HTML_ = <<< ABGHereDoc
<html>
  <body>
    <div style="
$this->DivStyle">
      <form name="frmQuery" action="" method="get">
        <table border="1" cellpadding="3" cellspacing="0" style="
$this->TblStyle">
          <tr>
            <td ><input type="text" name="txtEntry" value="
$CurEntry_" size="40" /></td>
            <td ><input type="submit" name="btnGo" value="Query" /></td>
          </tr>
        </table>
      </form>
    </div>
    <div style="
$this->DivStyle">
      <table border="1" cellpadding="3" cellspacing="0" style="
$this->TblStyle">
ABGHereDoc;
    foreach(
$SiteInfo_ as $Key_=>$Val_){
     
$HTML_.= "<tr>\n";
     
$HTML_.= "<td >$Key_</td>\n";
     
$HTML_.= "<td >$Val_&nbsp;</td>\n";
     
$HTML_.= "</tr>\n";
    }
   
$HTML_ .= <<< ABGHereDoc
</table>
    </div>
  </body>
</html>
ABGHereDoc;
    print(
$HTML_);
    return(
$HTML_);
  }
// PrintData

} #===== End class ABG_TestIPInfo ==========================================
?>