first version
This commit is contained in:
56
kirby/vendor/getkirby/composer-installer/src/Installer.php
vendored
Executable file
56
kirby/vendor/getkirby/composer-installer/src/Installer.php
vendored
Executable file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Kirby\ComposerInstaller;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Composer\Config;
|
||||
use Composer\Installer\LibraryInstaller;
|
||||
use Composer\Package\PackageInterface;
|
||||
|
||||
/**
|
||||
* @package Kirby Composer Installer
|
||||
* @author Lukas Bestle <lukas@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license MIT
|
||||
*/
|
||||
class Installer extends LibraryInstaller
|
||||
{
|
||||
/**
|
||||
* Decides if the installer supports the given type
|
||||
*
|
||||
* @param string $packageType
|
||||
* @return bool
|
||||
*/
|
||||
public function supports($packageType): bool
|
||||
{
|
||||
return $packageType === 'kirby-cms';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the installation path of a package
|
||||
*
|
||||
* @param PackageInterface $package
|
||||
* @return string path
|
||||
*/
|
||||
public function getInstallPath(PackageInterface $package): string
|
||||
{
|
||||
// get the extra configuration of the top-level package
|
||||
if ($rootPackage = $this->composer->getPackage()) {
|
||||
$extra = $rootPackage->getExtra();
|
||||
} else {
|
||||
$extra = [];
|
||||
}
|
||||
|
||||
// use path from configuration, otherwise fall back to default
|
||||
$path = $extra['kirby-cms-path'] ?? 'kirby';
|
||||
|
||||
// don't allow unsafe directories
|
||||
$vendorDir = $this->composer->getConfig()->get('vendor-dir', Config::RELATIVE_PATHS) ?? 'vendor';
|
||||
if ($path === $vendorDir || $path === '.') {
|
||||
throw new InvalidArgumentException('The path ' . $path . ' is an unsafe installation directory for ' . $package->getPrettyName() . '.');
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
}
|
29
kirby/vendor/getkirby/composer-installer/src/Plugin.php
vendored
Executable file
29
kirby/vendor/getkirby/composer-installer/src/Plugin.php
vendored
Executable file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Kirby\ComposerInstaller;
|
||||
|
||||
use Composer\Composer;
|
||||
use Composer\IO\IOInterface;
|
||||
use Composer\Plugin\PluginInterface;
|
||||
|
||||
/**
|
||||
* @package Kirby Composer Installer
|
||||
* @author Lukas Bestle <lukas@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license MIT
|
||||
*/
|
||||
class Plugin implements PluginInterface
|
||||
{
|
||||
/**
|
||||
* Apply plugin modifications to Composer
|
||||
*
|
||||
* @param Composer $composer
|
||||
* @param IOInterface $io
|
||||
*/
|
||||
public function activate(Composer $composer, IOInterface $io)
|
||||
{
|
||||
$installer = new Installer($io, $composer);
|
||||
$composer->getInstallationManager()->addInstaller($installer);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user