更新
This commit is contained in:
28
vendor/topthink/think-installer/src/LibraryInstaller.php
vendored
Normal file
28
vendor/topthink/think-installer/src/LibraryInstaller.php
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace think\composer;
|
||||
|
||||
use Composer\Package\PackageInterface;
|
||||
use Composer\Repository\InstalledRepositoryInterface;
|
||||
use React\Promise\PromiseInterface;
|
||||
|
||||
abstract class LibraryInstaller extends \Composer\Installer\LibraryInstaller
|
||||
{
|
||||
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
|
||||
{
|
||||
return $this->makePromise(parent::install($repo, $package));
|
||||
}
|
||||
|
||||
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
|
||||
{
|
||||
return $this->makePromise(parent::update($repo, $initial, $target));
|
||||
}
|
||||
|
||||
protected function makePromise($promise)
|
||||
{
|
||||
if ($promise instanceof PromiseInterface) {
|
||||
return $promise;
|
||||
}
|
||||
return new Promise();
|
||||
}
|
||||
}
|
||||
34
vendor/topthink/think-installer/src/Plugin.php
vendored
Normal file
34
vendor/topthink/think-installer/src/Plugin.php
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace think\composer;
|
||||
|
||||
use Composer\Composer;
|
||||
use Composer\IO\IOInterface;
|
||||
use Composer\Plugin\PluginInterface;
|
||||
|
||||
class Plugin implements PluginInterface
|
||||
{
|
||||
public function activate(Composer $composer, IOInterface $io)
|
||||
{
|
||||
$manager = $composer->getInstallationManager();
|
||||
|
||||
//框架核心
|
||||
$manager->addInstaller(new ThinkFramework($io, $composer));
|
||||
|
||||
//单元测试
|
||||
$manager->addInstaller(new ThinkTesting($io, $composer));
|
||||
|
||||
//扩展
|
||||
$manager->addInstaller(new ThinkExtend($io, $composer));
|
||||
}
|
||||
|
||||
public function deactivate(Composer $composer, IOInterface $io)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function uninstall(Composer $composer, IOInterface $io)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
vendor/topthink/think-installer/src/Promise.php
vendored
Normal file
11
vendor/topthink/think-installer/src/Promise.php
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace think\composer;
|
||||
|
||||
class Promise
|
||||
{
|
||||
public function then($callable)
|
||||
{
|
||||
$callable();
|
||||
}
|
||||
}
|
||||
77
vendor/topthink/think-installer/src/ThinkExtend.php
vendored
Normal file
77
vendor/topthink/think-installer/src/ThinkExtend.php
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: yunwuxin <448901948@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\composer;
|
||||
|
||||
use Composer\Package\PackageInterface;
|
||||
use Composer\Repository\InstalledRepositoryInterface;
|
||||
|
||||
class ThinkExtend extends LibraryInstaller
|
||||
{
|
||||
|
||||
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
|
||||
{
|
||||
return parent::install($repo, $package)->then(function () use ($package) {
|
||||
$this->copyExtraFiles($package);
|
||||
});
|
||||
}
|
||||
|
||||
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
|
||||
{
|
||||
return parent::update($repo, $initial, $target)->then(function () use ($target) {
|
||||
$this->copyExtraFiles($target);
|
||||
});
|
||||
}
|
||||
|
||||
protected function copyExtraFiles(PackageInterface $package)
|
||||
{
|
||||
if ($this->composer->getPackage()->getType() == 'project') {
|
||||
|
||||
$extra = $package->getExtra();
|
||||
|
||||
if (!empty($extra['think-config'])) {
|
||||
|
||||
$composerExtra = $this->composer->getPackage()->getExtra();
|
||||
|
||||
$appDir = !empty($composerExtra['app-path']) ? $composerExtra['app-path'] : 'application';
|
||||
|
||||
if (is_dir($appDir)) {
|
||||
|
||||
$extraDir = $appDir . DIRECTORY_SEPARATOR . 'extra';
|
||||
$this->filesystem->ensureDirectoryExists($extraDir);
|
||||
|
||||
//配置文件
|
||||
foreach ((array) $extra['think-config'] as $name => $config) {
|
||||
$target = $extraDir . DIRECTORY_SEPARATOR . $name . '.php';
|
||||
$source = $this->getInstallPath($package) . DIRECTORY_SEPARATOR . $config;
|
||||
|
||||
if (is_file($target)) {
|
||||
$this->io->write("<info>File {$target} exist!</info>");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!is_file($source)) {
|
||||
$this->io->write("<info>File {$target} not exist!</info>");
|
||||
continue;
|
||||
}
|
||||
|
||||
copy($source, $target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function supports($packageType)
|
||||
{
|
||||
return 'think-extend' === $packageType;
|
||||
}
|
||||
}
|
||||
62
vendor/topthink/think-installer/src/ThinkFramework.php
vendored
Normal file
62
vendor/topthink/think-installer/src/ThinkFramework.php
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace think\composer;
|
||||
|
||||
use Composer\Package\PackageInterface;
|
||||
use Composer\Repository\InstalledRepositoryInterface;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class ThinkFramework extends LibraryInstaller
|
||||
{
|
||||
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
|
||||
{
|
||||
return parent::install($repo, $package)->then(function () use ($package) {
|
||||
if ($this->composer->getPackage()
|
||||
->getType() == 'project' && $package->getInstallationSource() != 'source') {
|
||||
//remove tests dir
|
||||
$this->filesystem->removeDirectory($this->getInstallPath($package) . DIRECTORY_SEPARATOR . 'tests');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getInstallPath(PackageInterface $package)
|
||||
{
|
||||
if ('topthink/framework' !== $package->getPrettyName()) {
|
||||
throw new InvalidArgumentException('Unable to install this library!');
|
||||
}
|
||||
|
||||
if ($this->composer->getPackage()->getType() !== 'project') {
|
||||
return parent::getInstallPath($package);
|
||||
}
|
||||
|
||||
if ($this->composer->getPackage()) {
|
||||
$extra = $this->composer->getPackage()->getExtra();
|
||||
if (!empty($extra['think-path'])) {
|
||||
return $extra['think-path'];
|
||||
}
|
||||
}
|
||||
|
||||
return 'thinkphp';
|
||||
}
|
||||
|
||||
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
|
||||
{
|
||||
return parent::update($repo, $initial, $target)->then(function () use ($target) {
|
||||
if ($this->composer->getPackage()->getType() == 'project' && $target->getInstallationSource() != 'source') {
|
||||
//remove tests dir
|
||||
$this->filesystem->removeDirectory($this->getInstallPath($target) . DIRECTORY_SEPARATOR . 'tests');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function supports($packageType)
|
||||
{
|
||||
return 'think-framework' === $packageType;
|
||||
}
|
||||
}
|
||||
64
vendor/topthink/think-installer/src/ThinkTesting.php
vendored
Normal file
64
vendor/topthink/think-installer/src/ThinkTesting.php
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: yunwuxin <448901948@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\composer;
|
||||
|
||||
use Composer\Package\PackageInterface;
|
||||
use Composer\Repository\InstalledRepositoryInterface;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class ThinkTesting extends LibraryInstaller
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getInstallPath(PackageInterface $package)
|
||||
{
|
||||
if ('topthink/think-testing' !== $package->getPrettyName()) {
|
||||
throw new InvalidArgumentException('Unable to install this library!');
|
||||
}
|
||||
|
||||
return parent::getInstallPath($package);
|
||||
}
|
||||
|
||||
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
|
||||
{
|
||||
parent::install($repo, $package)->then(function () use ($package) {
|
||||
$this->copyTestDir($package);
|
||||
});
|
||||
}
|
||||
|
||||
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
|
||||
{
|
||||
return parent::update($repo, $initial, $target)->then(function () use ($target) {
|
||||
$this->copyTestDir($target);
|
||||
});
|
||||
}
|
||||
|
||||
private function copyTestDir(PackageInterface $package)
|
||||
{
|
||||
$appDir = dirname($this->vendorDir);
|
||||
$source = $this->getInstallPath($package) . DIRECTORY_SEPARATOR . 'example';
|
||||
if (!is_file($appDir . DIRECTORY_SEPARATOR . 'phpunit.xml')) {
|
||||
$this->filesystem->copyThenRemove($source, $appDir);
|
||||
} else {
|
||||
$this->filesystem->removeDirectoryPhp($source);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function supports($packageType)
|
||||
{
|
||||
return 'think-testing' === $packageType;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user