Source for file SyslogRequest.php

Documentation is available at SyslogRequest.php

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

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