Virtlab:Řídící server/ParserEquipment.php.inc
Z VirtlabWiki
(Rozdíly mezi verzemi)
												
			
			| Verze z 12:52, 21. 2. 2007 Vav166 (Diskuse | příspěvky) ← Předchozí porovnání | Verze z 21:17, 21. 2. 2007 Vav166 (Diskuse | příspěvky) Následující porovnání → | ||
| Řádka 1: | Řádka 1: | ||
| - | <pre> | + | Tato třída pomáhá vytahovat data o vybavení z XML souboru. Ten je naparsován třídou [[Virtlab:XmlParser.php.inc|virtlabXmlParser]]. | 
| - | 8: public function virtlabParserEquipment($file, $is_file=0, $cache_dev=1) { | + | |
| - | 24: public function getDevices() { | + | == Popis funkcí == | 
| - | 32: public function getDevicesCount() { | + | ; function __construct($file, $is_file=0, $cache_dev=1) : konstruktor třídy v PHP5 | 
| - | 42: public function getDevice($index) { | + | ; public function virtlabParserEquipment($file, $is_file=0, $cache_dev=1) : konstruktor třídy. Jednotlivé parametry mají tento význam: | 
| - | 48: public function getDeviceType($index) { | + | :; $file : obsahuje cestu k XML souboru s [[Virtlab:Equipment.dtd|popisem vybavení]], nebo jsou v této proměnné uložena přímo XML data (o variantě rozhoduje parametr <tt>$is_file</tt>) | 
| - | 54: public function getDeviceName($index) { | + | :; $is_file : udává jestli je atribut <tt>$file</tt> casta k souboru, nebo přímo XML data | 
| - | 60: public function getDeviceSerial($index) { | + | :; $cache_dev : nastavuje, jestli se maji data o vybavení uložit do proměnné, ze které si při potřebě načítají, nebo se vždy čtou z původního výstupu [[Virtlab:XmlParser.php.inc|třídy virtlabXmlParser]] | 
| - | 66: public function getDevicePlatform($index) { | + | ; public function getDevices() : vrátí původní pole s kompletním vybavením | 
| - | 72: public function getDeviceByName($name, &$index) { | + | ; public function getDevicesCount() : vrátí počet zařízení | 
| - | 84: public function getDeviceOS($name, $variant=1) { | + | ; public function getDevice($index) : vrátí určené zařízení (podle parametru <tt>$index</tt>, který odpovídá jejímu indexu v celkovém poli včech zařízení) | 
| - | 103: public function getDeviceInterfaces($name) { | + | ; public function getDeviceType($index) : vrátí typ zadaného zařízení | 
| - | 110: public function getDeviceInterfacesCount($name) { | + | ; public function getDeviceName($index) : vrátí název zadaného zařízení | 
| - | 117: public function getDeviceInterface($name, $index, $variant=1) { | + | ; public function getDeviceSerial($index) : vrátí seriové číslo zařízení | 
| - | 133: public function getDeviceInterfaceTechnology($name, $index) { | + | ; public function getDevicePlatform($index) : vrátí platformu zařízení | 
| - | 139: public function getDeviceInterfaceEthertype($name, $index) { | + | ; public function getDeviceByName($name, &$index) : vrátí požadované zařízení (určené jeho názvem). Do parametru <tt>$index</tt> se uloží jeho index. | 
| - | 146: public function getDeviceInterfaceMaxbps($name, $index) { | + | ; public function getDeviceOS($name, $variant=1) : vrátí veryi OS zařízení. Parametr <tt>$variant</tt> určuje jestli má být výstup upravený nebo v podobě, jako v původním poli. | 
| - | 153: public function getDeviceInterfaceFeatures($name, $index) { | + | ; public function getDeviceInterfaces($name) : vrátí rozhraní zadaného zařízení | 
| - | 167: public function getDeviceFeatures($name) { | + | ; public function getDeviceInterfacesCount($name) : vrátí počet rozhraní zadaného zařízení | 
| - | 183: public function getDevicesFeatures() { | + | ; public function getDeviceInterface($name, $index, $variant=1) : vrátí určené rozhraní (určené parametrem <tt>$index</tt>) určeného zařízení | 
| - | 196: public function getDevicesByType($type) { | + | ; public function getDeviceInterfaceTechnology($name, $index) : vratí technologii rozhraní | 
| - | 209: public function getDevicesTypes() { | + | ; public function getDeviceInterfaceEthertype($name, $index) : vrátí ''verzi'' ethernetu rozhraní. Pokud je technologie <tt>serial</tt> vrací NULL. | 
| - | 221: public function getDeviceInterfacesFeatures($name) { | + | ; public function getDeviceInterfaceMaxbps($name, $index) : vrátí maximální rychlost rozhraní. Pokud je technologie <tt>ethernet</tt> vrací NULL. | 
| - | 232: public function getDevicesInterfacesFeatures() { | + | ; public function getDeviceInterfaceFeatures($name, $index) : vrátí speciální vlastnosti zadaného rozhraní | 
| - | 244: public function getDevicesList() { | + | ; public function getDeviceFeatures($name) : vrátí speciální vlastnosti zařízení | 
| - | 252: public function getDeviceInterfaceName($name, $index) { | + | ; public function getDevicesFeatures() : vrátí všechny speciální vlastnosti všech zařízení | 
| - | </pre> | + | ; public function getDevicesByType($type) : vrátí jména zařízení daného typu | 
| + | ; public function getDevicesTypes() : vrátí typy zařízení, které se ve vybavení vyskytují | ||
| + | ; public function getDeviceInterfacesFeatures($name) : vrátí speciální vlastnosti všech rozhraní daného zařízení | ||
| + | ; public function getDevicesInterfacesFeatures() : vrátí speciální vlastnosti všech rozhraní všech zařízení | ||
| + | ; public function getDevicesList() : vrátí seznam názvů všech zařízení | ||
| + | ; public function getDeviceInterfaceName($name, $index) : vrátí jméno zadaného rozhraní | ||
| + | |||
| + | == Příklady == | ||
| == Zdrojový kód == | == Zdrojový kód == | ||
| Řádka 36: | Řádka 43: | ||
| private $cached_devices = 0; | private $cached_devices = 0; | ||
| - | public function virtlabParserEquipment($file, $is_file=0, $cache_dev=1) { | + | function __construct($file, $is_file=0, $cache_dev=1) { | 
| + | $this->virtlabParserEquipment($file, $is_file, $cache_dev); | ||
| + | }//konstruktor | ||
| + | |||
| + | private function virtlabParserEquipment($file, $is_file=0, $cache_dev=1) { | ||
| $parser = new virtlabXmlParser(1); | $parser = new virtlabXmlParser(1); | ||
Verze z 21:17, 21. 2. 2007
Tato třída pomáhá vytahovat data o vybavení z XML souboru. Ten je naparsován třídou virtlabXmlParser.
Popis funkcí
- function __construct($file, $is_file=0, $cache_dev=1)
- konstruktor třídy v PHP5
- public function virtlabParserEquipment($file, $is_file=0, $cache_dev=1)
-  konstruktor třídy. Jednotlivé parametry mají tento význam:
- $file
- obsahuje cestu k XML souboru s popisem vybavení, nebo jsou v této proměnné uložena přímo XML data (o variantě rozhoduje parametr $is_file)
- $is_file
- udává jestli je atribut $file casta k souboru, nebo přímo XML data
- $cache_dev
- nastavuje, jestli se maji data o vybavení uložit do proměnné, ze které si při potřebě načítají, nebo se vždy čtou z původního výstupu třídy virtlabXmlParser
 
- public function getDevices()
- vrátí původní pole s kompletním vybavením
- public function getDevicesCount()
- vrátí počet zařízení
- public function getDevice($index)
- vrátí určené zařízení (podle parametru $index, který odpovídá jejímu indexu v celkovém poli včech zařízení)
- public function getDeviceType($index)
- vrátí typ zadaného zařízení
- public function getDeviceName($index)
- vrátí název zadaného zařízení
- public function getDeviceSerial($index)
- vrátí seriové číslo zařízení
- public function getDevicePlatform($index)
- vrátí platformu zařízení
- public function getDeviceByName($name, &$index)
- vrátí požadované zařízení (určené jeho názvem). Do parametru $index se uloží jeho index.
- public function getDeviceOS($name, $variant=1)
- vrátí veryi OS zařízení. Parametr $variant určuje jestli má být výstup upravený nebo v podobě, jako v původním poli.
- public function getDeviceInterfaces($name)
- vrátí rozhraní zadaného zařízení
- public function getDeviceInterfacesCount($name)
- vrátí počet rozhraní zadaného zařízení
- public function getDeviceInterface($name, $index, $variant=1)
- vrátí určené rozhraní (určené parametrem $index) určeného zařízení
- public function getDeviceInterfaceTechnology($name, $index)
- vratí technologii rozhraní
- public function getDeviceInterfaceEthertype($name, $index)
- vrátí verzi ethernetu rozhraní. Pokud je technologie serial vrací NULL.
- public function getDeviceInterfaceMaxbps($name, $index)
- vrátí maximální rychlost rozhraní. Pokud je technologie ethernet vrací NULL.
- public function getDeviceInterfaceFeatures($name, $index)
- vrátí speciální vlastnosti zadaného rozhraní
- public function getDeviceFeatures($name)
- vrátí speciální vlastnosti zařízení
- public function getDevicesFeatures()
- vrátí všechny speciální vlastnosti všech zařízení
- public function getDevicesByType($type)
- vrátí jména zařízení daného typu
- public function getDevicesTypes()
- vrátí typy zařízení, které se ve vybavení vyskytují
- public function getDeviceInterfacesFeatures($name)
- vrátí speciální vlastnosti všech rozhraní daného zařízení
- public function getDevicesInterfacesFeatures()
- vrátí speciální vlastnosti všech rozhraní všech zařízení
- public function getDevicesList()
- vrátí seznam názvů všech zařízení
- public function getDeviceInterfaceName($name, $index)
- vrátí jméno zadaného rozhraní
Příklady
Zdrojový kód
<?php
class virtlabParserEquipment {
    private $parsed = array();
    private $devices = array();
    private $cached_devices = 0;
    
    function __construct($file, $is_file=0, $cache_dev=1) {
        $this->virtlabParserEquipment($file, $is_file, $cache_dev);
    }//konstruktor
    
    private function virtlabParserEquipment($file, $is_file=0, $cache_dev=1) {
        $parser = new virtlabXmlParser(1);
        if($is_file) $parser->parse($file);
        else $parser->parse_data($file);
        $this->parsed = $parser->output;
        unset($parser);
        if($cache_dev) {
            $this->devices = $this->getDevices();
            $this->cached_devices = 1;
        }
    }//function
    
    public function getDevices() {
        if(!$this->cached_devices) {
            $temp = $this->parsed[0]["child"];
            return $temp;
        }
        else return $this->devices;
    }//function
    public function getDevicesCount() {
        if(!$this->cached_devices)
        {    
            $temp = $this->getDevices();
            return count($temp);
        }
        else return count($this->devices);
    }//function
    public function getDevice($index) {
        $temp = $this->getDevices();
        return $temp[$index];
    }//function    
    public function getDeviceType($index) {
        $temp = $this->getDevice($index);
        return $temp["attribs"]["TYPE"];
    }//function
    public function getDeviceName($index) {
        $temp = $this->getDevice($index);
        return $temp["attribs"]["NAME"];
    }//function
    public function getDeviceSerial($index) {
        $temp = $this->getDevice($index);
        return $temp["attribs"]["SERIAL_NUMBER"];
    }//function
    public function getDevicePlatform($index) {
        $temp = $this->getDevice($index);
        return $temp["attribs"]["PLATFORM"];
    }//function
    public function getDeviceByName($name, &$index) {
        $result = array();
        for($i = $this->getDevicesCount(); $i>=0; $i--) {
            if($name==$this->getDeviceName($i)) {
                $index = $i;
                return $this->getDevice($i);
            }//if
        }//for
        return NULL;
    }//function
    public function getDeviceOS($name, $variant=1) {
        $temp = $this->getDeviceByName($name,$idx);
        if($temp["child"]) {
            $temp2 = $temp["child"][0];
        if(!isset($temp2)) return NULL;
        if($variant) {
            //$temp3["major"] = $temp2["child"][0]["content"];
            //if($temp2["child"][1]) $temp3["minor"] = $temp2["child"][1]["content"];
            //if($temp2["child"][2]) $temp3["other"] = $temp2["child"][2]["content"];
            //return $temp3;
            return $temp2["content"];
        }
        else return $temp2;
        }//if
        else return NULL;
    }//function
    public function getDeviceInterfaces($name) {
        $temp = $this->getDeviceByName($name,$idx);
        if($temp["child"][1]["name"]!="INTERFACES") return NULL;
        return $temp["child"][1];
    }//function
    
    public function getDeviceInterfacesCount($name) {
        $temp = $this->getDeviceInterfaces($name);
        if(!$temp["child"]) return NULL;
        return count($temp["child"]);
    }//function
    
    public function getDeviceInterface($name, $index, $variant=1) {
        $temp = $this->getDeviceInterfaces($name);
        if(!$temp["child"][$index]) return NULL;
        if($variant) {
            $temp2 = array();
            $temp2["technology"] = $temp["child"][$index]["attribs"]["TECHNOLOGY"];
            $temp2["connect_group"] = $temp["child"][$index]["attribs"]["CONNECT_GROUP"];
            $temp2["name"] = $temp["child"][$index]["attribs"]["NAME"];
            if($temp["child"][$index]["attribs"]["ETHER_TYPE"])
                $temp2["ether_type"] = $temp["child"][$index]["attribs"]["ETHER_TYPE"];
            return $temp2;
        }
        else return $temp["child"][$index];
    }//function
    
    public function getDeviceInterfaceTechnology($name, $index) {
        $temp = $this->getDeviceInterface($name, $index, 1);
        return $temp["technology"];
    }//function
    public function getDeviceInterfaceEthertype($name, $index) {
        $temp = $this->getDeviceInterface($name, $index, 1);
        if($temp["technology"] == "ethernet") return $temp["ether_type"];
        else return NULL;
    }//function
    public function getDeviceInterfaceMaxbps($name, $index) {
        $temp = $this->getDeviceInterface($name, $index, 0);
        if($temp["child"][0]["name"]!="MAX_BPS") return NULL;
        return $temp["child"][0]["content"];
    }//function
    
    public function getDeviceInterfaceFeatures($name, $index) {
        $temp = $this->getDeviceInterface($name, $index, 0);
        $temp2 = array();
        if(is_array($temp) && $temp["child"])
            foreach($temp["child"] as $hodnota) {
                if($hodnota["name"]=="INT_FEATURE") {
                    array_push($temp2, $hodnota["content"]);
                }//if
            }//foreach
        if(!$temp2[0]) return NULL;
        else return $temp2;
    }//function
    public function getDeviceFeatures($name) {
        $temp = $this->getDeviceByName($name,$idx);
        foreach($temp["child"] as $hodnota) {
            if($hodnota["name"]=="SPECIAL") {
                $result = array();
                foreach($hodnota["child"] as $hodnota2) {
                    array_push($result, $hodnota2["content"]);
                }//foreach
                break;
            }//if
        }//foreach
        if(!$result[0]) return NULL;
        else return $result;
    }//function    
    public function getDevicesFeatures() {
        $feat = array();
        for($i = $this->getDevicesCount() - 1; $i >= 0; $i--) {
            $jmeno = $this->getDeviceName($i);
            $temp = $this->getDeviceFeatures($jmeno);
            if(is_array($temp))
                foreach($temp as $value)
                array_push($feat, $value);
        }//for
        return $feat;
    }
    public function getDevicesByType($type) {
        $temp = $this->getDevices();
        $temp2 = array();
        foreach($temp as $hodnota) {
            if($hodnota["attribs"]["TYPE"] == $type)
                array_push($temp2, $hodnota["attribs"]["NAME"]);
        }
        if(!$temp2[0]) return NULL;
        return Unique($temp2);
    }//function
    public function getDevicesTypes() {
        $temp = $this->getDevices();
        $temp2 = array();
        foreach($temp as $hodnota) {
            array_push($temp2, $hodnota["attribs"]["TYPE"]);
        }
        if(!$temp2[0]) return NULL;
        return Unique($temp2);
    }//function
    public function getDeviceInterfacesFeatures($name) {
        $feat = array();
        for($i = $this->getDeviceInterfacesCount($name) - 1; $i >= 0; $i--) {
            $temp = $this->getDeviceInterfaceFeatures($name, $i);
            if(is_array($temp))
                foreach($temp as $hodnota)
                    array_push($feat, $hodnota);
        }//for
        return $feat;
    }//function
    public function getDevicesInterfacesFeatures() {
        $feat = array();
        for($i = $this->getDevicesCount() - 1; $i >= 0; $i--) {
            $jmeno = $this->getDeviceName($i);
            $temp = $this->getDeviceInterfacesFeatures($jmeno);
            if(is_array($temp))
                foreach($temp as $hodnota)
                    array_push($feat, $hodnota);
        }//for
        return $feat;
    }//function
    public function getDevicesList() {
        $temp = array();
        for($i = $this->getDevicesCount() - 1; $i >= 0; $i--) {
            $temp[$i] = $this->getDeviceName($i);
        }//for
        return $temp;
    }//function
    public function getDeviceInterfaceName($name, $index) {
        $temp = $this->getDeviceInterface($name, $index, 1);
        return $temp["name"];
    }//function
}//class
?>
			Kategorie: PHP | Třída | Diplomová práce | Jan Vavříček
