installer and downloaders update
parent
d7fe0dfda4
commit
d2150a3c2e
|
@ -20,4 +20,5 @@ use Composer\Package\PackageInterface;
|
|||
interface DownloaderInterface
|
||||
{
|
||||
function download(PackageInterface $package, $path, $url, $checksum = null);
|
||||
function isDownloaded(PackageInterface $package, $path);
|
||||
}
|
||||
|
|
|
@ -28,18 +28,17 @@ class GitDownloader implements DownloaderInterface
|
|||
|
||||
public function download(PackageInterface $package, $path, $url, $checksum = null)
|
||||
{
|
||||
if (!is_dir($path)) {
|
||||
if (file_exists($path)) {
|
||||
throw new \UnexpectedValueException($path.' exists and is not a directory.');
|
||||
}
|
||||
if (!mkdir($path, 0777, true)) {
|
||||
throw new \UnexpectedValueException($path.' does not exist and could not be created.');
|
||||
}
|
||||
}
|
||||
if ($this->clone) {
|
||||
system('git clone '.escapeshellarg($url).' -b master '.escapeshellarg($path.'/'.$package->getName()));
|
||||
} else {
|
||||
system('git archive --format=tar --prefix='.escapeshellarg($package->getName()).' --remote='.escapeshellarg($url).' master | tar -xf -');
|
||||
}
|
||||
}
|
||||
|
||||
public function isDownloaded(PackageInterface $package, $path)
|
||||
{
|
||||
$targetPath = $path . '/' . $package->getName();
|
||||
|
||||
return is_dir($targetPath);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,4 +66,11 @@ class PearDownloader implements DownloaderInterface
|
|||
}
|
||||
chdir($cwd);
|
||||
}
|
||||
|
||||
public function isDownloaded(PackageInterface $package, $path)
|
||||
{
|
||||
$targetPath = $path . '/' . $package->getName();
|
||||
|
||||
return is_dir($targetPath);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,4 +73,11 @@ class ZipDownloader implements DownloaderInterface
|
|||
throw new \UnexpectedValueException($zipName.' is not a valid zip archive, got error code '.$retval);
|
||||
}
|
||||
}
|
||||
|
||||
public function isDownloaded(PackageInterface $package, $path)
|
||||
{
|
||||
$targetPath = $path . '/' . $package->getName();
|
||||
|
||||
return is_dir($targetPath);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,15 +18,18 @@ use Composer\Composer;
|
|||
|
||||
/**
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
||||
*/
|
||||
class LibraryInstaller implements InstallerInterface
|
||||
{
|
||||
private $dir;
|
||||
private $composer;
|
||||
private $preferSource;
|
||||
|
||||
public function __construct($dir = 'vendor')
|
||||
public function __construct($dir = 'vendor', $preferSource = false)
|
||||
{
|
||||
$this->dir = $dir;
|
||||
$this->preferSource = $preferSource;
|
||||
}
|
||||
|
||||
public function setComposer(Composer $composer)
|
||||
|
@ -36,39 +39,52 @@ class LibraryInstaller implements InstallerInterface
|
|||
|
||||
public function install(PackageInterface $package)
|
||||
{
|
||||
if ($package->getDistType()) {
|
||||
if (!is_dir($this->dir)) {
|
||||
if (file_exists($this->dir)) {
|
||||
throw new \UnexpectedValueException($this->dir.' exists and is not a directory.');
|
||||
}
|
||||
if (!mkdir($this->dir, 0777, true)) {
|
||||
throw new \UnexpectedValueException($this->path.' does not exist and could not be created.');
|
||||
}
|
||||
}
|
||||
|
||||
$this->composer->getDownloader($package->getDistType())->download(
|
||||
if (!($this->preferSource && $package->getSourceType()) && $package->getDistType()) {
|
||||
$downloader = $this->composer->getDownloader($package->getDistType());
|
||||
|
||||
return $downloader->download(
|
||||
$package, $this->dir, $package->getDistUrl(), $package->getDistSha1Checksum()
|
||||
);
|
||||
|
||||
} elseif ($package->getSourceType()) {
|
||||
|
||||
$this->composer->getDownloader($package->getSourceType())->download(
|
||||
$package, $this->dir, $package->getSourceUrl()
|
||||
);
|
||||
|
||||
} else {
|
||||
throw new \InvalidArgumentException(
|
||||
'Type must be one of (dist, source), '.$type.' given.'
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
if ($package->getSourceType()) {
|
||||
$downloader = $this->composer->getDownloader($package->getSourceType());
|
||||
|
||||
return $downloader->download(
|
||||
$package, $this->dir, $package->getSourceUrl()
|
||||
);
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException('Package should have dist or source specified');
|
||||
}
|
||||
|
||||
public function isInstalled(PackageInterface $package)
|
||||
{
|
||||
// TODO: implement installation check
|
||||
}
|
||||
if ($package->getSourceType()) {
|
||||
$downloader = $this->composer->getDownloader($package->getSourceType());
|
||||
|
||||
public function update(PackageInterface $package)
|
||||
{
|
||||
// TODO: implement package update
|
||||
}
|
||||
if ($downloader->isDownloaded($package, $this->dir)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function remove(PackageInterface $package)
|
||||
{
|
||||
// TODO: implement package removal
|
||||
if ($package->getDistType()) {
|
||||
$downloader = $this->composer->getDownloader($package->getDistType());
|
||||
|
||||
if ($downloader->isDownloaded($package, $this->dir)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue