初始化
This commit is contained in:
commit
08fb1ff868
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
/vendor/
|
||||
/.idea/
|
||||
/composer.lock
|
24
composer.json
Normal file
24
composer.json
Normal file
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"name": "tm_xls/composer-thinkphp-installer",
|
||||
"description": "description",
|
||||
"minimum-stability": "stable",
|
||||
"type": "composer-plugin",
|
||||
"license": "proprietary",
|
||||
"authors": [
|
||||
{
|
||||
"name": "zyimm",
|
||||
"email": "email@example.com"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"tm\\xls\\composer\\thinkphp\\": "src"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"composer-plugin-api": "^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"composer/composer": "^2.0"
|
||||
}
|
||||
}
|
25
src/Plugin.php
Normal file
25
src/Plugin.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace tm\xls\composer\thinkphp;
|
||||
|
||||
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 Vendor($io, $composer));
|
||||
}
|
||||
|
||||
public function deactivate(Composer $composer, IOInterface $io)
|
||||
{
|
||||
}
|
||||
|
||||
public function uninstall(Composer $composer, IOInterface $io)
|
||||
{
|
||||
}
|
||||
}
|
13
src/Promise.php
Normal file
13
src/Promise.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace tm\xls\composer\thinkphp;
|
||||
|
||||
use React\Promise\PromiseInterface;
|
||||
|
||||
class Promise implements PromiseInterface
|
||||
{
|
||||
public function then(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null)
|
||||
{
|
||||
$onFulfilled();
|
||||
}
|
||||
}
|
78
src/Vendor.php
Normal file
78
src/Vendor.php
Normal file
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
namespace tm\xls\composer\thinkphp;
|
||||
|
||||
use Composer\Installer\LibraryInstaller;
|
||||
use Composer\Package\PackageInterface;
|
||||
use Composer\Repository\InstalledRepositoryInterface;
|
||||
use React\Promise\PromiseInterface;
|
||||
|
||||
class Vendor extends LibraryInstaller
|
||||
{
|
||||
public function install(InstalledRepositoryInterface $repo, PackageInterface $package): PromiseInterface
|
||||
{
|
||||
return parent::install($repo, $package)
|
||||
->then(function () use ($package) {
|
||||
$this->config($package);
|
||||
})->then(function () use ($package) {
|
||||
$this->route($package);
|
||||
});
|
||||
}
|
||||
|
||||
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target): PromiseInterface
|
||||
{
|
||||
return parent::update($repo, $initial, $target)
|
||||
->then(function () use ($target) {
|
||||
$this->config($target);
|
||||
})->then(function () use ($target) {
|
||||
$this->route($target);
|
||||
});
|
||||
}
|
||||
|
||||
protected function config(PackageInterface $package): PackageInterface
|
||||
{
|
||||
if ($this->composer->getPackage()->getType() == 'project') {
|
||||
$extra = $package->getExtra();
|
||||
if (!empty($extra['think-config'])) {
|
||||
$configDir = 'config';
|
||||
$this->filesystem->ensureDirectoryExists($configDir);
|
||||
//配置文件
|
||||
foreach ((array)$extra['think-config'] as $name => $config) {
|
||||
$this->copyFile($configDir, $package, $name, $config);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $package;
|
||||
}
|
||||
|
||||
protected function route(PackageInterface $package): PackageInterface
|
||||
{
|
||||
if ($this->composer->getPackage()->getType() == 'project') {
|
||||
$extra = $package->getExtra();
|
||||
if (!empty($extra['think-route'])) {
|
||||
$configDir = 'route';
|
||||
$this->filesystem->ensureDirectoryExists($configDir);
|
||||
//配置文件
|
||||
foreach ((array)$extra['think-route'] as $name => $config) {
|
||||
$this->copyFile($configDir, $package, $name, $config);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $package;
|
||||
}
|
||||
|
||||
private function copyFile($configDir, $package, $name, $config)
|
||||
{
|
||||
$target = $configDir.DIRECTORY_SEPARATOR.$name.'.php';
|
||||
$source = $this->getInstallPath($package).DIRECTORY_SEPARATOR.$config;
|
||||
if (is_file($target)) {
|
||||
$this->io->write("<info>File $target exist!</info>");
|
||||
return;
|
||||
}
|
||||
if (!is_file($source)) {
|
||||
$this->io->write("<info>File $target not exist!</info>");
|
||||
return;
|
||||
}
|
||||
copy($source, $target);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user