function Project::__construct

8.0.x Project.php Project::__construct(\SimpleXMLElement $xml)
7.x Project.php Project::__construct(\SimpleXMLElement $xml)
master Project.php Project::__construct(\SimpleXMLElement $xml)

Constructor.

Parameters

string $project_name: Project name.

\SimpleXMLElement $xml: XML data.

File

lib/Drush/UpdateService/Project.php, line 23

Namespace

Drush\UpdateService

Class

Project
Representation of a project's release info from the update service.

Code

function __construct(\SimpleXMLElement $xml) {
  // Check if the xml contains an error on the project.
  if ($error = $xml->xpath('/error')) {
    $error = (string) $error[0];
    if (strpos($error, 'No release history available for') === 0) {
      $project_status = 'unsupported';
    }
    elseif (strpos($error, 'No release history was found for the requested project') === 0) {
      $project_status = 'unknown';
    }
    // Any other error we are not aware of.
    else {
      $project_status = 'unknown';
    }
  }
  // The xml has a project, but still it can have errors.
  else {
    $this->parsed = self::parseXml($xml);
    if (empty($this->parsed['releases'])) {
      $error = dt('No available releases found for the requested project (!name).', array('!name' => $this->parsed['short_name']));
      $project_status = 'unknown';
    }
    else {
      $error = FALSE;
      $project_status = $xml->xpath('/project/project_status');
      $project_status = (string) $project_status[0];
    }
  }

  $this->project_status = $project_status;
  $this->error = $error;
  if ($error) {
    drush_set_error('DRUSH_RELEASE_INFO_ERROR', $error);
  }
}