Changeset 7631 for trunk/src/inc


Ignore:
Timestamp:
Mar 30, 2010, 8:51:44 PM (15 years ago)
Author:
Pieter Naber
Message:

Fixed a lot of bugs, introduced KMLFile::parseFile for parsing the node status file

Location:
trunk/src/inc
Files:
1 deleted
4 edited
1 copied
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/inc/ErrorHandler.php

    r7628 r7631  
    2626 */
    2727
    28 class ErrorHandler {
    29         /*
    30          * Function: ErrorHandler
    31          * Parameters: int $errno, string $errstr, string $errfile, int $errline, array $errcontext
    32          * Function: Handling with errors, decides what to do with it
    33          */
    34         public function ErrorHandler(int $errno, string $errstr, string $errfile, int $errline, array $errcontext) {
    35                 switch ($errno) {
    36                         case E_ERROR:
    37                                 echo 'E_ERROR: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
    38                                 // TODO
    39                                 break;   
    40                         case E_WARNING: 
    41                                 echo 'E_WARNING: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
    42                                 // TODO
    43                                 break;   
    44                         case E_PARSE:   
    45                                 echo 'E_PARSE: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
    46                                 // TODO
    47                                 break;   
    48                         case E_NOTICE:   
    49                                 echo 'E_NOTICE: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
    50                                 // TODO
    51                                 break;   
    52                         case E_CORE_ERROR:
    53                                 echo 'E_CORE_ERROR: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
    54                                 // TODO
    55                                 break;   
    56                         case E_CORE_WARNING:
    57                                 echo 'E_CORE_WARNING: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
    58                                 // TODO
    59                                 break;   
    60                         case E_COMPILE_ERROR:
    61                                 echo 'E_COMPILE_ERROR: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
    62                                 // TODO
    63                                 break;   
    64                         case E_COMPILE_WARNING:
    65                                 echo 'E_COMPILE_WARNING: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
    66                                 // TODO
    67                                 break;   
    68                         case E_USER_ERROR:
    69                                 echo 'E_USER_ERROR: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
    70                                 // TODO
    71                                 break;   
    72                         case E_USER_WARNING:
    73                                 echo 'E_USER_WARNING: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
    74                                 // TODO
    75                                 break;   
    76                         case E_USER_NOTICE:
    77                                 echo 'E_USER_NOTICE: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
    78                                 // TODO
    79                                 break;   
    80                         case E_STRICT:
    81                                 echo 'E_STRICT: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
    82                                 // TODO
    83                                 break;   
    84                         case E_RECOVERABLE_ERROR:
    85                                 echo 'E_RECOVERABLE_ERROR: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
    86                                 // TODO
    87                                 break;   
    88                         case E_DEPRECATED:
    89                                 echo 'E_DEPRECATED: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
    90                                 // TODO
    91                                 break;   
    92                         case E_USER_DEPRECATED:
    93                                 echo 'E_USER_DEPRECATED: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
    94                                 // TODO
    95                                 break;   
    96                         default:
    97                                 echo 'E_DEFAULT: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
    98                                 // TODO
    99                                 break;   
    100                 }
     28/*
     29 * Function: ErrorHandler
     30 * Parameters: int $errno, string $errstr, string $errfile, int $errline, array $errcontext
     31 * Function: Handling with errors, decides what to do with it
     32 */
     33function ErrorHandler(int $errno, string $errstr, string $errfile, int $errline, array $errcontext) {
     34        switch ($errno) {
     35                case E_ERROR:
     36                        echo 'E_ERROR: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
     37                        // TODO
     38                        break;   
     39                case E_WARNING: 
     40                        echo 'E_WARNING: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
     41                        // TODO
     42                        break;   
     43                case E_PARSE:   
     44                        echo 'E_PARSE: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
     45                        // TODO
     46                        break;   
     47                case E_NOTICE:   
     48                        echo 'E_NOTICE: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
     49                        // TODO
     50                        break;   
     51                case E_CORE_ERROR:
     52                        echo 'E_CORE_ERROR: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
     53                        // TODO
     54                        break;   
     55                case E_CORE_WARNING:
     56                        echo 'E_CORE_WARNING: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
     57                        // TODO
     58                        break;   
     59                case E_COMPILE_ERROR:
     60                        echo 'E_COMPILE_ERROR: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
     61                        // TODO
     62                        break;   
     63                case E_COMPILE_WARNING:
     64                        echo 'E_COMPILE_WARNING: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
     65                        // TODO
     66                        break;   
     67                case E_USER_ERROR:
     68                        echo 'E_USER_ERROR: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
     69                        // TODO
     70                        break;   
     71                case E_USER_WARNING:
     72                        echo 'E_USER_WARNING: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
     73                        // TODO
     74                        break;   
     75                case E_USER_NOTICE:
     76                        echo 'E_USER_NOTICE: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
     77                        // TODO
     78                        break;   
     79                case E_STRICT:
     80                        echo 'E_STRICT: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
     81                        // TODO
     82                        break;   
     83                case E_RECOVERABLE_ERROR:
     84                        echo 'E_RECOVERABLE_ERROR: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
     85                        // TODO
     86                        break;   
     87                case E_DEPRECATED:
     88                        echo 'E_DEPRECATED: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
     89                        // TODO
     90                        break;   
     91                case E_USER_DEPRECATED:
     92                        echo 'E_USER_DEPRECATED: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
     93                        // TODO
     94                        break;   
     95                default:
     96                        echo 'E_DEFAULT: ' , $errno , ': ' , $errstr , '<br/>Bestand: ' , $errfile , '<br/>Regel: ' , $errline , '<br/>';
     97                        // TODO
     98                        break;   
     99        }
    101100
    102                 /* Don't execute PHP internal error handler */
    103                 return true;
    104         }
     101        /* Don't execute PHP internal error handler */
     102        return true;
    105103}
    106104
    107 set_exception_handler('ErrorHandler::ErrorHandler');
     105set_exception_handler('ErrorHandler');
  • trunk/src/inc/FileHandler.class.php

    r7622 r7631  
    1414         * Function: Handling with a node file
    1515         */
    16         public function __construct(string $filename) {
     16        public function __construct($filename) {
    1717                try {
    18                         $this->file = fopen($filename);
     18                        $handle = fopen($filename, 'r');
     19                        $this->file = '';
     20                        while (!feof($handle)) {
     21                                $this->file .= fread($handle, 8192);
     22                        }
     23                        fclose($handle);
    1924                } catch (Exception $err) {
    2025                        // TODO: Better error description
    2126                        trigger_error();
    2227                }
     28        }
    2329
    24                 // TODO: Needs to do something
     30        public function getFile() {
     31                return $this->file;
    2532        }
    2633}
  • trunk/src/inc/KMLFile.class.php

    r7628 r7631  
    77
    88class KMLFile {
    9         final $template = '
     9        private $template = '
    1010                <?xml version="1.0" encoding="UTF-8"?>
    1111                <kml xmlns="http://www.opengis.net/kml/2.2">
    1212                        %CONTENT%
    1313                </kml>';
     14        private $fileFirst = 'type,host_name,has_been_checked,check_execution_time,current_state,last_hard_state,last_check,problem_has_been_acknowledged';
     15        private $fileContent = array('string', 'string', 'integer', 'double', 'integer', 'integer', 'integer', 'integer');
    1416
    1517        private $KMLPlacemarks = array();
     
    2022         * Function: Creating a new KMLFile
    2123         */
    22         function __construct() {
     24        public function __construct() {
    2325        }
    2426
    25         function addPlacemark(KMLPlacemark $placemark) {
     27        public function addPlacemark(KMLPlacemark $placemark) {
    2628                $this->KMLPlacemarks[] = $placemark;
    2729        }
    2830
    29         function addPlacemark(string $name, string $description, float $xcoordinate, float $ycoordinate) {
    30                 $placemark = new KMLPlacemark();
    31                 $placemark->setName($name);
    32                 $placemark->setDescription($description);
    33                 $placemark->setXCoordinate($xcoordinate);
    34                 $placemark->setYCoordinate($ycoordinate);
    35 
    36                 $this->KMLPlacemarks[] = $placemark;
    37         }
    38 
    39         function toString() {
    40                 $toString = $template;
     31        public function toString() {
     32                $toString = $this->template;
    4133
    4234                $placemarkString = '';
    4335                $placemarkCount = count($this->KMLPlacemarks);
    4436                for ($i = 0; $i < $placemarkCount; $i++) {
    45                         $placemarkString .= $this->KMLPlacemarks->toString();
     37                        $placemarkString .= $this->KMLPlacemarks[$i]->toString();
    4638                }
    4739
    48                 $toString = preg_replace('%CONTENT%', $placemarkString, $toString);
     40                $toString = str_replace('%CONTENT%', $placemarkString, $toString);
    4941
    5042                return $toString;
    5143        }
    5244
    53         function write(string $filename) {
     45        public function write($filename) {
    5446                // TODO: Write KMLFile to a KML file
     47        }
     48
     49        public function parseFile($file) {
     50                $fileContents = explode("\r\n", $nodeStatus->getFile());
     51
     52                if ($fileContents[0] != $this->fileFirst) {
     53                        // TODO: Better error description
     54                        trigger_error();
     55                }
     56
     57                $lines = count($fileContents);
     58                for ($i = 1; $i < count($lines); $i++) {
     59                        $lineContent = explode(',', $fileContents[$i]);
     60
     61                        if (count($lineContent) != count($this->fileContent)) {
     62                                // TODO: Better error description
     63                                trigger_error();
     64                        }
     65
     66                        // TODO: Process all lines and create KMLPlacemark objects we can add to a new KMLFile object
     67                }
    5568        }
    5669}
  • trunk/src/inc/KMLPlacemark.class.php

    r7628 r7631  
    77
    88class KMLPlacemark {
    9         final $template = '
     9        private $template = '
    1010                <placemark>
    1111                        <name>%NAME%</name>
     
    2929        }
    3030
    31         function setName(string $newName) {
     31        function setName($newName) {
    3232                $this->name = $newName;
    3333        }
    3434
    35         function setDescription(string $newDescription) {
    36                 $this->description = $newDescription;
     35        function setDescription($newDescription) {
     36                $this->description = (string) $newDescription;
    3737        }
    3838
    39         function setXCoordinate(float $newXCoordinate) {
    40                 $this->xCoordinate = $newXCoordinate;
     39        function setXCoordinate($newXCoordinate) {
     40                $this->xCoordinate = (double) $newXCoordinate;
    4141        }
    4242
    43         function setYCoordinate(float $newYCoordinate) {
    44                 $this->yCoordinate = $newYCoordinate;
     43        function setYCoordinate($newYCoordinate) {
     44                $this->yCoordinate = (double) $newYCoordinate;
    4545        }
    4646
    4747        function toString() {
    48                 $toString = $template;
     48                $toString = $this->template;
    4949
    50                 $toString = preg_replace('%NAME%', $this->name, $toString);
    51                 $toString = preg_replace('%DESCRIPTION%', $this->description, $toString);
    52                 $toString = preg_replace('%XCOORDINATE%', $this->xCoordinate, $toString);
    53                 $toString = preg_replace('%YCOORDINATE%', $this->yCoordinate, $toString);
     50                $toString = str_replace('%NAME%', $this->name, $toString);
     51                $toString = str_replace('%DESCRIPTION%', $this->description, $toString);
     52                $toString = str_replace('%XCOORDINATE%', $this->xCoordinate, $toString);
     53                $toString = str_replace('%YCOORDINATE%', $this->yCoordinate, $toString);
    5454
    5555                return $toString;
  • trunk/src/inc/LogHandler.class.php

    r7627 r7631  
    1717 *   LOG_DEBUG          Debug-level message
    1818 */
    19 
    20 define('LOG_EMERG', 0);
    21 define('LOG_ALERT', 1);
    22 define('LOG_CRIT', 2);
    23 define('LOG_ERR', 3);
    24 define('LOG_WARNING', 4);
    25 define('LOG_NOTICE', 5);
    26 define('LOG_INFO', 6);
    27 define('LOG_DEBUG', 7);
    2819
    2920class LogHandler {
Note: See TracChangeset for help on using the changeset viewer.