Introduction
This package provides a solid foundation on which extensions and themes can be built. It utilises the Composer Plugin API to allow for installing to directories other than the vendor
directory.
The package follows the FIG standard PSR-4 to ensure a high level of interoperability between shared PHP code.
The package requires PHP 5.6.4+.
Installation
The best and easiest way to install the Composer Installers package is with Composer.
Preparation
Open your composer.json
file and add the following to the require
array:
"cartalyst/composer-installers": "^2.0"
Add the following lines after the require
array on your composer.json
file:
"repositories": [
{ "type": "composer", "url": "https://packages.cartalyst.com" }
],
Note: Make sure that after the required changes your
composer.json
file is valid by runningcomposer validate
.
Install the dependencies
Run Composer to install or update the new requirement.
php composer install
or
php composer update
Now you are able to require the vendor/autoload.php
file to autoload the package.
Usage
This package does little on its own. The benefit of using it is being able to choose where your dependencies install themselves to.
Custom Paths
In order to specify that, you need to add a few additional things to your Composer file:
{
"type": "composer-installer",
"extra": {
"path": "extensions/"
}
}
This is from
composer.json
When next you run composer install
/composer update
, the library will detect the custom package type and look for extra.path
. If it finds it; the package will be installed to that directory.
To illustrate this point, consider the following example:
- Your website has widgets, and you want them installed into the public directory. You create a new widget, and give it the custom package type. You also tell it to depend on the
composer-installers
package. - You install your widget. Composer recognises the custom package type and installs your widget to the path you've set.
Overriding Custom Paths
Packages being able to set their own install paths is great, but it presents a sticky problem for shared hosting. Sometimes it's not practical to have packages install themselves, when you can't control the folder structure you're working with, or even set the document root.
In cases like that (or if you just need the flexibility), it's possible to override the package-level paths. Just alter your root Composer file:
{
"require": {
"acme/extension": "~1.0"
},
"extra": {
"paths": {
"acme/extension": "new/path/to/extension/"
}
}
}
This is from
composer.json
What this does is match the key (in extra.paths
) to a dependency, so that it can be installed in the new location. It will override any path set at the level of the dependency.
There are two things to note:
new/path/to/extension/
will contain all the files fromacme/extension
. They will not be nested another level deep, so keep that in mind when specifying custom locations.- Your dependencies will still need their package type set to
composer-installer
.