You are here

public function DrupalApacheSolrService::setUrl in Apache Solr Search 8

Same name and namespace in other branches
  1. 6.3 Drupal_Apache_Solr_Service.php \DrupalApacheSolrService::setUrl()
  2. 7 Drupal_Apache_Solr_Service.php \DrupalApacheSolrService::setUrl()

Set the Solr url.

Parameters

$url:

Return value

$this

Overrides DrupalApacheSolrServiceInterface::setUrl

1 call to DrupalApacheSolrService::setUrl()
DrupalApacheSolrService::__construct in ./Drupal_Apache_Solr_Service.php
Constructor

File

./Drupal_Apache_Solr_Service.php, line 623

Class

DrupalApacheSolrService
Starting point for the Solr API. Represents a Solr server resource and has methods for pinging, adding, deleting, committing, optimizing and searching.

Code

public function setUrl($url) {
  $parsed_url = parse_url($url);
  if (!isset($parsed_url['scheme'])) {
    $parsed_url['scheme'] = 'http';
  }
  $parsed_url['scheme'] .= '://';
  if (!isset($parsed_url['user'])) {
    $parsed_url['user'] = '';
  }
  else {
    $parsed_url['host'] = '@' . $parsed_url['host'];
  }
  $parsed_url['pass'] = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
  $parsed_url['port'] = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
  if (isset($parsed_url['path'])) {

    // Make sure the path has a single leading/trailing slash.
    $parsed_url['path'] = '/' . ltrim($parsed_url['path'], '/');
    $parsed_url['path'] = rtrim($parsed_url['path'], '/') . '/';
  }
  else {
    $parsed_url['path'] = '/';
  }

  // For now we ignore query and fragment.
  $this->parsed_url = $parsed_url;

  // Force the update url to be rebuilt.
  unset($this->update_url);
  return $this;
}