Overview

Namespaces

  • Mapbender
    • Component
      • HTTP
    • CoreBundle
      • Command
      • Component
        • Exception
      • Controller
      • DataFixtures
        • ORM
      • DependencyInjection
      • Element
        • Type
      • Entity
      • EventListener
      • Extension
      • Form
        • DataTransformer
        • EventListener
        • Type
      • Security
      • Template
    • DrupalIntegrationBundle
      • DependencyInjection
      • Security
        • Authentication
          • Provider
          • Token
        • Authorization
          • Voter
        • Factory
        • Firewall
        • User
      • Session
    • KmlBundle
      • Element
    • ManagerBundle
      • Controller
      • Form
        • DataTransformer
        • Type
    • MonitoringBundle
      • Command
      • Component
      • Controller
      • DependencyInjection
      • Entity
      • EventListener
      • Form
    • PrintBundle
      • Component
      • Controller
    • WmcBundle
      • Component
        • Exception
      • Element
        • Type
      • Entity
      • Form
        • EventListener
        • Type
    • WmsBundle
      • Component
        • Exception
      • Controller
      • DependencyInjection
      • Element
        • Type
      • Entity
      • Event
      • Form
        • EventListener
        • Type
    • WmtsBundle
      • Component
        • Exception
      • Controller
      • Entity
      • Form
        • Type
  • None
  • PHP

Classes

  • MonitoringRunner
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
 1: <?php
 2: namespace Mapbender\MonitoringBundle\Component;
 3: use Mapbender\MonitoringBundle\Entity\MonitoringDefinition;
 4: use Mapbender\MonitoringBundle\Entity\MonitoringJob;
 5: use Mapbender\Component\HTTP\HTTPClient;
 6: 
 7: class MonitoringRunner {
 8:     protected $md;
 9:     protected $client;
10: 
11:     public function __construct(MonitoringDefinition $md,HTTPclient $client){
12:         $this->md = $md;
13:         $this->client = $client;
14:     }
15: 
16:     public function run(){
17:         $job = new MonitoringJob();
18:         $time_pre = microtime(true);
19:         $result = null;
20: 
21:         try {
22:             $result = $this->client->open($this->md->getRequestUrl());
23:             if($result->getStatusCode()=="200") {
24:                 if(is_int(strpos($result->getHeader('Content-Type'), "image/"))){ # check if contentType image
25:                     $job->setResult(base64_encode($result->getData()));
26:                     $job->setSTATUS(MonitoringJob::$STATUS_SUCCESS);
27:                 } else {
28:                     $job->setResult($result->getData());
29:                     $isXml = true;
30:                     $xml = new \DOMDocument();
31:                     if(!$xml->loadXML($result->getData())){
32:                         if(!$xml->loadHTML($xmlDocStr)){
33:                               $isXml = false;
34:                         }
35:                     }
36:                     if($isXml){
37:                         if(strripos(strtolower($xml->documentElement->tagName), "exception") !== false){
38:                             $job->setSTATUS(MonitoringJob::$STATUS_ERROR.":".MonitoringJob::$STATUS_EXCEPTION);
39:                         } else {
40:                             $job->setSTATUS(MonitoringJob::$STATUS_SUCCESS);
41:                         }
42:                     } else {
43:                         $job->setSTATUS(MonitoringJob::$STATUS_SUCCESS);
44:                     }
45:                 }
46:             } else {
47:                 $job->setResult($result->getData());
48:                 $job->setSTATUS(MonitoringJob::$STATUS_ERROR.":".$result->getStatusCode());
49:             }
50:         }catch(\Exception $E){
51:             $job->setSTATUS(MonitoringJob::$STATUS_TIMEOUT);
52:         }
53:         $time_post = microtime(true);
54:         $job->setMonitoringDefinition($this->md);
55:         $job->setLatency(round($time_post-$time_pre,3));
56:         return $job;
57:     }
58: }
59: 
Mapbender3 API documenation API documentation generated by ApiGen 2.8.0