Craft 3 Class Reference

Class craft\services\Composer

Inheritance
craft\services\Composer » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/services/Composer.php

Composer service.

An instance of the Composer service is globally accessible in Craft via Craft::$app->composer.

Public Properties
Property Type Description Defined By
$composerRepoUrl string craft\services\Composer
$disablePackagist boolean craft\services\Composer
Public Methods
Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getJsonPath() Returns the path to composer.json. craft\services\Composer
getLockPath() Returns the path to composer.lock, if it exists. craft\services\Composer
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. yii\base\BaseObject
install() Installs a given set of packages with Composer. craft\services\Composer
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
optimize() Optimizes the Composer autoloader. craft\services\Composer
trigger() Triggers an event. yii\base\Component
uninstall() Uninstalls a given set of packages with Composer. craft\services\Composer
Protected Methods
Method Description Defined By
_ensureHomeVar() Ensures that HOME/APPDATA or COMPOSER_HOME env vars have been set. craft\services\Composer
composerConfig() Returns the decoded Composer config, modified to use composer.craftcms.com instead of packagist.org. craft\services\Composer
createComposer() Creates a new Composer instance. craft\services\Composer
findCraftRepo() craft\services\Composer
findDisablePackagist() craft\services\Composer
preloadComposerClasses() Preloads Composer classes in case Composer needs to update itself craft\services\Composer
updateRequirements() Updates the composer.json file with new requirements craft\services\Composer

Property Details

$composerRepoUrl public property #

public string $composerRepoUrl 'https://composer.craftcms.com/'

$disablePackagist public property #

public boolean $disablePackagist true

Method Details

_ensureHomeVar() protected method #

Ensures that HOME/APPDATA or COMPOSER_HOME env vars have been set.

protected void _ensureHomeVar ( )

composerConfig() protected method #

Returns the decoded Composer config, modified to use composer.craftcms.com instead of packagist.org.

protected array composerConfig ( \Composer\IO\IOInterface $io, \craft\services\string $jsonPath, \craft\services\bool $swapPackagist true )
$io \Composer\IO\IOInterface
$jsonPath string
$swapPackagist boolean

createComposer() protected method #

Creates a new Composer instance.

protected \Composer\Composer createComposer ( \Composer\IO\IOInterface $io, \craft\services\string $jsonPath, \craft\services\bool $swapPackagist true )
$io \Composer\IO\IOInterface
$jsonPath string
$swapPackagist boolean

findCraftRepo() protected method #

protected void findCraftRepo ( array $config )
$config

findDisablePackagist() protected method #

protected void findDisablePackagist ( array $config )
$config

getJsonPath() public method #

Returns the path to composer.json.

public string getJsonPath ( )
throws yii\base\Exception if composer.json can't be located

getLockPath() public method #

Returns the path to composer.lock, if it exists.

public string, null getLockPath ( )
throws yii\base\Exception if composer.json can't be located

install() public method #

Installs a given set of packages with Composer.

public void install ( array $requirements, \Composer\IO\IOInterface $io null )
$requirements array Package name/version pairs
$io \Composer\IO\IOInterface, null The IO object that Composer should be instantiated with
throws Throwable if something goes wrong

optimize() public method #

Optimizes the Composer autoloader.

public void optimize ( \Composer\IO\IOInterface $io null )
$io \Composer\IO\IOInterface, null The IO object that Composer should be instantiated with
throws Throwable if something goes wrong

preloadComposerClasses() protected method #

Preloads Composer classes in case Composer needs to update itself

protected void preloadComposerClasses ( )

uninstall() public method #

Uninstalls a given set of packages with Composer.

public void uninstall ( array $packages, \Composer\IO\IOInterface $io null )
$packages string[] Package names
$io \Composer\IO\IOInterface, null The IO object that Composer should be instantiated with
throws Throwable if something goes wrong

updateRequirements() protected method #

Updates the composer.json file with new requirements

protected void updateRequirements ( \craft\services\string $jsonPath, array $requirements, \craft\services\bool $sortPackages )
$jsonPath string
$requirements array
$sortPackages boolean