Example #1
0
 private function doServicesRequest()
 {
     $source = $this->doRequest();
     if ($source !== false) {
         parent::parseResponse($source);
         if (count($this->respErrorsList) == 0) {
             $carriers = $this->xpath->query('/operators/operator');
             foreach ($carriers as $c => $carrier) {
                 $index = $c + 1;
                 $result = $this->parseCarrierNode($carrier);
                 $this->carriers[$result["code"]] = $result;
                 $this->carriers[$result["code"]]["services"] = $this->parseServicesNode($index);
             }
         }
     }
 }
Example #2
0
 /**
  * Function executes services request and prepares the $carriers array.
  * @access private
  * @return Void
  */
 private function doServicesRequest()
 {
     $source = $this->doRequest();
     /* Uncomment if ou want to display the XML content */
     //echo '<textarea>'.$source.'</textarea>';
     /* We make sure there is an XML answer and try to parse it */
     if ($source !== false) {
         parent::parseResponse($source);
         if (count($this->respErrorsList) == 0) {
             /* The XML file is loaded, we now gather the datas */
             $carriers = $this->xpath->query('/operators/operator');
             foreach ($carriers as $c => $carrier) {
                 $index = $c + 1;
                 $result = $this->parseCarrierNode($carrier);
                 $this->carriers[$result["code"]] = $result;
                 $this->carriers[$result["code"]]["services"] = $this->parseServicesNode($index);
             }
         }
     }
 }
Example #3
0
function test_Env_Carrier($userData)
{
    $result = default_value();
    $start = microtime_float();
    /* Initialisation */
    $env = new Env_Carrier(array("user" => $userData["login"], "pass" => $userData["password"], "key" => $userData["api_key"]));
    $env->setEnv('test');
    $env->getCarriers();
    /* Reception test */
    if ($env->curlError) {
        $result['reception'] = max($result['reception'], ERROR);
        $result['reception_info'][count($result['reception_info'])] = 'Error while sending the query';
    } else {
        if ($env->respError) {
            $result['reception'] = max($result['reception'], ERROR);
            $result['reception_info'][count($result['reception_info'])] = 'Invalid query : ' . $userData["api_key"];
            foreach ($env->respErrorsList as $message) {
                $result['reception_info'][count($result['reception_info'])] = $message['message'];
            }
        } else {
            $result['reception'] = max($result['reception'], OK);
            $result['reception_info'][count($result['reception_info'])] = 'Reception time : ' . (microtime_float() - $start) . 's';
        }
    }
    /* Additionals test */
    /* Test for the result structure */
    $result['additionals'][0]['name'] = 'Structure';
    $result['additionals'][0]['state'] = OK;
    if (count($env->carriers) == 0) {
        $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING);
        $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '$carriers array is empty';
    } else {
        foreach ($env->carriers as $code => $carrier) {
            if (!isset($carrier['label'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"label" not defined in $carriers["' . $code . '"] array';
            }
            if (!isset($carrier['code'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"code" not defined in $carriers["' . $code . '"] array';
            }
            if (!isset($carrier['logo'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"logo" not defined in $carriers["' . $code . '"] array';
            }
            if (!isset($carrier['logo_modules'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"logo_modules" not defined in $carriers["' . $code . '"] array';
            }
            if (!isset($carrier['description'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"description" not defined in $carriers["' . $code . '"] array';
            }
            if (!isset($carrier['address'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"address" not defined in $carriers["' . $code . '"] array';
            }
            if (!isset($carrier['url'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"url" not defined in $carriers["' . $code . '"] array';
            }
            if (!isset($carrier['tracking'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"tracking" not defined in $carriers["' . $code . '"] array';
            }
            if (!isset($carrier['tel'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"tel" not defined in $carriers["' . $code . '"] array';
            }
            if (!isset($carrier['cgv'])) {
                $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR);
                $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"cgv" not defined in $carriers["' . $code . '"] array';
            }
        }
    }
    $result['duration'] = microtime_float() - $start;
    return $result;
}