酒店预订平台
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

78 líneas
2.8 KiB

  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: yunwuxin <448901948@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace think\composer;
  12. use Composer\Package\PackageInterface;
  13. use Composer\Repository\InstalledRepositoryInterface;
  14. class ThinkExtend extends LibraryInstaller
  15. {
  16. public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
  17. {
  18. return parent::install($repo, $package)->then(function () use ($package) {
  19. $this->copyExtraFiles($package);
  20. });
  21. }
  22. public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
  23. {
  24. return parent::update($repo, $initial, $target)->then(function () use ($target) {
  25. $this->copyExtraFiles($target);
  26. });
  27. }
  28. protected function copyExtraFiles(PackageInterface $package)
  29. {
  30. if ($this->composer->getPackage()->getType() == 'project') {
  31. $extra = $package->getExtra();
  32. if (!empty($extra['think-config'])) {
  33. $composerExtra = $this->composer->getPackage()->getExtra();
  34. $appDir = !empty($composerExtra['app-path']) ? $composerExtra['app-path'] : 'application';
  35. if (is_dir($appDir)) {
  36. $extraDir = $appDir . DIRECTORY_SEPARATOR . 'extra';
  37. $this->filesystem->ensureDirectoryExists($extraDir);
  38. //配置文件
  39. foreach ((array) $extra['think-config'] as $name => $config) {
  40. $target = $extraDir . DIRECTORY_SEPARATOR . $name . '.php';
  41. $source = $this->getInstallPath($package) . DIRECTORY_SEPARATOR . $config;
  42. if (is_file($target)) {
  43. $this->io->write("<info>File {$target} exist!</info>");
  44. continue;
  45. }
  46. if (!is_file($source)) {
  47. $this->io->write("<info>File {$target} not exist!</info>");
  48. continue;
  49. }
  50. copy($source, $target);
  51. }
  52. }
  53. }
  54. }
  55. }
  56. public function supports($packageType)
  57. {
  58. return 'think-extend' === $packageType;
  59. }
  60. }