Changeset View
Changeset View
Standalone View
Standalone View
src/packages/ArcanistPackageDescriptor.php
- This file was added.
<?php | |||||
final class ArcanistPackageDescriptor | |||||
extends Phobject { | |||||
private $identifier; | |||||
private $version; | |||||
private $configSource; | |||||
private $description; | |||||
public static function fromConfig( | |||||
array $config_item, | |||||
ArcanistConfigurationSource $config_source) { | |||||
$ident = idx($config_item, 'identifier'); | |||||
$version = idx($config_item, 'version'); | |||||
if (!strlen($ident) || !strlen($version)) { | |||||
throw new ArcanistUsageException( | |||||
pht( | |||||
'Package configuration requires both identifier and a version. '. | |||||
'(reading %s)', | |||||
$config_source->getSourceDisplayName())); | |||||
} | |||||
return id(new self()) | |||||
->setIdentifier($ident) | |||||
->setVersion($version) | |||||
->setConfigSource($config_source); | |||||
} | |||||
public static function fromDirectory($directory) { | |||||
$filename = $directory.'/.arcpackage'; | |||||
if (!Filesystem::pathExists($filename)) { | |||||
return null; | |||||
} | |||||
$manifest = phutil_json_decode(Filesystem::readFile($filename)); | |||||
return self::fromManifest($manifest); | |||||
} | |||||
/** | |||||
* "Manifest" refers to the .arcpackage file. | |||||
*/ | |||||
public static function fromManifest(array $manifest) { | |||||
$ident = idx($manifest, 'identifier'); | |||||
$version = idx($manifest, 'version'); | |||||
if (!strlen($ident) || !strlen($version)) { | |||||
throw new ArcanistUsageException(pht('Bad manifest file!')); | |||||
} | |||||
return id(new self()) | |||||
->setIdentifier($ident) | |||||
->setVersion($version) | |||||
->setDescription(idx($manifest, 'description')); | |||||
} | |||||
public function __toString() { | |||||
return pht('Package %s (ver %s)', $this->identifier, $this->version); | |||||
} | |||||
public function getDirectoryName() { | |||||
return $this->identifier.'-'.$this->version; | |||||
} | |||||
public function setConfigSource(ArcanistConfigurationSource $config_source) { | |||||
$this->configSource = $config_source; | |||||
return $this; | |||||
} | |||||
public function getConfigSource() { | |||||
return $this->configSource; | |||||
} | |||||
public function setDescription($description) { | |||||
$this->description = $description; | |||||
return $this; | |||||
} | |||||
public function getDescription() { | |||||
return $this->description; | |||||
} | |||||
public function setIdentifier(string $identifier) { | |||||
$this->identifier = $identifier; | |||||
return $this; | |||||
} | |||||
public function getIdentifier() { | |||||
return $this->identifier; | |||||
} | |||||
public function setVersion(string $version) { | |||||
$this->version = $version; | |||||
return $this; | |||||
} | |||||
public function getVersion() { | |||||
return $this->version; | |||||
} | |||||
} |