Back to Update class

Method loadFromXml

public bool
loadFromXml
(mixed $url, mixed $minimumStability = Updater::STABILITY_STABLE)
Loads an XML file from a URL.
Parameters
  • string $url The URL.
  • int $minimumStability The minimum stability required for updating the extension {@see \Joomla\CMS\Updater\Updater}
Returns
  • bool True on success
Since
  • 1.7.0
Class: Update
Project: Joomla

Method loadFromXml - Source code

/**
 * Loads an XML file from a URL.
 *
 * @param   string  $url               The URL.
 * @param   int     $minimumStability  The minimum stability required for updating the extension {@see Updater}
 *
 * @return  boolean  True on success
 *
 * @since   1.7.0
 */
public function loadFromXml($url, $minimumStability = Updater::STABILITY_STABLE)
{
    $version = new Version();
    $httpOption = new Registry();
    $httpOption->set('userAgent', $version->getUserAgent('Joomla', true, false));
    try {
        $http = HttpFactory::getHttp($httpOption);
        $response = $http->get($url);
    } catch (\RuntimeException $e) {
        $response = null;
    }
    if ($response === null || $response->code !== 200) {
        // @todo: Add a 'mark bad' setting here somehow
        Log::add(Text::sprintf('JLIB_UPDATER_ERROR_EXTENSION_OPEN_URL', $url), Log::WARNING, 'jerror');
        return false;
    }
    $this->minimum_stability = $minimumStability;
    $this->xmlParser = xml_parser_create('');
    xml_set_object($this->xmlParser, $this);
    xml_set_element_handler($this->xmlParser, '_startElement', '_endElement');
    xml_set_character_data_handler($this->xmlParser, '_characterData');
    if (!xml_parse($this->xmlParser, $response->body)) {
        Log::add(sprintf('XML error: %s at line %d', xml_error_string(xml_get_error_code($this->xmlParser)), xml_get_current_line_number($this->xmlParser)), Log::WARNING, 'updater');
        return false;
    }
    xml_parser_free($this->xmlParser);
    return true;
}