Skip to content

Instantly share code, notes, and snippets.

@hailwood
Created April 21, 2014 09:07
Show Gist options
  • Save hailwood/11137012 to your computer and use it in GitHub Desktop.
Save hailwood/11137012 to your computer and use it in GitHub Desktop.
<?php namespace Vapor\Theme\Composer;
use Composer\Package\PackageInterface;
use Composer\Installer\LibraryInstaller;
use Composer\Repository\InstalledRepositoryInterface;
class ThemeInstaller extends LibraryInstaller {
protected $type = 'vapor-theme';
protected $thumbnailFile = 'thumbnail.png';
public function install(InstalledRepositoryInterface $repo, PackageInterface $package){
parent::install($repo, $package);
//copy thumbnail
}
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target){
parent::update($repo, $initial, $target);
$this->removeThumbnail($initial);
$this->installThumbnail($target);
}
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package){
parent::uninstall($repo, $package);
$this->removeThumbnail($package);
}
protected function installThumbnail(PackageInterface $package){
if(!file_exists($this->getInstallPath($package).$this->thumbnailFile)){
$this->io->write(' <warning>Skipped installation of '.$this->thumbnailFile.' for package '.$package->getName().': file not found in package</warning>');
return;
}
$this->removeThumbnail($package);
$source = $this->getInstallPath($package).$this->thumbnailFile;
$destination = $this->vendorDir.'/../public/packages/'.$package->getPrettyName().'/';
$this->filesystem->ensureDirectoryExists($destination);
copy($source, $destination.$this->thumbnailFile);
}
protected function removeThumbnail(PackageInterface $package){
$this->filesystem->remove($this->vendorDir.'/../public/packages/'.$package->getPrettyName().'/'.$this->thumbnailFile);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment