ThinkFramework.php 2.0 KB

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