class Composer

Traits

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

Closure|null
guardProcessOutput(Process $process, callable|null $output)

Stop the process if its output callback fails.

__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 application Composer autoloader registered with a vendor directory.

static array
rootPackage()

Get the root package of the application's Composer installation.

static string
vendorPath(string $rootPath)

Get the vendor directory of the Composer install rooted at the given path.

static void
flushState()

Flush all static state.

Details

protected Closure|null guardProcessOutput(Process $process, callable|null $output)

Stop the process if its output callback fails.

Parameters

Process $process
callable|null $output

Return Value

Closure|null

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

Create a new Composer manager instance.

Parameters

Filesystem $files
string|null $workingPath

at line 57
bool hasPackage(string $package)

Determine if the given Composer package is installed.

Parameters

string $package

Return Value

bool

Exceptions

JsonException
RuntimeException

at line 70
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 97
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 127
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 151
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 163
int dumpOptimized(string|null $composerBinary = null)

Regenerate the optimized Composer autoloader files.

Parameters

string|null $composerBinary

Return Value

int

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

Get the Composer binary / command for the environment.

Parameters

string|null $composerBinary

Return Value

array

at line 190
protected string findComposerFile()

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

Return Value

string

Exceptions

RuntimeException

at line 204
protected int fileMode(string $path)

Get the basic permission bits for the Composer file.

Parameters

string $path

Return Value

int

at line 220
protected string phpBinary()

Get the PHP binary.

Return Value

string

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

Get a new Symfony process instance.

Parameters

array $command
array $env

Return Value

Process

at line 241
Composer setWorkingPath(string $path)

Set the working path used by the class.

Parameters

string $path

Return Value

Composer

at line 251
string|null getVersion()

Get the version of Composer.

Return Value

string|null

at line 274
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 285
static ClassLoader setLoader(ClassLoader $classLoader)

Set the Composer autoloader instance.

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

Parameters

ClassLoader $classLoader

Return Value

ClassLoader

at line 297
static protected ClassLoader findLoader()

Find the application Composer autoloader registered with a vendor directory.

A tool shipped as a PHAR, such as PHPStan, registers its own autoloader first, so a loader outside a PHAR is preferred.

Return Value

ClassLoader

at line 323
static array rootPackage()

Get the root package of the application's Composer installation.

A tool shipped as a PHAR, such as PHPStan, registers its own installation first, so InstalledVersions::getRootPackage() returns the tool's. The first installation outside a PHAR is preferred.

Return Value

array

at line 341
static string vendorPath(string $rootPath)

Get the vendor directory of the Composer install rooted at the given path.

The loaded install records its own root, so a vendor directory chosen through project or global configuration, or while installing, needs no Composer configuration parsing. A relative COMPOSER_VENDOR_DIR is relative to the root.

Parameters

string $rootPath

Return Value

string

at line 385
static void flushState()

Flush all static state.

Return Value

void