You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

59 lines
1.8 KiB

  1. <?php
  2. namespace think\composer;
  3. use Composer\Installer\LibraryInstaller;
  4. use Composer\Package\PackageInterface;
  5. use Composer\Repository\InstalledRepositoryInterface;
  6. class ThinkFramework extends LibraryInstaller
  7. {
  8. public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
  9. {
  10. parent::install($repo, $package);
  11. if ($this->composer->getPackage()->getType() == 'project' && $package->getInstallationSource() != 'source') {
  12. //remove tests dir
  13. $this->filesystem->removeDirectory($this->getInstallPath($package) . DIRECTORY_SEPARATOR . 'tests');
  14. }
  15. }
  16. /**
  17. * {@inheritDoc}
  18. */
  19. public function getInstallPath(PackageInterface $package)
  20. {
  21. if ('topthink/framework' !== $package->getPrettyName()) {
  22. throw new \InvalidArgumentException('Unable to install this library!');
  23. }
  24. if ($this->composer->getPackage()->getType() !== 'project') {
  25. return parent::getInstallPath($package);
  26. }
  27. if ($this->composer->getPackage()) {
  28. $extra = $this->composer->getPackage()->getExtra();
  29. if (!empty($extra['think-path'])) {
  30. return $extra['think-path'];
  31. }
  32. }
  33. return 'thinkphp';
  34. }
  35. public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
  36. {
  37. parent::update($repo, $initial, $target);
  38. if ($this->composer->getPackage()->getType() == 'project' && $target->getInstallationSource() != 'source') {
  39. //remove tests dir
  40. $this->filesystem->removeDirectory($this->getInstallPath($target) . DIRECTORY_SEPARATOR . 'tests');
  41. }
  42. }
  43. /**
  44. * {@inheritDoc}
  45. */
  46. public function supports($packageType)
  47. {
  48. return 'think-framework' === $packageType;
  49. }
  50. }