class Composer

Properties

protected Filesystem $files

The filesystem instance.

protected string|null $workingPath

The working path to regenerate from.

static protected ClassLoader|null $classLoader

The cached Composer autoloader instance.

Methods

__construct(Filesystem $files, string|null $workingPath = null)

Create a new Composer manager instance.

bool
hasPackage(string $package)

Determine if the given Composer package is installed.

bool
requirePackages(array $packages, bool $dev = false, Closure|OutputInterface|null $output = null, string|null $composerBinary = null)

Install the given Composer packages into the application.

bool
removePackages(array $packages, bool $dev = false, Closure|OutputInterface|null $output = null, string|null $composerBinary = null)

Remove the given Composer packages from the application.

void
modify(callable $callback)

Modify the "composer.json" file contents using the given callback.

int
dumpAutoloads(string|array $extra = '', string|null $composerBinary = null)

Regenerate the Composer autoloader files.

int
dumpOptimized(string|null $composerBinary = null)

Regenerate the optimized Composer autoloader files.

array
findComposer(string|null $composerBinary = null)

Get the Composer binary / command for the environment.

string
findComposerFile()

Get the path to the "composer.json" file.

int
fileMode(string $path)

Get the basic permission bits for the Composer file.

string
phpBinary()

Get the PHP binary.

Process
getProcess(array $command, array $env = [])

Get a new Symfony process instance.

setWorkingPath(string $path)

Set the working path used by the class.

string|null
getVersion()

Get the version of Composer.

static ClassLoader
getLoader()

Get the Composer autoloader instance.

static ClassLoader
setLoader(ClassLoader $classLoader)

Set the Composer autoloader instance.

static ClassLoader
findLoader()

Find the Composer autoloader from registered autoload functions.

static void
flushState()

Flush all static state.

Details

at line 39
__construct(Filesystem $files, string|null $workingPath = null)

Create a new Composer manager instance.

Parameters

Filesystem $files
string|null $workingPath

at line 51
bool hasPackage(string $package)

Determine if the given Composer package is installed.

Parameters

string $package

Return Value

bool

Exceptions

JsonException
RuntimeException

at line 64
bool requirePackages(array $packages, bool $dev = false, Closure|OutputInterface|null $output = null, string|null $composerBinary = null)

Install the given Composer packages into the application.

Parameters

array $packages
bool $dev
Closure|OutputInterface|null $output
string|null $composerBinary

Return Value

bool

at line 89
bool removePackages(array $packages, bool $dev = false, Closure|OutputInterface|null $output = null, string|null $composerBinary = null)

Remove the given Composer packages from the application.

Parameters

array $packages
bool $dev
Closure|OutputInterface|null $output
string|null $composerBinary

Return Value

bool

at line 117
void modify(callable $callback)

Modify the "composer.json" file contents using the given callback.

Parameters

callable $callback

Return Value

void

Exceptions

JsonException
RuntimeException

at line 136
int dumpAutoloads(string|array $extra = '', string|null $composerBinary = null)

Regenerate the Composer autoloader files.

Parameters

string|array $extra
string|null $composerBinary

Return Value

int

at line 148
int dumpOptimized(string|null $composerBinary = null)

Regenerate the optimized Composer autoloader files.

Parameters

string|null $composerBinary

Return Value

int

at line 156
array findComposer(string|null $composerBinary = null)

Get the Composer binary / command for the environment.

Parameters

string|null $composerBinary

Return Value

array

at line 173
protected string findComposerFile()

Get the path to the "composer.json" file.

Return Value

string

Exceptions

RuntimeException

at line 187
protected int fileMode(string $path)

Get the basic permission bits for the Composer file.

Parameters

string $path

Return Value

int

at line 203
protected string phpBinary()

Get the PHP binary.

Return Value

string

at line 211
protected Process getProcess(array $command, array $env = [])

Get a new Symfony process instance.

Parameters

array $command
array $env

Return Value

Process

at line 219
Composer setWorkingPath(string $path)

Set the working path used by the class.

Parameters

string $path

Return Value

Composer

at line 229
string|null getVersion()

Get the version of Composer.

Return Value

string|null

at line 252
static ClassLoader getLoader()

Get the Composer autoloader instance.

Static because AOP proxy generation needs autoloader access during bootstrap, before the container is available.

Return Value

ClassLoader

at line 263
static ClassLoader setLoader(ClassLoader $classLoader)

Set the Composer autoloader instance.

Tests only. Swaps the cached Composer loader for the worker lifetime and affects every subsequent class-map registration.

Parameters

ClassLoader $classLoader

Return Value

ClassLoader

at line 271
static protected ClassLoader findLoader()

Find the Composer autoloader from registered autoload functions.

Return Value

ClassLoader

at line 287
static void flushState()

Flush all static state.

Return Value

void