framework/extensions/package-manager/src/PackageManagerServiceProvider.php
2021-09-01 19:49:44 +01:00

39 lines
1.3 KiB
PHP

<?php
namespace SychO\PackageManager;
use Composer\Config;
use Composer\Console\Application;
use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\Paths;
use Illuminate\Contracts\Container\Container;
class PackageManagerServiceProvider extends AbstractServiceProvider
{
public function register()
{
$this->container->singleton(Application::class, function (Container $container) {
// This should only ever be resolved when running composer commands,
// because we modify other environment configurations.
$composer = new Application();
$composer->setAutoExit(false);
$paths = $container->make(Paths::class);
putenv("COMPOSER_HOME={$paths->storage}/.composer");
putenv("COMPOSER={$paths->base}/composer.json");
Config::$defaultConfig['vendor-dir'] = $paths->base.'/vendor';
// When running simple require, update and remove commands on packages,
// composer 2 doesn't really need this much unless the extensions are very loaded dependency wise,
// but this is necessary for running flarum updates.
@ini_set('memory_limit', '1G');
@set_time_limit(5 * 60);
return $composer;
});
$this->container->alias(Application::class, 'flarum.composer');
}
}