/**
  * Returns the configuration
  *
  * @param integer $id
  *
  * @return array
  */
 public function getConfiguration($id)
 {
     if (!isset($this->configurationArray[$id])) {
         $modTsConfig = t3lib_BEfunc::getModTSconfig($id, 'mod.vcc');
         $this->configurationArray[$id] = $modTsConfig['properties'];
         // Log debug information
         $logData = array('id' => $id, 'configuration' => $modTsConfig['properties']);
         $this->loggingService->debug('TsConfigService::getConfiguration id: ' . $id, $logData);
     }
     return $this->configurationArray[$id];
 }
 /**
  * Processes the CURL request and sends action to Varnish server
  *
  * @param string $url
  * @param integer $pid
  * @param string $host
  * @param boolean $quote
  *
  * @return array
  */
 protected function processClearCacheCommand($url, $pid, $host = '', $quote = TRUE)
 {
     $responseArray = array();
     foreach ($this->serverArray as $server) {
         $response = array('server' => $server);
         // Build request
         if ($this->stripSlash) {
             $url = rtrim($url, '/');
         }
         $request = $server . '/' . ltrim($url, '/');
         $response['request'] = $request;
         // Check for curl functions
         if (!function_exists('curl_init')) {
             // TODO: Implement fallback to file_get_contents()
             $response['status'] = t3lib_FlashMessage::ERROR;
             $response['message'] = 'No curl_init available';
         } else {
             // If no host was given we need to loop over all
             $hostArray = array();
             if ($host !== '') {
                 $hostArray = t3lib_div::trimExplode(',', $host, 1);
             } else {
                 // Get all (non-redirecting) domains from root
                 $rootLine = t3lib_BEfunc::BEgetRootLine($pid);
                 foreach ($rootLine as $row) {
                     $domainArray = t3lib_BEfunc::getRecordsByField('sys_domain', 'pid', $row['uid'], ' AND redirectTo="" AND hidden=0');
                     if (is_array($domainArray) && !empty($domainArray)) {
                         foreach ($domainArray as $domain) {
                             $hostArray[] = $domain['domainName'];
                         }
                         unset($domain);
                     }
                 }
                 unset($row);
             }
             // Fallback to current server
             if (empty($hostArray)) {
                 $domain = rtrim(t3lib_div::getIndpEnv('TYPO3_SITE_URL'), '/');
                 $hostArray[] = substr($domain, strpos($domain, '://') + 3);
             }
             // Loop over hosts
             foreach ($hostArray as $xHost) {
                 $response['host'] = $xHost;
                 // Curl initialization
                 $ch = curl_init();
                 // Disable direct output
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                 // Only get header response
                 curl_setopt($ch, CURLOPT_HEADER, 1);
                 curl_setopt($ch, CURLOPT_NOBODY, 1);
                 // Set url
                 curl_setopt($ch, CURLOPT_URL, $request);
                 // Set method and protocol
                 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->httpMethod);
                 curl_setopt($ch, CURLOPT_HTTP_VERSION, $this->httpProtocol === 'http_10' ? CURL_HTTP_VERSION_1_0 : CURL_HTTP_VERSION_1_1);
                 // Set X-Host and X-Url header
                 curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Host: ' . ($quote ? preg_quote($xHost) : $xHost), 'X-Url: ' . ($quote ? preg_quote($url) : $url)));
                 // Store outgoing header
                 curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
                 // Include preProcess hook (e.g. to set some alternative curl options
                 foreach ($this->hookObjects as $hookObject) {
                     /** @var tx_vcc_hook_communicationServiceHookInterface $hookObject */
                     $hookObject->preProcess($ch, $request, $response, $this);
                 }
                 unset($hookObject);
                 $header = curl_exec($ch);
                 if (!curl_error($ch)) {
                     $response['status'] = curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200 ? t3lib_FlashMessage::OK : t3lib_FlashMessage::ERROR;
                     $response['message'] = preg_split('/(\\r|\\n)+/m', trim($header));
                 } else {
                     $response['status'] = t3lib_FlashMessage::ERROR;
                     $response['message'] = array(curl_error($ch));
                 }
                 $response['requestHeader'] = preg_split('/(\\r|\\n)+/m', trim(curl_getinfo($ch, CURLINFO_HEADER_OUT)));
                 // Include postProcess hook (e.g. to start some other jobs)
                 foreach ($this->hookObjects as $hookObject) {
                     /** @var tx_vcc_hook_communicationServiceHookInterface $hookObject */
                     $hookObject->postProcess($ch, $request, $response, $this);
                 }
                 unset($hookObject);
                 curl_close($ch);
                 // Log debug information
                 $logData = array('url' => $url, 'pid' => $pid, 'host' => $host, 'response' => $response);
                 $logType = $response['status'] == t3lib_FlashMessage::OK ? tx_vcc_service_loggingService::OK : tx_vcc_service_loggingService::ERROR;
                 $this->loggingService->log('CommunicationService::processClearCacheCommand', $logData, $logType, $pid, 3);
                 $responseArray[] = $response;
             }
             unset($xHost);
         }
     }
     unset($server);
     return $responseArray;
 }