On Github PHPDX / ComposerSlides
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" } }This will tell Composer to install this version and this version only. If other dependencies require a different version, the solver will ultimately fail and abort any install or update procedures.
# composer.json { "require": { "silex/silex": ">=1.0,<1.1 || >=1.2" } }By using comparison operators you can specify ranges of valid versions. Valid operators are >, >=, <, <=, !=. You can define multiple ranges. Ranges separated by a space ( ) or comma (,) will be treated as a logical AND. A double pipe (||) will be treated as a logical OR. AND has higher precedence than OR.
# composer.json { "require": { "silex/silex": "1.0.*" } }
# composer.json { "require": { "silex/silex": "~1.2" } }Next significant release. Specifies a minimum version, but allows the last digit specified to go up.
# composer.json { "require": { "silex/silex": "^1.2.3" } }Next significant release. For pre-1.0 versions it also acts with safety in mind and treats ^0.3 as >=0.3.0 <0.4.0. This is the recommended operator for maximum interoperability when writing library code.
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": "*" } }such as installing packages outside of the default vendor library. In these cases you could consider creating a Custom Installer to handle your specific logic. phpDocumentor features Templates that need to be installed outside of the default /vendor folder structure. As such they have chosen to adopt the phpdocumentor-template type and create a plugin providing the Custom Installer to send these templates to the correct folder.
{ "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); } }alter or expand Composer's functionality with your own
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.
This is just the task-runner side of Composer. Like Gradle, Maven, Grunt, Gulp.Host your own composer repository.
For example let's assume you have a few packages you want to reuse across your company but don't really want to open-source. You would first define a Satis configuration: a json file with an arbitrary name that lists your curated repositories.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" ] }Creates a .BAT and Bash file for you, in a known location.
# 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