Make ArrayDumper and ArrayLoader reversible
parent
4904e76185
commit
b100df33d8
|
@ -68,7 +68,7 @@ class DownloadManager
|
||||||
public function getDownloader($type)
|
public function getDownloader($type)
|
||||||
{
|
{
|
||||||
if (!isset($this->downloaders[$type])) {
|
if (!isset($this->downloaders[$type])) {
|
||||||
throw new \InvalidArgumentException('Unknown source type: '.$type);
|
throw new \InvalidArgumentException('Unknown downloader type: '.$type);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->downloaders[$type];
|
return $this->downloaders[$type];
|
||||||
|
|
|
@ -16,6 +16,7 @@ use Composer\Package\PackageInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Konstantin Kudryashiv <ever.zet@gmail.com>
|
* @author Konstantin Kudryashiv <ever.zet@gmail.com>
|
||||||
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||||
*/
|
*/
|
||||||
class ArrayDumper
|
class ArrayDumper
|
||||||
{
|
{
|
||||||
|
@ -25,12 +26,7 @@ class ArrayDumper
|
||||||
'type',
|
'type',
|
||||||
'names',
|
'names',
|
||||||
'extra',
|
'extra',
|
||||||
'installationSource',
|
'installationSource' => 'installation-source',
|
||||||
'sourceType',
|
|
||||||
'sourceUrl',
|
|
||||||
'distType',
|
|
||||||
'distUrl',
|
|
||||||
'distSha1Checksum',
|
|
||||||
'version',
|
'version',
|
||||||
'license',
|
'license',
|
||||||
'requires',
|
'requires',
|
||||||
|
@ -48,8 +44,26 @@ class ArrayDumper
|
||||||
if ($package->getTargetDir()) {
|
if ($package->getTargetDir()) {
|
||||||
$data['target-dir'] = $package->getTargetDir();
|
$data['target-dir'] = $package->getTargetDir();
|
||||||
}
|
}
|
||||||
foreach ($keys as $key) {
|
|
||||||
$getter = 'get'.ucfirst($key);
|
if ($package->getSourceType()) {
|
||||||
|
$data['source']['type'] = $package->getSourceType();
|
||||||
|
$data['source']['url'] = $package->getSourceUrl();
|
||||||
|
$data['source']['reference'] = $package->getSourceReference();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($package->getDistType()) {
|
||||||
|
$data['dist']['type'] = $package->getDistType();
|
||||||
|
$data['dist']['url'] = $package->getDistUrl();
|
||||||
|
$data['dist']['reference'] = $package->getDistReference();
|
||||||
|
$data['dist']['shasum'] = $package->getDistSha1Checksum();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($keys as $method => $key) {
|
||||||
|
if (is_numeric($method)) {
|
||||||
|
$method = $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
$getter = 'get'.ucfirst($method);
|
||||||
$value = $package->$getter();
|
$value = $package->$getter();
|
||||||
|
|
||||||
if (null !== $value && !(is_array($value) && 0 === count($value))) {
|
if (null !== $value && !(is_array($value) && 0 === count($value))) {
|
||||||
|
|
|
@ -73,6 +73,10 @@ class ArrayLoader
|
||||||
$package->setLicense($config['license']);
|
$package->setLicense($config['license']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($config['installation-source'])) {
|
||||||
|
$package->setInstallationSource($config['installation-source']);
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($config['source'])) {
|
if (isset($config['source'])) {
|
||||||
if (!isset($config['source']['type']) || !isset($config['source']['url'])) {
|
if (!isset($config['source']['type']) || !isset($config['source']['url'])) {
|
||||||
throw new \UnexpectedValueException(sprintf(
|
throw new \UnexpectedValueException(sprintf(
|
||||||
|
|
Loading…
Reference in New Issue