Help:Using Composer

From semantic-mediawiki.org
Jump to: navigation, search
InstallationHelp:Using Composer
Composer usage
Some information about how to use Composer
Keywords
Table of Contents

Composer is a dependency manager for PHP. For a more in-depth understanding on how Composer works and how to interpret the composer.json file, see Composer net.tuts tutorial.

Installation

Hosting with shell access

Shared hosting

Download composer.phar using

curl -sS http://getcomposer.org/installer | php

into the same folder where the composer.json file is located (Installing Composer locally).

The next step is to run php composer.phar install in order to download all necessary libraries (into the extension/ or vendor/ directory).

Related links

Usage

Adding packages

Installing a package can be done by running composer require "PackageNameIs:ForVersion".

The require command consists of two parts, the name of the package and second devided by a colon represents the version to be installed.

~/^ usage and meaning

The tilde section describes its expected behavior in detail but in short it allows to specify a range of allowed release tags. If with the next composer update execution a new update is available (new release, bugfix etc.) it will be automatically pulled together with all its dependencies. Something like ~2.3 indicates an equivalence to >= 2.0, < 3.0.

Fetching a distinct release

If for some reason you want to use a different release other than the latest available "~2.4" then using a distinct release tag without the ~ is a viable option but it will lock the release to a specific version and available updates (for bugfixes etc.) will not be fetched on the next composer update run therefore it is not the preferred option.

Remove packages

Remove the PackageNameIs from the composer.json repositories section and run composer update.

Update packages and dependencies

If a new release is available run composer update and if for some reason you need to pull directly from master (using git pull/git fetch) it is recommended that after executing git you run composer dump-autoload from the MW root directory.

Using development versions

composer require mediawiki/semantic-media-wiki "@dev-thenameofthebranchyouwanttotest"

Using development fork

Sometimes you may want to load a package directly from a version control system (VCS) like on GitHub. There are a few use cases for this. The most common one is maintaining your own fork during softwatre development time. To use your own fork, change the "composer.json" file as follows:

"require": {
   "mediawiki/semantic-result-formats": "dev-master"
},
"repositories": [
   {
      "type": "vcs",
      "url": "https://github.com/gesinn-it/SemanticResultFormats"
   }
]

Now, run

composer update --prefer-source

Improve autoloader

Composer recommends to use dump-autoload together with option -o to get a faster autoloader especially for production environments. dump-autoload will convert PSR-0/4 packages into a classmap in order to optimize the loading of classes.

Individual file release

Note Note: Access to a server is needed for this to work, so you might have to ask somebody to do this.

If the above steps didn't work (due to configuration restrictions on part of the hosting company or missing CLI access), it it is suggested to run a local copy and upload the generated files together with the /vendor directory to the target destination:

  1. Create a directory on your server which is able to handle Composer:
    mkdir w
    Change "w" to the name of the script path you are using for your wiki.
  2. Change into the newly created directory:
    cd w
  3. Place your "composer.json" file in this directory.
  4. Run Composer to generate the necessary directories and files either with
    php composer.phar update
    if Composer was installed locally (see above) in this directory or
    composer update
    if Composer was installed globally. You will get the new subdirectories called /extensions/ and /vendor/.
  5. Copy the contents of the "/w/" directory and its subdirectories to the destination on the server which cannot handle Composer.
  6. Do the rest of the installation of SMW and enjoy!

FAQ

See also