Source for file VMPSRequest.php

Documentation is available at VMPSRequest.php

  1. <?php
  2. /**
  3.  * VMPSRequest.php
  4.  *
  5.  * PHP version 5
  6.  *
  7.  * LICENSE: This program is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU General Public License as published
  9.  * by the Free Software Foundation.
  10.  *
  11.  * @package                     FreeNAC
  12.  * @author                      Hector Ortiz (FreeNAC Core Team)
  13.  * @copyright                   2007 FreeNAC
  14.  * @license                     http://www.gnu.org/copyleft/gpl.html   GNU Public License Version 2
  15.  * @version                     SVN: $Id$
  16. */
  17.  
  18.  
  19. /**
  20.  * Class that contains information related to a VMPS request
  21.  * This class extends the {@link Request} class
  22.  */
  23. final class VMPSRequest    extends Request        # Disallow inheriting from this class
  24. {
  25.    private $props=array();            # Here we hold our internal properties
  26.    private static $instance=NULL;            # Our instance of this class
  27.    public $switch_port=NULL;
  28.    public $host=NULL;
  29.  
  30.    public function __construct($tmac$tswitch,$tport,$tvtp,$tlastvlan)
  31.    {    
  32.       parent::__construct();
  33.       #Sanity checks
  34.       if (is_string($tmac&& is_string($tswitch&& is_string($tport&& is_string($tvtp&& is_string($tlastvlan&&
  35.          (strlen($tmac)>0&& (strlen($tswitch)>0&& (strlen($tport)>0&& (strlen($tvtp)>0&& (strlen($tlastvlan)>0))
  36.       {
  37.          #Copy what we've received to our internal array
  38.          $this->props['mac']=$tmac;
  39.          $this->props['switch']=$tswitch;
  40.          $this->props['port']=$tport;
  41.          $this->props['vtp']=$tvtp;
  42.          $this->props['lastvlan']=$tlastvlan;
  43.          
  44.          #Initialize a port and a system objects
  45.          $this->props['created']=true;
  46.          $this->switch_port=new CallWrapper(new Port($this));
  47.          $this->host=new CallWrapper(new EndDevice($this));
  48.       }
  49.       else
  50.       {
  51.          $this->logger->logit("A VMPSRequest object wasn't initialized. Only non empty strings are allowed to be passed to its constructor");
  52.          $this->props['created']=false;
  53.       }
  54.    }
  55.  
  56.    /**
  57.    * Get the value of one property if it exists
  58.    * @param mixed $key          Property to lookup
  59.    * @return mixed              The value of the wanted property, or false if such a property doesn't exist
  60.    */
  61.    public function __get($key)        
  62.    {
  63.       if ($this->props['created'])
  64.       {
  65.          if (array_key_exists($key,$this->props))    #First look if it exists in our internal array
  66.             return $this->props[$key];        #If so, return it
  67.          else
  68.             return false;                #Nothing found, return false
  69.       }
  70.       else
  71.       {
  72.          $this->logger->logit("VMPSRequest object contains no properties because it hasn't been properly initialized")
  73.       }
  74.    }
  75.  
  76.    /**
  77.    * Disallow overriding this method. This prevents our internal
  78.    * array from being modified by other classes.
  79.    */
  80.    final public function __set($key,$value{}
  81.  
  82.    /**
  83.    * Prevent clonning the instance
  84.    * @throws     Exception indicating that a clone operation cannot be performed
  85.    */
  86.    final public function __clone()        
  87.    {
  88.       if ($this->created)
  89.       {
  90.          throw new Exception("Cannot clone the VMPSRequest object");
  91.       }
  92.       else
  93.       {
  94.          $this->logger->logit("A VMPSRequest object wasn't initialized");
  95.       }
  96.    }
  97.  
  98.    /**
  99.    * Get a copy of our EndDevice object
  100.    * @return object    EndDevice 
  101.    */
  102.    public function getEndDevice()
  103.    {
  104.       if ($this->created)
  105.       {
  106.          return $this->system;
  107.       }
  108.       else
  109.       {
  110.          $this->logger->logit("EndDevice object hasn't been created");
  111.       }
  112.    }
  113.  
  114.    /**
  115.    * Get a copy of our Port object
  116.    * @return object    Port 
  117.    */
  118.    public function getPort()
  119.    {
  120.       if ($this->created)
  121.       {
  122.          return $this->port;
  123.       }
  124.       else
  125.       {
  126.          $this->logger->logit("Port object hasn't been created");
  127.       }
  128.    }
  129. }

Documentation generated on Mon, 17 Nov 2008 01:10:54 +0100 by phpDocumentor 1.4.0