class UpdateFetcher in Drupal 8
Same name and namespace in other branches
- 9 core/modules/update/src/UpdateFetcher.php \Drupal\update\UpdateFetcher
Fetches project information from remote locations.
Hierarchy
- class \Drupal\update\UpdateFetcher implements UpdateFetcherInterface uses DependencySerializationTrait
Expanded class hierarchy of UpdateFetcher
1 file declares its use of UpdateFetcher
- UpdateFetcherTest.php in core/
modules/ update/ tests/ src/ Unit/ UpdateFetcherTest.php
1 string reference to 'UpdateFetcher'
- update.services.yml in core/
modules/ update/ update.services.yml - core/modules/update/update.services.yml
1 service uses UpdateFetcher
- update.fetcher in core/
modules/ update/ update.services.yml - Drupal\update\UpdateFetcher
File
- core/
modules/ update/ src/ UpdateFetcher.php, line 13
Namespace
Drupal\updateView source
class UpdateFetcher implements UpdateFetcherInterface {
use DependencySerializationTrait;
/**
* URL to check for updates, if a given project doesn't define its own.
*/
const UPDATE_DEFAULT_URL = 'http://updates.drupal.org/release-history';
/**
* The fetch url configured in the update settings.
*
* @var string
*/
protected $fetchUrl;
/**
* The update settings
*
* @var \Drupal\Core\Config\Config
*/
protected $updateSettings;
/**
* The HTTP client to fetch the feed data with.
*
* @var \GuzzleHttp\ClientInterface
*/
protected $httpClient;
/**
* Constructs a UpdateFetcher.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \GuzzleHttp\ClientInterface $http_client
* A Guzzle client object.
*/
public function __construct(ConfigFactoryInterface $config_factory, ClientInterface $http_client) {
$this->fetchUrl = $config_factory
->get('update.settings')
->get('fetch.url');
$this->httpClient = $http_client;
$this->updateSettings = $config_factory
->get('update.settings');
}
/**
* {@inheritdoc}
*/
public function fetchProjectData(array $project, $site_key = '') {
$url = $this
->buildFetchUrl($project, $site_key);
$data = '';
try {
$data = (string) $this->httpClient
->get($url, [
'headers' => [
'Accept' => 'text/xml',
],
])
->getBody();
} catch (RequestException $exception) {
watchdog_exception('update', $exception);
}
return $data;
}
/**
* {@inheritdoc}
*/
public function buildFetchUrl(array $project, $site_key = '') {
$name = $project['name'];
$url = $this
->getFetchBaseUrl($project);
$url .= '/' . $name . '/current';
// Only append usage information if we have a site key and the project is
// enabled. We do not want to record usage statistics for disabled projects.
if (!empty($site_key) && strpos($project['project_type'], 'disabled') === FALSE) {
// Append the site key.
$url .= strpos($url, '?') !== FALSE ? '&' : '?';
$url .= 'site_key=';
$url .= rawurlencode($site_key);
// Append the version.
if (!empty($project['info']['version'])) {
$url .= '&version=';
$url .= rawurlencode($project['info']['version']);
}
// Append the list of modules or themes enabled.
$list = array_keys($project['includes']);
$url .= '&list=';
$url .= rawurlencode(implode(',', $list));
}
return $url;
}
/**
* {@inheritdoc}
*/
public function getFetchBaseUrl($project) {
if (isset($project['info']['project status url'])) {
$url = $project['info']['project status url'];
}
else {
$url = $this->fetchUrl;
if (empty($url)) {
$url = static::UPDATE_DEFAULT_URL;
}
}
return $url;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
UpdateFetcher:: |
protected | property | The fetch url configured in the update settings. | |
UpdateFetcher:: |
protected | property | The HTTP client to fetch the feed data with. | |
UpdateFetcher:: |
protected | property | The update settings | |
UpdateFetcher:: |
public | function |
Generates the URL to fetch information about project updates. Overrides UpdateFetcherInterface:: |
|
UpdateFetcher:: |
public | function |
Retrieves the project information. Overrides UpdateFetcherInterface:: |
|
UpdateFetcher:: |
public | function |
Returns the base of the URL to fetch available update data for a project. Overrides UpdateFetcherInterface:: |
|
UpdateFetcher:: |
constant | URL to check for updates, if a given project doesn't define its own. | ||
UpdateFetcher:: |
public | function | Constructs a UpdateFetcher. | |
UpdateFetcherInterface:: |
constant | We need to (re)fetch available update data for this project. | ||
UpdateFetcherInterface:: |
constant | Project's status cannot be checked. | ||
UpdateFetcherInterface:: |
constant | There was a failure fetching available update data for this project. | ||
UpdateFetcherInterface:: |
constant | No available update data was found for project. |