Presented by John Kelly
# composer.json
{
"require": {
"silex/silex": "~1.1"
}
}
$ composer install
Include the autoloader
require __DIR__ . '/vendor/autoload.php';
1.0.2
# composer.json
{
"require": {
"silex/silex": "1.0.2"
}
}
# composer.json
{
"require": {
"silex/silex": ">=1.0,<1.1 || >=1.2"
}
}
# composer.json
{
"require": {
"silex/silex": "1.0.*"
}
}
# composer.json
{
"require": {
"silex/silex": "~1.2"
}
}
# composer.json
{
"require": {
"silex/silex": "^1.2.3"
}
}
http://semver.mwl.be/
Used to alias a branch to a specific version.
# composer.json
{
"require": {
"silex/silex": "dev-master as 1.2.9"
}
}
After installing the dependencies, Composer writes the list of the exact versions it installed into a composer.lock file. This locks the project to those specific versions.
Allows for a package maintainer to customize the installation of their package.
{
"name": "phpdocumentor/template-responsive",
"type": "phpdocumentor-template",
"require": {
"phpdocumentor/template-installer-plugin": "*"
}
}
{
"name": "phpdocumentor/template-installer-plugin",
"type": "composer-plugin",
"license": "MIT",
"autoload": {
"psr-0": {"phpDocumentor\\Composer": "src/"}
},
"extra": {
"class": "phpDocumentor\\Composer\\TemplateInstallerPlugin"
},
"require": {
"composer-plugin-api": "1.0.0"
}
}
namespace phpDocumentor\Composer;
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
class TemplateInstallerPlugin implements PluginInterface
{
public function activate(Composer $composer, IOInterface $io)
{
$installer = new TemplateInstaller($io, $composer);
$composer->getInstallationManager()->addInstaller($installer);
}
}
namespace phpDocumentor\Composer;
use Composer\Package\PackageInterface;
use Composer\Installer\LibraryInstaller;
class TemplateInstaller extends LibraryInstaller
{
/**
* {@inheritDoc}
*/
public function getPackageBasePath(PackageInterface $package)
{
$prefix = substr($package->getPrettyName(), 0, 23);
if ('phpdocumentor/template-' !== $prefix) {
throw new \InvalidArgumentException(
'Unable to install template, phpdocumentor templates '
. 'should always start their package name with '
. '"phpdocumentor/template-"'
);
}
return 'data/templates/'.substr($package->getPrettyName(), 23);
}
/**
* {@inheritDoc}
*/
public function supports($packageType)
{
return 'phpdocumentor-template' === $packageType;
}
}
Execute custom code or package-specific commands during the composer execution process.
Host your own composer repository.
Any command line script that a Composer package would like to pass along to a user who installs the package should be listed as a vendor binary.
# composer.json
{
"bin": [
"bin/my-script",
"bin/my-other-script"
]
}
# composer.json
{
"config": {
"platform": {
"php": "5.3.3"
}
}
}
Lets you fake platform packages (PHP and extensions) so that you can emulate a production env or define your target platform in the config
$ composer install --no-dev --prefer-dist --optimize-autoloader --no-interaction